void ProfilerCommunication::RequestInformation(BR buildRequest, PR processResults, DWORD dwTimeout, tstring message) { try { buildRequest(); DWORD dwSignal = m_eventProfilerRequestsInformation.SignalAndWait(m_eventInformationReadyForProfiler, dwTimeout); if (WAIT_OBJECT_0 != dwSignal) throw CommunicationException(dwSignal); m_eventInformationReadyForProfiler.Reset(); BOOL hasMore = FALSE; do { hasMore = processResults(); if (hasMore) { dwSignal = m_eventInformationReadByProfiler.SignalAndWait(m_eventInformationReadyForProfiler, COMM_WAIT_SHORT); if (WAIT_OBJECT_0 != dwSignal) throw CommunicationException(dwSignal); m_eventInformationReadyForProfiler.Reset(); } }while (hasMore); m_eventInformationReadByProfiler.Set(); } catch (CommunicationException ex) { RELTRACE(_T("ProfilerCommunication::RequestInformation(...) => Communication (Chat channel - %s) with host has failed (0x%x)"), message.c_str(), ex.getReason()); hostCommunicationActive = false; } }
bool DEProtoProxy::receiveFromServer(DEPacket& pkt) { long pktSize = 0; // Get Packet size. if (!this->server->receive((void*)&pktSize, sizeof(unsigned long), this->paramTimeout)) { BOOST_THROW_EXCEPTION(CommunicationException() << errorMessage("Unable to receive message size from server.\n")); } else { this->recvBufferNew.resizeIfNeeded(pktSize); } if (!this->server->receive((void*)this->recvBufferNew.getBufferPtr(), pktSize, this->paramTimeout * 2)) { BOOST_THROW_EXCEPTION(CommunicationException() << errorMessage("Unable to receive message from server.\n")); } if (!pkt.ParseFromArray(this->recvBufferNew.getBufferPtr(), pktSize)) { BOOST_THROW_EXCEPTION(CommunicationException() << errorMessage("Unable to parse message on receipt from server.\n")); } return true; }
bool DEProtoProxy::get_Image(void* image, unsigned int length) { boost::lock_guard<boost::mutex>(*this->server->getTransactionMutex()); DEPacket pkt, dataHeader; pkt.set_type(DEPacket::P_COMMAND); SingleCommand* cmd = pkt.add_command(); cmd->set_command_id(k_GetImage); this->sendCommand(pkt); this->receiveFromServer(dataHeader); if (dataHeader.type() != DEPacket::P_DATA_HEADER || !dataHeader.has_data_header()) BOOST_THROW_EXCEPTION(ProtocolException() << errorMessage("Did not receive expected data header for image.")); this->imgBuffer.resizeIfNeeded(static_cast<std::size_t>(dataHeader.data_header().bytesize())); if (!this->server->receive(this->imgBuffer.getBufferPtr(), static_cast<std::size_t>(dataHeader.data_header().bytesize()), this->imageTimeout)) { BOOST_THROW_EXCEPTION(CommunicationException() << errorMessage("Unable to receive image from server.")); } if (dataHeader.data_header().bytesize() != length) { BOOST_THROW_EXCEPTION(CommandException() << errorMessage ("Image received did not have the expected size")); } memcpy(image, this->imgBuffer.getBufferPtr(), length); return true; }
/******************************************************************************** * Functions */ INetworkAccessProvider* CommunicationService::provider() { instance(); if (_instance->_provider == 0) { throw CommunicationException("No provider defined."); } return _instance->_provider; }
void VsftpdConfigHandler::restart() const { int exitStatus = ServiceManager::restart(m_serviceName); if (exitStatus == 1) { std::string err("The process crashed."); throw CommunicationException(err.c_str()); } }
void Provider::bindObjectToName(const char* name, CORBA::Object_ptr objectRef) { try { CosNaming::Name objectName; objectName.length(2); objectName[0].id = CONTEXT_NAME_ID; objectName[0].kind = CONTEXT_NAME_KIND; objectName[1].id = name; objectName[1].kind = CONTEXT_OBJECT_KIND; try { this->_naming->bind(objectName, objectRef); } catch(CosNaming::NamingContext::AlreadyBound& ex) { this->_naming->rebind(objectName, objectRef); } } catch(CORBA::TRANSIENT &) { throw CommunicationException("The naming service could not be found, make sure it is correctly started."); } catch(CORBA::SystemException & e) { throw CommunicationException(QString("Receive a corba system error: ") + e._name()); } }
IServerConfigurationProvider* Provider::getServiceClient(const QString& name) { if (CORBA::is_nil(this->_naming)) { throw CommunicationException("Naming service is not properly started, cannot locate provider"); } try { CosNaming::Name cname; cname.length(2); cname[0].id = CONTEXT_NAME_ID; cname[0].kind = CONTEXT_NAME_KIND; cname[1].id = name.toStdString().c_str(); cname[1].kind = CONTEXT_OBJECT_KIND; return new ServiceClientAdapter(ServerConfigHandler::_narrow(this->_naming->resolve(cname))); } catch (const CORBA::COMM_FAILURE& e) { throw CommunicationException("Cannot communicate with the naming service, make sure it is still alive."); } catch (...) { throw CommunicationException("An unknown error occurred, unable to retrieve the requested service."); } return 0; }
void Provider::registerServiceProvider(const QString& name, IServerConfigurationProvider* provider) { if (CORBA::is_nil(this->_naming)) { throw CommunicationException("Naming service is not properly started, cannot register provider"); } try { ServiceAdapter* handler = new ServiceAdapter(provider); _handlers[provider->getServerName()] = handler; this->_poa->activate_object(handler); this->bindObjectToName(name.toStdString().c_str(), handler->_this()); handler->_remove_ref(); this->_poa->the_POAManager()->activate(); } catch(const CORBA::SystemException& e) { throw CommunicationException(QString("Receive a corba system error: ") + e._name()); } catch(const CORBA::Exception& e) { throw CommunicationException(QString("Receive a corba error: ") + e._name()); } catch(const omniORB::fatalException& e) { throw CommunicationException(QString("Receive an omniORB fatal error: ") + e.errmsg()); } }
void ProfilerCommunication::SendVisitPoints() { if (!hostCommunicationActive) return; try { DWORD dwSignal = m_eventProfilerHasResults.SignalAndWait(m_eventResultsHaveBeenReceived, COMM_WAIT_SHORT); if (WAIT_OBJECT_0 != dwSignal) throw CommunicationException(dwSignal); m_eventResultsHaveBeenReceived.Reset(); } catch (CommunicationException ex) { RELTRACE(_T("ProfilerCommunication::SendVisitPoints() => Communication (Results channel) with host has failed (0x%x)"), ex.getReason()); hostCommunicationActive = false; } return; }
void CommunicationService::configure(INetworkAccessProvider::MODE::mode mode, const QMap<QString, QString>& options) { instance(); if (_instance->_provider == 0) { throw CommunicationException("No provider defined."); } // Register custom type into QMetaType system qRegisterMetaTypeStreamOperators<int>("IServerConfigurationProvider_INTERNET_PROTOCOL"); qRegisterMetaTypeStreamOperators<int>("IServerConfigurationProvider_VIRTUAL_USER_AUTHENTICATION"); // Configure provider try { _instance->_provider->configure(mode, options); } catch (const CommunicationException& e) { qCritical() << "Error while configuring the network provider: " << e.message(); } }
void VsftpdConfigHandler::importConfiguration(const QString & configuration) { QFile file(m_parser.filename()); if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) { std::string err("Unable to access configuration file."); std::cerr << err << std::endl; throw CommunicationException(err.c_str()); } QTextStream out(&file); out << configuration; file.close(); }
QString VsftpdConfigHandler::exportConfiguration() const { QFile file(m_parser.filename()); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { std::string err("Unable to access configuration file."); std::cerr << err << std::endl; throw CommunicationException(err.c_str()); } QTextStream in(&file); QString data = in.readAll(); file.close(); return data; }
bool DEProtoProxy::sendToServer(DEPacket& pkt) { int sz = sizeof(unsigned long); pkt.set_camera_name(this->_cameraName); int pktSize = pkt.ByteSize(); this->sendBufferNew.resetOffset(); this->sendBufferNew.add(pktSize); this->sendBufferNew.add(pkt); if (!this->server->send(this->sendBufferNew.getBufferPtr(), pktSize + sz, 5)) { BOOST_THROW_EXCEPTION(CommunicationException() << errorMessage("Unable to send message to server") << boost::errinfo_file_name(__FILE__) << boost::errinfo_at_line(__LINE__) <<errorPacket(pkt)); } return true; }
void Provider::configure(MODE::mode mode, const QMap<QString, QString>& options) { qDebug() << "Configuring CORBA Provider..."; // Provider... try { char* args[] = { 0 }; int argc = 0; // const char* opts[options.size() + 1][2]; // opts[options.size()][0] = 0; // opts[options.size()][1] = 0; // int i = 0; // for (QMap<QString, QString>::const_iterator it = options.begin(); it != options.end(); i++, it++) { // opts[i][0] = strdup(it.key().toStdString().c_str()); // opts[i][1] = strdup(it.value().toStdString().c_str()); // } const char* opts[2][2]; if (options.contains("InitRef")) { opts[0][0] = strdup("InitRef"); opts[0][1] = strdup(options["InitRef"].toStdString().c_str()); } else { opts[0][0] = 0; opts[0][1] = 0; } opts[1][0] = 0; opts[1][1] = 0; this->_orb = CORBA::ORB_init(argc, args, "omniORB4", opts); if (mode == INetworkAccessProvider::MODE::SERVER) { this->_poa = PortableServer::POA::_narrow(this->_orb->resolve_initial_references("RootPOA")); if (CORBA::is_nil(this->_poa)) { throw CommunicationException("Failed to narrow the root POA."); } } this->_naming = CosNaming::NamingContext::_narrow(this->_orb->resolve_initial_references("NameService")); if (CORBA::is_nil(this->_naming)) { throw CommunicationException("Failed to narrow the root naming context."); } if (mode == INetworkAccessProvider::MODE::SERVER) { CosNaming::Name contextName; contextName.length(1); contextName[0].id = CONTEXT_NAME_ID; contextName[0].kind = CONTEXT_NAME_KIND; try { this->_naming->bind_new_context(contextName); } catch(CosNaming::NamingContext::AlreadyBound& ex) { //std::cerr << "Server context already exists, trying to narrow existing context." << std::endl; if (CORBA::is_nil(CosNaming::NamingContext::_narrow(this->_naming->resolve(contextName)))) { throw CommunicationException("Failed to narrow naming context."); } } } // For details on CORBA Exception: // http://techpubs.borland.com/am/bes/v6/en/updates/except_cpp.html } catch (const CORBA::NO_RESOURCES& e) { throw CommunicationException("No resources found, please verify the configuration of omniORB."); } catch (const CORBA::ORB::InvalidName& e) { throw CommunicationException("Service required is invalid or does not exist."); } catch(const CORBA::TRANSIENT& e) { throw CommunicationException("The naming service could not be found, make sure it is correctly started."); } catch(CORBA::SystemException & e) { throw CommunicationException(QString("Receive a CORBA system error: ") + e._name()); } catch(const CORBA::Exception& e) { std::string err(); throw CommunicationException(QString("Receive a CORBA error: ") + e._name()); } catch(const omniORB::fatalException& e) { std::string err(); throw CommunicationException(QString("Receive an omniORB fatal error: ") + e.errmsg()); } catch (const CommunicationException& e) { throw e; } catch (...) { throw CommunicationException("An unknown error occurred while configuring the network layer."); } qDebug() << "Configuration of CORBA Provider done, ready."; }