Creating your own main

You can use the following example to create your own main.

int main (int argc, char *argv[]) { [...] // variable declaration // create a broker that contain module. // Create broker will automatically load network dynamic library and run server ALPtr<ALBroker> broker = ALBroker::createBroker(brokerName, brokerIp, brokerPort, "", 0); // ALBrokerManager is the only singleton. // Warning depending on plateform posix or win32 singleton // (or static variable) are duplicated in every dynamic library broker->setBrokerManagerInstance(ALBrokerManager::getInstance()); // if listen on 0.0.0.0, get an IP (ethernet or wifi) // to allow client/server communication if (brokerIp == "0.0.0.0") broker->updateIPFromOS(); try { brokerPort = broker->getPort(); } catch(ALError & /*e*/) { std::cout << "Network error. Wait a little and retry." << std::endl; exit(AL_ERROR_EXIT_CODE_NETWORK_BUSY); } try { // Waiting for the broker to be initialized (server is in another thread) SleepMs( 500 ); // launcher will manage autoload.ini broker->getLibraryManager()->loadLibrary("launcher"); // launcher will run the autolaod.ini file } AL_CATCH_ERR( printf( "\nException caught by NAOqi. System may be unstable...\n" ); ); #ifndef WIN32 struct sigaction new_action; /* Set up the structure to specify the new action. */ new_action.sa_handler = ALTools::_termination_handler; sigemptyset (&new_action.sa_mask); new_action.sa_flags = 0; sigaction (SIGINT, &new_action, NULL); sigaction (SIGTERM, &new_action, NULL); # else signal( SIGINT, ALTools::_termination_handler ); #endif #ifdef WIN32 #endif // WIN32 // smart pointer is in ALBrokerManager, we can reset this one broker.reset(); while(true) { SleepMs(1000); } #ifdef _WIN32 ALTools::_termination_handler(0); #endif }





Copyright © 2010 Aldebaran-Robotics - All rights reserved