MessageInterface* ComManager::getMessage() { if (current_connection != 0) { delete current_connection; current_connection = 0; } if (messages.empty()) { readSockets(); } if(!messages.empty()) { current_connection = new MessageContainer(messages.front().getSocket(),messages.front().getMessage()); messages.pop(); if (utility->validHeader(current_connection->getMessage())) { MessageInterface* msg = utility->buildIncomingMessage(current_connection->getMessage(),true); if(msg->getHeader()->getMsgType()!=Msg::VERSIONING) addClientConnection(msg->getHeader()->getClientID()); return msg; } else { Message<StatusAndError>* return_msg = new Message<StatusAndError>(CommonHeader(Msg::STATUS_AND_ERROR,Msg::Sub::UNKNOWN,0,0), StatusAndError(Status::MESSAGE_CORRUPTED,Msg::UNKNOWN,Msg::Sub::UNKNOWN,"Corrupted Message")); sendMessage(return_msg); delete return_msg; return 0; } } else return 0; }
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- // related to settings reading // ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- bool InternetServerPlatform::loadSettings() { // get the settings file path QString settingsFilePath = QCoreApplication::applicationFilePath() + ".config"; Logging::logInfo( this, QString("loadSettingsFile() -> %1").arg(settingsFilePath) ); // get all key nodes QDomDocument settingsFileAsXml; QDomNode internetServerPlatform = IspComponents::Dom::loadXmlFileAndGetRootNode( settingsFilePath, settingsFileAsXml ); QDomNode variables = IspComponents::Dom::getChildNodeByName( internetServerPlatform, "variables" ); QDomNode ispSettings = IspComponents::Dom::getChildNodeByName( internetServerPlatform, "ispSettings" ); QDomNode sockets = IspComponents::Dom::getChildNodeByName( internetServerPlatform, "sockets" ); readVariables ( variables ); readIspSettings ( ispSettings ); readSockets ( sockets ); return true; }
int main(int argc, char** argv) { UDBSocketType socketType = (!SILSIM_TELEMETRY_RUN_AS_SERVER) ? UDBSocketUDPServer : UDBSocketUDPClient; uint32_t udpPort = SILSIM_TELEMETRY_PORT; char *udpHost = SILSIM_TELEMETRY_HOST; char *serialPort = NULL; uint32_t serialBaud = 0; uint8_t argPos = 0; int i; for (i = 1; i < argc; i++) { if (argv[i][0] == '-') { if (argv[i][1] == 'h') { printHelp(); return 0; } else if (argv[i][1] == 's') { socketType = UDBSocketUDPServer; } else if (argv[i][1] == 'c') { socketType = UDBSocketUDPClient; } else if (argv[i][1] == 'l') { socketType = UDBSocketSerial; } } else { if (argPos == 0) { if (socketType == UDBSocketSerial) { serialPort = argv[i]; } else { udpPort = atoi(argv[i]); } } else if (argPos == 1) { if (socketType == UDBSocketUDPClient) { udpHost = argv[i]; } else { serialBaud = atoi(argv[i]); } } else { printHelp(); return 0; } argPos++; } } stdioSocket = UDBSocket_init(UDBSocketStandardInOut, 0, NULL, NULL, 0); transportSocket = UDBSocket_init(socketType, udpPort, udpHost, serialPort, serialBaud); if (!transportSocket) { printf("ERROR: UDBSocket_init failed: %s\n", UDBSocketLastErrorMessage()); exit(1); } while (1) { if (!readSockets()) { usleep(1000); } } }