int main (int argc, char *argv[]) { Application_Executable_Name = argv[0]; const char *pszMethodName = "DSProMain::main"; #ifdef UNIX SigFaultHandler handler (Application_Executable_Name); #endif if (signal (SIGINT, sigIntHandler) == SIG_ERR) { fprintf (stderr, "Error registering SIGINT handler\n"); exit (-1); } // Parse arguments IHMC_ACI::Arguments arguments; IHMC_ACI::parseArguments (argc, argv, arguments); String homeDir; getHomeDir (arguments.pathToExecutable, homeDir); String logDir (homeDir); logDir += getPathSepCharAsString(); logDir += "logs"; IHMC_ACI::initializeLoggers (logDir); if (arguments.configFilePath.length() <= 0) { IHMC_ACI::getDefaultConfigFile (homeDir, "dspro.properties", arguments.configFilePath, false); } if (!FileUtils::fileExists (arguments.configFilePath.c_str())) { checkAndLogMsg (pszMethodName, Logger::L_Info, "The config file at " "location: %s does not exist!\n", arguments.configFilePath.c_str()); } ConfigManager cfgMgr; int rc = cfgMgr.init(); if (rc != 0) { printf ("Count not initialize ConfigManager. Returned code %d\n", rc); exit (1); } if ((rc = cfgMgr.readConfigFile (arguments.configFilePath)) != 0) { checkAndLogMsg (pszMethodName, Logger::L_Warning, "Error in config file " "%s reading. Returned code %d\n", arguments.configFilePath.c_str(), rc); } //Initializing and starting DSPro String nodeId; if (getNodeId (&cfgMgr, nodeId) != 0) { checkAndLogMsg (pszMethodName, Logger::L_SevereError, "Node ID was not set.\n"); return 2; } // Read extra-attributes if necessary char *pszMetadataExtraAttributes = NULL; if (arguments.metadataExtraAttributesFile.length() <= 0) { IHMC_ACI::getDefaultConfigFile (homeDir, "metadataExtraAttributes.xml", arguments.metadataExtraAttributesFile); } if (arguments.metadataExtraAttributesFile.length() > 0) { DSLib::readFileIntoString (arguments.metadataExtraAttributesFile, &pszMetadataExtraAttributes); } // Read extra-values if necessary char *pszMetadataValues = NULL; if (arguments.metadataValuesFile.length() <= 0) { IHMC_ACI::getDefaultConfigFile (homeDir, "metadataExtraValues.xml", arguments.metadataExtraAttributesFile); } if (arguments.metadataValuesFile.length() > 0) { DSLib::readFileIntoString (arguments.metadataValuesFile, &pszMetadataValues); } // Instantiate and init DSPro DSPro dspro (nodeId, BUILD_TIME); if ((rc = dspro.init (&cfgMgr, pszMetadataExtraAttributes, pszMetadataValues)) < 0) { checkAndLogMsg (pszMethodName, Logger::L_SevereError, "DSPro has failed to initialize. Return code: %d\n", rc); return 3; } uint16 ui16; uint16 ui16ClientId = 0; DSProCmdProcessor dsproCmdProc (&dspro); dspro.registerDSProListener (ui16ClientId, &dsproCmdProc, ui16); dspro.registerSearchListener (ui16ClientId, &dsproCmdProc, ui16); //Initializing and starting ProxyServer DSProProxyServer proxySrv; rc = initializeAndStartProxyServer (&dspro, &cfgMgr, proxySrv); if (rc != 0) { checkAndLogMsg (pszMethodName, Logger::L_SevereError, "DSProProxyServer has failed to initialize. Return code: %d\n", rc); return 4; } // Connect to peers DSProUtils::addPeers (dspro, cfgMgr); dsproCmdProc.run(); // Request Termination proxySrv.requestTerminationAndWait(); // And delete objects delete pLogger; pLogger = NULL; delete pNetLog; pNetLog = NULL; delete pTopoLog; pTopoLog = NULL; // Terminate return 0; }
int main (int argc, char *argv[]) { _m.lock(); _terminated = false; _m.unlock(); if (signal (SIGINT, sigIntHandler) == SIG_ERR) { printf ("Error handling SIGINT\n"); exit (-1); } ConfigManager *pConfigManager = NULL; uint16 ui16Port = DIS_SVC_PROXY_SERVER_PORT_NUMBER; // Read Configuration if (argc > 2) { printf ("Usage: ./DisServiceProxy <configFile>\n"); exit (-2); } if (argv[1]) { if (FileUtils::fileExists(argv[1])) { pConfigManager = new ConfigManager(); pConfigManager->init(); int rc; if ((rc = pConfigManager->readConfigFile((const char *) argv[1])) != 0) { printf ("Error in config file %s reading. Returned code %d.\n", (const char *) argv[1], rc); exit (-3); } if (pConfigManager->hasValue("aci.disservice.proxy.port")) { ui16Port = (uint16) pConfigManager->getValueAsInt("aci.disservice.proxy.port"); } if (pConfigManager->getValueAsBool("util.logger.enabled", true)) { if (!pLogger) { pLogger = new Logger(); if (pConfigManager->getValueAsBool("util.logger.out.screen.enabled", true)) { pLogger->enableScreenOutput(); } if (pConfigManager->getValueAsBool("util.logger.out.file.enabled", true)) { pLogger->initLogFile (pConfigManager->getValue ("util.logger.out.file.path", "ds.log"), false); pLogger->enableFileOutput(); pLogger->initErrorLogFile (pConfigManager->getValue ("util.logger.error.file.path", "dserror.log"), false); pLogger->enableErrorLogFileOutput(); } uint8 ui8DbgDetLevel = (uint8) pConfigManager->getValueAsInt ("util.logger.detail", Logger::L_LowDetailDebug); switch (ui8DbgDetLevel) { case Logger::L_SevereError: case Logger::L_MildError: case Logger::L_Warning: case Logger::L_Info: case Logger::L_NetDetailDebug: case Logger::L_LowDetailDebug: case Logger::L_MediumDetailDebug: case Logger::L_HighDetailDebug: pLogger->setDebugLevel (ui8DbgDetLevel); pLogger->logMsg ("DisServiceLauncher::main", Logger::L_Info, "Setting debug level to %d\n", ui8DbgDetLevel); break; default: pLogger->setDebugLevel(Logger::L_LowDetailDebug); pLogger->logMsg("DisServiceLauncher::main", Logger::L_Info, "Invalid Logger detail debug level. Setting it to %d\n", Logger::L_LowDetailDebug); } } } } else { printf ("The file at location: %s does not exist.\n", (const char *) argv[1]); exit (-4); } } if (pConfigManager == NULL) { // Default Logger conf if (!pLogger) { pLogger = new Logger(); pLogger->enableScreenOutput(); pLogger->initLogFile("disseminationservice.log",false); pLogger->enableFileOutput(); pLogger->setDebugLevel(Logger::L_LowDetailDebug); } } if (pLogger != NULL) { pLogger->displayAbsoluteTime(); } //Initializing and starting DisService DisseminationService * _pDisService = (pConfigManager ? new DisseminationService(pConfigManager) : new DisseminationService()); int rc; if (0 != (rc = _pDisService->init())) { printf ("\nDisseminationService is failed to initialize\n"); return -5; } _pDisService->start(); // Initializing and starting ProxyServer DisseminationServiceProxyServer dsProxyServer; dsProxyServer.init (_pDisService, ui16Port); dsProxyServer.start(); printf ("\nDisseminationProxyServer is running on port %d\n", ui16Port); // Invoking the command processor pLogger->disableScreenOutput(); DisServiceCommandProcessor cmdProc (_pDisService); cmdProc.setPrompt ("DisService"); cmdProc.enableNetworkAccess (5555); cmdProc.run(); printf ("\nDisService is terminating...\n"); _pDisService->requestTerminationAndWait(); delete _pDisService; _pDisService = NULL; delete pLogger; pLogger = NULL; delete pConfigManager; pConfigManager = NULL; return 0; }
JNIEXPORT jint JNICALL Java_us_ihmc_aci_dspro2_DSProLauncher_initConfigNative (JNIEnv *pEnv, jobject joThis, jstring jsConfigFile) { // Loading config file const char *pcConfigFile; pcConfigFile = pEnv->GetStringUTFChars (jsConfigFile, NULL); if (pcConfigFile == NULL) { pEnv->ThrowNew (pEnv->FindClass ("us/ihmc/aci/dspro2/DSProLauncher/DSProInitException"), "FAIL while copying string configFile"); pEnv->ReleaseStringUTFChars (jsConfigFile, pcConfigFile); return -12; } ConfigManager *pCfgMgr = new ConfigManager(); if (pCfgMgr == NULL) { pEnv->ThrowNew (pEnv->FindClass ("us/ihmc/aci/dspro2/DSProLauncher/DSProInitException"), "DSProJNIWrapper not initialized - ConfigManager is null"); return -13; } jclass jcCfgMgr = pEnv->GetObjectClass (joThis); jfieldID jfCfgMgr = pEnv->GetFieldID (jcCfgMgr, "_configManager", "J"); union { jlong jlValue; void *p; } u; u.p = pCfgMgr; pEnv->SetLongField (joThis, jfCfgMgr, u.jlValue); pCfgMgr->init(); String cfgFilePath = pcConfigFile; if (0 == access (cfgFilePath, 0)) { // There is a config file to be read int rc; if (0 != (rc = (pCfgMgr->readConfigFile(cfgFilePath, true)))) { if (pLogger != NULL) { pLogger->logMsg("main", Logger::L_SevereError, "failed to read the config file; rc=%d\n", rc); } delete pCfgMgr; pCfgMgr = NULL; return -23; } if (pLogger != NULL) { pLogger->logMsg ("main", Logger::L_LowDetailDebug, "reading config file: %s\n", (const char*)cfgFilePath); } } else { if (pLogger != NULL) { pLogger->logMsg("main", Logger::L_SevereError, "could not find config file %s\n", (const char *)cfgFilePath); } delete pCfgMgr; pCfgMgr = NULL; return -24; } return 0; }