coredata::dmcp::ModuleExitCodeMessage::ModuleExitCode ClientModule::runModule() { // Try to discover supercomponent. try { SharedPointer<discoverer::Client> discovererClient = SharedPointer<discoverer::Client>( new discoverer::Client(getMultiCastGroup(), coredata::dmcp::Constants::BROADCAST_PORT_SERVER, coredata::dmcp::Constants::BROADCAST_PORT_CLIENT, getName())); bool supercomponentFound = false; uint32_t attempt = 0; while ( !supercomponentFound && ( attempt < coredata::dmcp::Constants::CONNECTION_RETRIES)) { CLOG1 << "(ClientModule) discovering supercomponent..." << endl; supercomponentFound = discovererClient->existsServer(); attempt++; } if ( !supercomponentFound ) { CLOG1 << "(ClientModule) no supercomponent running for " << getMultiCastGroup() << endl; return coredata::dmcp::ModuleExitCodeMessage::NO_SUPERCOMPONENT; } m_serverInformation = discovererClient->getServerInformation(); CLOG1 << "(ClientModule) supercomponent found at " << m_serverInformation.toString() << endl; } catch (...) { CLOG1 << "(ClientModule) error while discovering supercomponent." << endl; return coredata::dmcp::ModuleExitCodeMessage::SERIOUS_ERROR; } CLOG1 << "(ClientModule) connecting to supercomponent..." << endl; string myVersion = "No version set."; ModuleDescriptor md(getName(), getIdentifier(), myVersion, getFrequency()); try { // Try to get configuration from DMCP server. m_dmcpClient = SharedPointer<connection::Client>( new connection::Client(md, m_serverInformation)); m_dmcpClient->setSupercomponentStateListener(this); m_dmcpClient->initialize(); // Get configuration from DMCP client. m_keyValueConfiguration = m_dmcpClient->getConfiguration(); } catch (ConnectException& e) { CLOG1 << "(ClientModule) connecting to supercomponent failed: " << e.getMessage() << endl; return coredata::dmcp::ModuleExitCodeMessage::SERIOUS_ERROR; } CLOG1 << "(ClientModule) connecting to supercomponent...done - managed level: " << m_serverInformation.getManagedLevel() << endl; // Run user implementation from derived ConferenceClientModule. coredata::dmcp::ModuleExitCodeMessage::ModuleExitCode retVal = runModuleImplementation(); if (m_dmcpClient.isValid()) { m_dmcpClient->sendModuleExitCode(retVal); } return retVal; }
ModuleState::MODULE_EXITCODE ClientModule::runModule() { ModuleState::MODULE_EXITCODE retVal = ModuleState::OKAY; // Try to discover supercomponent. ServerInformation serverInformation; try { SharedPointer<discoverer::Client> discovererClient = SharedPointer<discoverer::Client>( new discoverer::Client(getMultiCastGroup(), BROADCAST_PORT_SERVER, BROADCAST_PORT_CLIENT)); bool supercomponentFound = false; uint32_t attempt = 0; while ( !supercomponentFound && ( attempt < CONNECTION_RETRIES)) { clog << "(ClientModule) discovering supercomponent..." << endl; supercomponentFound = discovererClient->existsServer(); attempt++; } if ( !supercomponentFound ) { clog << "(ClientModule) no supercomponent running for " << getMultiCastGroup() << endl; return ModuleState::NO_SUPERCOMPONENT; } serverInformation = discovererClient->getServerInformation(); clog << "(ClientModule) supercomponent found at " << serverInformation.toString() << endl; } catch (...) { clog << "(ClientModule) error while discovering supercomponent." << endl; return ModuleState::SERIOUS_ERROR; } clog << "(ClientModule) connecting to supercomponent..." << endl; string myVersion = "No version set."; ModuleDescriptor md(getName(), getIdentifier(), myVersion); try { // Try to get configuration from DMCP server. m_dmcpClient = SharedPointer<connection::Client>( new connection::Client(md, serverInformation)); m_dmcpClient->setSupercomponentStateListener(this); m_dmcpClient->initialize(); // Get configuration from DMCP client. m_keyValueConfiguration = m_dmcpClient->getConfiguration(); } catch (ConnectException& e) { clog << "(ClientModule) connecting to supercomponent failed: " << e.getMessage() << endl; return ModuleState::SERIOUS_ERROR; } clog << "(ClientModule) connecting to supercomponent...done" << endl; try { // Setup the module itself. setUp(); setModuleState(ModuleState::RUNNING); m_dmcpClient->sendModuleState(ModuleState::RUNNING); // Execute the module's body. retVal = body(); setModuleState(ModuleState::NOT_RUNNING); m_dmcpClient->sendModuleState(ModuleState::NOT_RUNNING); // Clean up. tearDown(); } catch (std::exception &e) { // Try to catch any exception derived from std::exception and print32_t out reason. clog << e.what() << endl; retVal = ModuleState::EXCEPTION_CAUGHT; } catch (std::string &str) { clog << "string exception caught in ClientModule::run()" << endl; clog << str << endl; retVal = ModuleState::SERIOUS_ERROR; } catch (...) { // Try to catch anything else print32_t generic error. clog << "Unknown exception caught in ClientModule::run()" << endl; retVal = ModuleState::SERIOUS_ERROR; } if (m_dmcpClient.isValid()) { m_dmcpClient->sendModuleExitCode(retVal); } return retVal; }