Example #1
0
    Joystick Joystick::deserialize(std::string input){
        Joystick joy;
        joy.is_xbox = stob(pullObject("\"is_xbox\"", input));
        joy.type = std::stoi(pullObject("\"type\"",input));
        joy.name = unquote(pullObject("\"name\"", input));
        joy.buttons = std::stoi(pullObject("\"buttons\"", input));
        joy.button_count = std::stoi(pullObject("\"button_count\"", input));
        std::vector<int8_t> axes_deserialized = deserializeList(pullObject("\"axes\"",input), std::function<int8_t(std::string)>([&](std::string input){ return std::stoi(input);}), true);
        if(axes_deserialized.size() == joy.axes.size()){
            joy.axes = axes_deserialized;
        } else {
            throw std::out_of_range("Exception: deserialization resulted in array of " + std::to_string(axes_deserialized.size()) + " axes, expected " + std::to_string(joy.axes.size()));
        }
        joy.axis_count = std::stoi(pullObject("\"axis_count\"", input));
        std::vector<uint8_t> axis_types_deserialized = deserializeList(pullObject("\"axis_types\"",input), std::function<uint8_t(std::string)>([&](std::string input){ return std::stoi(input);}), true);
        if(axis_types_deserialized.size() == joy.axis_types.size()){
            joy.axis_types = axis_types_deserialized;
        } else {
            throw std::out_of_range("Exception: deserialization resulted in array of " + std::to_string(axis_types_deserialized.size()) + " axis types, expected " + std::to_string(joy.axis_types.size()));
        }
        std::vector<int16_t> povs_deserialized = deserializeList(pullObject("\"povs\"",input), std::function<int16_t(std::string)>([&](std::string input){ return std::stoi(input);}), true);
        if(povs_deserialized.size() == joy.povs.size()){
            joy.povs = povs_deserialized;
        } else {
            throw std::out_of_range("Exception: deserialization resulted in array of " + std::to_string(povs_deserialized.size()) + " povs, expected " + std::to_string(joy.povs.size()));
        }
        joy.pov_count = std::stoi(pullObject("\"pov_count\"", input));
        joy.outputs = std::stoi(pullObject("\"outputs\"", input));
        joy.left_rumble = std::stoi(pullObject("\"left_rumble\"", input));
        joy.right_rumble = std::stoi(pullObject("\"right_rumble\"", input));

        return joy;
    }
	void executeKssCommandList(char * arg , ListenSocket ls){
		RuntimeErrorValidator * validator = buildErrorSuccessValidator();
		//List params = getFirstParameter("Dispositivo o directorio a Listar");
		List params = buildStringsListWithValues(1 , arg);

		MpsRequest * req = buildMpsRequest( generateRandomKey(16) , SHELL_LS , params);
		MpsResponse * resp = sendAndReceiveMpsMessages(ls , req ,validator);

		if(isDebugEnabled())
			debug(concatAll(2, "Codigo de resultado: " , resp->statusCode));

		Iterator * ite = buildIterator(resp->returnValues);

		if( equalsStrings(resp->statusCode , MPS_RESPONSE_STATUS_CODE_SUCCESS)){

			char * serializedFiles = next(ite);
			List files = deserializeList(serializedFiles);
			ite = buildIterator(files);

			printf("Contenido del directorio:\n");
			printf("--------------------------------------------------------------------------------------\n");

			while(hasMoreElements(ite)){
				char * elem = next(ite);
				printf("%s\n " , trim(elem));
			}
		}else{
			printf("%s" , ( hasMoreElements(ite) ? (char *) next(ite) : "Ha ocurrido un error"));
		}
	}
	void doOnlineListFiles(ClientThreadResource * res , ListenSocket clientSocket ,
		RuntimeErrorValidator * validator){

		char * pathToList = res->relativeWorkingDir;
		List contents = callKssOperationList(res->heapHandler , pathToList , validator);
		Iterator * ite = buildIterator(contents , res->heapHandler);

		while(hasMoreElements(ite)){
				
			if( equalsStrings(res->relativeWorkingDir , "/")){
				char * vdaName = next(ite);

				char * msg = concat(res->heapHandler, 3, 
					"drwxrwxrwx 1 ftp ftp 4096 Jul 11 2011 ", 
					vdaName , CHARACTER_CRLF);
				
				sendBytes(clientSocket , msg , (int) strlen(msg));

			}else{

				char * serializedContent = next(ite);								
				List files = deserializeList(serializedContent ,res->heapHandler);
				Iterator * ite = buildIterator(files , res->heapHandler);

				char * size = hasMoreElements(ite) ? next(ite) : NULL;
				char * fileName = hasMoreElements(ite) ? next(ite) : NULL;
				
				char * msg = concat(res->heapHandler, 5 ,
					"-rwxrwxrwx 1 ftp ftp " , size , "Jul 11 2011 " , fileName , CHARACTER_CRLF);

				sendBytes(clientSocket , msg , (int) strlen(msg));
			}
		}			

		if(hasError(validator)){
			res->resultMessage = buildResponseMessageType426(res->heapHandler);
		}else{
			res->resultMessage = buildResponseMessageType226(res->heapHandler);
		}
	}