int main(int argc, char *argv[]) /* Process command line. */ { char *command; bzpTime(NULL); dnaUtilOpen(); setMaxAlloc(2LL*1024LL*1024LL*1024LL); optionInit(&argc, argv, options); port = optionInt("port", port); host = optionVal("host", host); netParseSubnet(optionVal("subnet", NULL), subnet); cpuCount = optionInt("cpu", cpuCount); if (argc < 2) usage(); command = argv[1]; if (sameWord(command, "start")) { if (argc < 3) usage(); serverStart(argv+2, argc-2); } else if (sameWord(command, "stop")) { serverStop(); } else if (sameWord(command, "status")) { serverStatus(); } else usage(); return 0; }
MyApplication::MyApplication(int argc, char *argv[]): _bridge(150), _audioStarter(_bridge), _menu(_bridge) { QObject::connect(&_menu, SIGNAL(destroyed()), &_audioStarter, SLOT(stop())); QObject::connect(&_menu, SIGNAL(serverStart()), &_audioStarter, SLOT(run())); QObject::connect(&_menu, SIGNAL(serverStop()), &_audioStarter, SLOT(stop())); }
void PluginQt::setServerPort(quint16 val) { if (val == m_serverPort) return; m_serverPort = val; serverStop(); if (m_isServerEnabled) { serverStart(); } }
void PluginQt::setServerEnabled(bool val) { if (val == m_isServerEnabled) return; m_isServerEnabled = val; if (m_isServerEnabled && m_serverPort > 0) { serverStart(); } else if (!m_isServerEnabled) serverStop(); }
int main(int argc, char ** argv ) { if ( argc < 2 ) { printf( "Usage: %s <iniFile>\n", argv[0] ); return 0; } Event serverStop( CharString().format("StopProcess%u", Process::getCurrentProcessId()) ); // read the settings Settings config( "LogServer", argv[1] ); // initialize the logging first thing before we do anything else.. std::string logFile( config.get( "logFile", "LogServer.log" ) ); std::string logExclude( config.get( "logExclude", "" ) ); unsigned int nLogLevel = config.get( "logLevel", LL_STATUS ); new FileReactor( logFile, nLogLevel, logExclude ); int nPort = config.get( "Port", 10000 ); int nMaxClients = config.get( "MaxClients", 128 ); int nCPT = config.get( "CPT", 8 ); // start the server LogServer theServer; if (! theServer.start( nLogLevel, nPort, nMaxClients ) ) return -1; // run the server forever, unless it crashes while( theServer.running() ) { if ( serverStop.signaled() ) break; Thread::sleep( 1000 ); } theServer.stop(); return 0; }
virtual void TearDown() { clientStop(); serverStop(); }
NetworkManager::~NetworkManager() { LuaDebugging::studioLink(NULL); serverStop(); }
int main( int argc, char ** argv ) { CharString iniFile = "./ProcessServer.ini"; if ( argc > 1 ) iniFile = argv[1]; Settings settings( "ProcessServer", iniFile ); // initialize the logging first thing before we do anything else.. std::string logFile( settings.get( "logFile", "ProcessServer.log" ) ); std::string logExclude( settings.get( "logExclude", "" ) ); unsigned int nMinLogLevel = settings.get( "logLevel", LL_STATUS ); new FileReactor( logFile, nMinLogLevel, logExclude ); bool bRemoteUpdate = settings.get( "remoteUpdate", 1 ) != 0; bool bLocalUpdate = settings.get( "localUpdate", (dword)0 ) != 0; CharString sPath( FileDisk::currentDirectory() ); if (! sPath.endsWith( PATH_SEPERATOR ) ) sPath += PATH_SEPERATOR; #if !defined(_DEBUG) // update the files if ( settings.get( "doUpdate", 1 ) != 0 ) { settings.put( "doUpdate", (dword)0 ); if ( bLocalUpdate ) { CharString updatePath = settings.get( "localUpdatePath", "" ); if ( updatePath.length() > 0 ) { FileDisk::normalizePath( updatePath.buffer() ); if (! updatePath.endsWith( PATH_SEPERATOR ) ) updatePath += PATH_SEPERATOR; // copy the files from a directory if ( localUpdate( sPath, updatePath ) ) return -3; // let the service/script update our files.. } } } #endif // do the update next time! settings.put( "doUpdate", 1 ); ProcessServer::Context context; context.logFile = logFile.c_str(); context.name = settings.get( "name", "ProcessServer" ); context.config = iniFile; context.gameId = settings.get( "gameId", 1 ); context.processGroup = settings.get( "processGroup", 1 ); context.networkGroup = settings.get( "networkGroup", 1 ); context.metaAddress = settings.get( "metaAddress", "meta-server.palestar.com" ); context.metaPort = settings.get( "metaPort", 9000 ); context.uid = settings.get( "uid", "DSS" ); context.pw = settings.get( "pw", "darkspace" ); context.address = settings.get( "address", "" ); context.port = settings.get( "port", 8000 ); context.maxClients = settings.get( "maxClients", 1000 ); context.processFile = iniFile; context.syncClock = settings.get ("syncClock", (dword)0 ) != 0; // start the server MyProcessServer theServer; if (! theServer.start( context ) ) return -1; // signal that we are running Event serverRunning( "ProcessServerRun" ); serverRunning.signal(); dword nNextUpdateCheck = Time::seconds() + settings.get("updateTime",300); dword nLastCRC = 0; // run the server forever, unless it crashes Event serverStop( "ProcessServerStop" ); while( theServer.running() && !theServer.shutdownCompleted() ) { if (! serverStop.wait( 10 ) ) { LOG_STATUS( "ProcessServer", "Recevied shutdown signal." ); theServer.shutdown(); serverStop.clear(); } theServer.update(); theServer.updatePerformanceMonitor(); #if !defined(_DEBUG) if ( bRemoteUpdate && nNextUpdateCheck < Time::seconds() ) { // check for new code update MirrorClient mirrorClient; if ( mirrorClient.open( settings.get( "mirrorAddress", "mirror-server.palestar.com" ), settings.get( "mirrorPort", 9200 ), sPath, NULL, true ) ) { // attempt to login, ingore if failed mirrorClient.login( settings.get( "uid", "" ), settings.get( "pw", "" ) ); // get the CRC only, only do a sync if remote files have been changed... dword nCRC = mirrorClient.getCRC(); if ( nCRC != nLastCRC ) { nLastCRC = nCRC; dword nJobID = mirrorClient.syncronize(); if ( nJobID != 0 && mirrorClient.waitJob( nJobID, 86400 * 1000 ) ) { int nWarningTime = settings.get( "warningTime", 300 ); LOG_STATUS( "ProcessServer", "Files updated -- Restarting the server in %d seconds.", nWarningTime ); CharString sWarningMessage = settings.get( "warningMessage", CharString().format("/notice /%s Updating in $T...", context.name.cstr() ) ); while( nWarningTime > 0 ) { CharString sTimeLeft; sTimeLeft.format("%d %s", nWarningTime > 60 ? nWarningTime / 60 : nWarningTime, nWarningTime > 60 ? "minute(s)" : "second(s)"); // replace the "$T" token with the time remaining... CharString sChat = sWarningMessage; sChat.replace( "$T", sTimeLeft ); theServer.sendChat( sChat ); int nSleepTime = 0; if ( nWarningTime > (60 * 10) ) nSleepTime = 60 * 5; // sleep for 5 minutes else nSleepTime = 60; // sleep for 1 minute if ( nSleepTime > nWarningTime ) nSleepTime = nWarningTime; nWarningTime -= nSleepTime; dword nEndSleep = Time::seconds() + nSleepTime; while( Time::seconds() < nEndSleep ) { if (! serverStop.wait( 10 ) ) { LOG_STATUS( "ProcessServer", "Received stop signal, stopping now." ); nSleepTime = nWarningTime = 0; // stop now... no warning break; } theServer.update(); theServer.updatePerformanceMonitor(); } } // start the shutdown, server will exit once the last process has stopped.. theServer.shutdown(); } } mirrorClient.close(); } else { LOG_ERROR( "ProcessServer", "Failed to connect to MirrorServer!" ); } nNextUpdateCheck = Time::seconds() + settings.get("updateTime",300); } #endif } theServer.stop(); return 0; }
void CMediaControlServerProfile::onBufferReceived(const iviLink::Channel::tChannelId channel, iviLink::CBuffer const& buffer) { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__); if (mChannelID != channel) { LOG4CPLUS_INFO(msLogger, "mChannelID != channel_id"); return; } else { LOG4CPLUS_INFO(msLogger, "mChannelID == channel_id"); } UInt8 *incomingData = buffer.getBuffer(); int read_size = buffer.getSize(); LOG4CPLUS_INFO(msLogger, "Procedure ID = " + convertIntegerToString(incomingData[0])); if(incomingData[0] == STOP) { LOG4CPLUS_INFO(msLogger, "case STOP"); mpAppCallbacks->onServerStop(); mpServControl->sendCommand(mpServControl->mStop); } else if(incomingData[0] == SERVERSTOP) { LOG4CPLUS_INFO(msLogger, "case SERVERSTOP"); serverStop(); } else if(incomingData[0] == PAUSE) { LOG4CPLUS_INFO(msLogger, "case PAUSE"); mpAppCallbacks->onServerPause(); mpServControl->sendCommand(mpServControl->mPause); } else if(incomingData[0] == RESUME) { LOG4CPLUS_INFO(msLogger, "case RESUME"); resume(); } else if(incomingData[0] == SYNC) { LOG4CPLUS_INFO(msLogger, "case SYNC"); mpAppCallbacks->onServerSync(); } else if(incomingData[0] == UNSYNC) { LOG4CPLUS_INFO(msLogger, "case UNSYNC"); mpAppCallbacks->onServerUnsync(); } else if(incomingData[0] == TOGGLE) { LOG4CPLUS_INFO(msLogger, "case TOGGLE"); mpAppCallbacks->onServerToggle(); } else if(incomingData[0] == PLAY) { LOG4CPLUS_INFO(msLogger, "case PLAY"); std::string message((char*)(incomingData + 1), read_size - 1); LOG4CPLUS_INFO(msLogger, "message = " + message); vector<string> parse_result; split(message, ";", parse_result); if (parse_result.size() == 3) { LOG4CPLUS_INFO(msLogger, parse_result[0]); LOG4CPLUS_INFO(msLogger, parse_result[1]); LOG4CPLUS_INFO(msLogger, parse_result[2]); LOG4CPLUS_INFO(msLogger, "get message:" + parse_result[0] + " ; " + parse_result[1] + " ; " + parse_result[2]); play(parse_result[0], parse_result[1], parse_result[2]); } else { LOG4CPLUS_INFO(msLogger, "cannot parse message"); } } else { LOG4CPLUS_INFO(msLogger, "unknown procedure ID"); } }