void P3LeafMesh::open_i(ServiceParamsPtr& params, int fttype) throw (ServiceException&) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T) INFO: P3LeafMesh::open_i(%d)\n"), m_status)); ACE_GUARD(ACE_SYNCH_RECURSIVE_MUTEX, ace_mon, m_lock); if (isStarting() /*|| isResuming()*/) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T) INFO: P3LeafMesh::open_i starting(%d)\n"), m_status)); //Task::activate(); int maxBindTries = 10000; //IncrementalSleep sleeper(1,0); //IncrementalSleep sleeper(0,1000); IncrementalSleep sleeper(0, DEFAULT_BIND_TIME); m_start = ACE_OS::gettimeofday(); for (int i = 0; i < maxBindTries; i++) { try { bind(true); return; } catch (ServiceException& bindEx) { //discard bindEx sleeper.sleep(); } } ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T) INFO: P3LeafMesh::open(): bind failed\n"))); throw ServiceException(ServiceException::REGISTRATION_ERROR); } else { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T) INFO: P3LeafMesh::open(): error\n"))); throw ServiceException(ServiceException::REGISTRATION_ERROR); } }
/** * @brief reserve a new VM from the local RM using VMInfo sent * by migration source host, * read VM space from source host and map into local RM */ void MigrationService::handleMigrationMigrateRequest(std::auto_ptr<network::Socket>& connectionPtr) throw (ServiceException&) { streaming::InputStream inputStream = connectionPtr->getInputStream(); // read VMInfo l4app::VMInfo vmInfo; if (inputStream.read(reinterpret_cast<char *>(&vmInfo), sizeof(vmInfo)) < 0) throw ServiceException("reading VMInfo"); // reserve VM l4app::Resourcemon resourcemon; L4_Word_t spaceId; if (resourcemon.reserveVM(vmInfo, &spaceId) < 0) throw ServiceException("reserving VM"); // send reply streaming::OutputStream outputStream = connectionPtr->getOutputStream(); Request reply; outputStream << reply; // read VM space int len = (1<<27); char *vmSpace = new char(len); // TODO: determine correct len if (inputStream.read(vmSpace, len) < 0) throw ServiceException("reading VM space"); // map to RM if (resourcemon.mapVMSpace(spaceId, vmSpace) < 0) throw ServiceException("mapping VM space"); outputStream << reply; }
ServiceAbstract* DefaultServiceFactory::getInstance(const UUIDPtr& sid) throw (ServiceException&) { ServiceAbstract* service = 0; if (m_services.find(sid, service) == -1) { throw ServiceException(ServiceException::SERVICE_NOT_KNOWN); } if (service == 0) { //paranoid check throw ServiceException(ServiceException::SERVICE_NOT_KNOWN); } return service->duplicate(); }
void SthenoCore::removeService(UUIDPtr& sid) throw (RuntimeException&, ServiceException&) { if (!isValid()) { throw RuntimeException(RuntimeException::INVALID_RUNTIME); } LocalServicePtr localService; if (m_serviceMap.find(sid, localService) == -1) { throw ServiceException(ServiceException::SERVICE_NOT_KNOWN); } if (m_serviceMap.unbind(sid) == 0) { throw ServiceException(ServiceException::SERVICE_NOT_KNOWN); } }
/* * start a migration process on the local host, * initiated by the mmcCtrl application */ void MigrationService::handleMigrationStartRequest(std::auto_ptr<network::Socket>& connectionPtr) throw (ServiceException&) { // read VMInfo from local RM l4app::Resourcemon resourcemon; l4app::VMInfo vmInfo; unsigned int spaceId = 0; resourcemon.getVMInfo(spaceId, vmInfo); try { // connect to destination network::Connector connector; unsigned short port = 6666; const char *host = "localhost"; std::auto_ptr<network::Socket> socketPtr = connector.connect(port, host); // send reserve request to destination streaming::OutputStream outputStream = socketPtr->getOutputStream(); Request reserveRequest(Request::MIGRATION_RESERVE); outputStream << reserveRequest; outputStream.copyBuffer(reinterpret_cast<char *>(&vmInfo), sizeof(vmInfo)); // check the reserve reply streaming::InputStream inputStream = socketPtr->getInputStream(); Request reply; inputStream >> reply; // map VM space and send to destination char *vm_space = NULL; resourcemon.getVMSpace(spaceId, vm_space); Request sendRequest(Request::MIGRATION_SEND); outputStream << sendRequest; outputStream.copyBuffer(vm_space, vmInfo.get_space_size()); // check send reply inputStream >> reply; // delete local VM resourcemon.deleteVM(spaceId); } catch (network::ConnectException& ce) { std::cerr << "ConnectException: " << ce.what() << std::endl; throw ServiceException("Migration Start Request Failed"); } catch (streaming::StreamingException& se) { std::cerr << "StreamingException: " << se.what() << std::endl; throw ServiceException("Migration Start Request Failed"); } }
Service::HttpStatus Service::CommandeService::remove(int id) { const Commande2* commande = commandeDB.getCommande(id); if (!commande) throw ServiceException(HttpStatus::NOT_FOUND, "Invalid commande id"); commandeDB.removeCommande(id); return HttpStatus::NO_CONTENT; }
HttpStatus ActionService::get (json::Value& out, int id) const { const int action = actionDB.getAction(id); if (!action) throw ServiceException(HttpStatus::NOT_FOUND,"Invalid action id"); out["id"] = action->id; return HttpStatus::OK; }
HttpStatus ActionService::remove (int id) { const int action = actionDB.getAction(id); if (!action) throw ServiceException(HttpStatus::NOT_FOUND,"Invalid action id"); actionDB.removeAction(id); return HttpStatus::NO_CONTENT; }
HttpStatus ActionService::post (const Json::Value& in, int id) { const int action = actionDB.getAction(id); if (!action) throw ServiceException(HttpStatus::NOT_FOUND,"Invalid action id"); actionDB.setAction(id); return HttpStatus::NO_CONTENT; }
Service::HttpStatus Service::CommandeService::get(Json::Value& out, int id) const { const Commande2* commande = commandeDB.getCommande(id); if (!commande) throw ServiceException(HttpStatus::NOT_FOUND, "Invalid commande id"); out["name"] = commande->name; out["id"] = commande->id; return HttpStatus::OK; }
void PeerInfo::getInstancesOfService(const UUIDPtr& sid, list<UUIDPtr>& l) throw (ServiceException&) { ServiceInfoPtr servicePtr; //ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)S=%s\n"), sid->toString().c_str())); if (m_serviceMap.find(sid, servicePtr) == -1) { throw ServiceException("Service not found!"); } servicePtr->getInstancesOfService(l); }
bool PeerInfo::getInstanceOfService(const UUIDPtr& sid, const UUIDPtr& iid, ServiceInstanceInfoPtr& instance) throw (ServiceException&) { ServiceInfoPtr servicePtr; if (m_serviceMap.find(sid, servicePtr) == -1) { throw ServiceException("Service not found!"); } return servicePtr->getInstanceOfService(iid, instance); }
ImagePtr ResourceLoader::load<Image>(std::string file) { FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; FIBITMAP* dib(0); BYTE* bits(0); unsigned int width(0), height(0); fif = FreeImage_GetFileType(file.c_str(),0); if(fif==FIF_UNKNOWN) { fif = FreeImage_GetFIFFromFilename(file.c_str()); } if(fif == FIF_UNKNOWN) { throw ServiceException("Cannot load file named: "+file); } if(FreeImage_FIFSupportsReading(fif)) dib = FreeImage_Load(fif,file.c_str()); if(!dib) throw ServiceException("Cannot load file named: "+file); //FreeImage_ConvertToRGBAF() dib = FreeImage_ConvertTo32Bits(dib); FreeImage_FlipVertical(dib); bits = FreeImage_GetBits(dib); width = FreeImage_GetWidth(dib); height = FreeImage_GetHeight(dib); if((bits == 0)||(width == 0)||(height == 0)) throw ServiceException("Cannot load file named: "+file); Pixel* p = reinterpret_cast<Pixel*>(bits); ImagePtr res = make_shared<Image>(p,width,height); FreeImage_Unload(dib); return res; }
void ServiceAbstract::changeState(int newState) throw (ServiceException&) { printf("ServiceAbstract::changeState(%d,%d\n", newState, m_status); ACE_GUARD(ACE_SYNCH_RECURSIVE_MUTEX, ace_mon, m_lock); switch (m_status) { case NOT_INIT: { handleNotInitState(newState); break; } case STARTING: { handleStartingState(newState); break; } case RUNNING: { handleRunningState(newState); break; } case SUSPENDING: { handleSuspendingState(newState); break; } case SUSPENDED: { handleSuspendedState(newState); break; } case FAULT: { handleFaultState(newState); break; } case RECOVERING: { handleRecoveringState(newState); break; } case CLOSING: { handleClosingState(newState); break; } case CLOSED: { handleClosedState(newState); break; } default: throw ServiceException(ServiceException::INSUFFICIENT_RESOURCES); } m_status = newState; }
UUIDPtr& DefaultServiceFactory::getServiceName(const char* name) throw (ServiceException&) { ACE_Hash_Map_Manager<UUIDPtr, ServiceAbstract*, ACE_SYNCH_RW_MUTEX>::iterator iter = m_services.begin(); while (iter != m_services.end()) { if (ACE_OS::strcmp(iter->item()->getName(),name) == 0) { return iter->key(); } iter++; } throw ServiceException(ServiceException::SERVICE_NOT_KNOWN); }
list<UUIDPtr>* SthenoCore::getInstancesOfServiceUUIDs(UUIDPtr& sid) throw (RuntimeException&, ServiceException&) { if (!isValid()) { throw RuntimeException(RuntimeException::INVALID_RUNTIME); } LocalServicePtr servicePtr; ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)S=%s\n"), sid->toString().c_str())); if (m_serviceMap.find(sid, servicePtr) == -1) { throw ServiceException("Service not found!"); } return servicePtr->getInstancesOfService(); }
bool SthenoCore::getInstanceOfService(UUIDPtr& sid, UUIDPtr& iid, ServiceAbstractPtr& instance) throw (RuntimeException&, ServiceException&) { if (!isValid()) { throw RuntimeException(RuntimeException::INVALID_RUNTIME); } LocalServicePtr servicePtr; if (m_serviceMap.find(sid, servicePtr) == -1) { throw ServiceException("Service not found!"); } return servicePtr->getInstanceOfService(iid, instance); }
void P3LeafMesh::createRemoteService(const SAPInfo* hint, const UUIDPtr& uuid, const UUIDPtr& sid, ServiceParamsPtr& params, UUIDPtr& iid) throw (ServiceException&) { ACE_GUARD(ACE_SYNCH_RECURSIVE_MUTEX, ace_mon, m_lock); if (hint == 0) { throw ServiceException(ServiceException::SERVICE_WITHOUT_IMPL); } Endpoint endpoint; ACE_Connector<P3MeshClientHandler, ACE_SOCK_Connector> connector; hint->getFirstEndpoint(endpoint); QoSEndpoint qosE = *(endpoint.getQoS()); UUIDPtr runtimeUUID; getUUID(runtimeUUID); UUIDPtr fid; getFID(fid); P3MeshClientHandler* clientHandler = new P3MeshClientHandler( runtimeUUID, fid, qosE, false, false, 0, 0, 0, 0); if (connector.connect(clientHandler, endpoint.getAddr()) == -1) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%T)%@\n"), ACE_TEXT("(%T)ERROR: P3Mesh::createRemoteService - connect failed:"))); clientHandler->close(); clientHandler = 0; delete clientHandler; } else { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: P3LeafMesh::createRemoteService - Connect OK!\n"))); } int ret = clientHandler->createService(params, iid); clientHandler->close(); delete clientHandler; if (ret == -1) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: P3LeafMesh::createRemoteService - failed to create, not enough resources\n"))); throw ServiceException(ServiceException::INSUFFICIENT_RESOURCES); } ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: P3LeafMesh::createRemoteService - service created!\n"))); }
Service::HttpStatus Service::CommandeService::post(const Json::Value& in, int id) { const Commande2* commande = commandeDB.getCommande(id); if (!commande) throw ServiceException(HttpStatus::NOT_FOUND, "Invalid commande id"); std::unique_ptr<Commande2> commandemod(new Commande2(*commande)); if (in.isMember("name")) { commandemod->name = in["name"].asString(); } if (in.isMember("id")) { commandemod->id = in["id"].asInt(); } commandeDB.setCommande(id, std::move(commandemod)); return HttpStatus::NO_CONTENT; }
void P3ReplicationGroup::openReplica() throw (ServiceException&) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: P3ReplicationGroup::open() - REPLICA() replicaCount=%d\n"), m_replicas.size())); /*list<OverlayPeerInfoPtr>::iterator iter = m_replicas.begin(); while (iter != m_replicas.end()) { addReplica(*iter); iter++; }*/ //add itself MeshPtr meshPtr; try { m_ft->getOverlay()->getMesh(meshPtr); } catch (OverlayException& ex) { throw ServiceException(ServiceException::LOW_LVL_P2P_UNAVAILABLE); } SAPInfoPtr meshSapInfo; meshPtr->getSAP(meshSapInfo); SAPInfoPtr ftSapInfo; m_ft->getSAP(ftSapInfo); UUIDPtr uuid; m_ft->getOverlay()->getUUID(uuid); UUIDPtr fid; meshPtr->getFID(fid); OverlayPeerInfo* ourReplicaInfo = new OverlayPeerInfo( uuid, fid, meshSapInfo, ftSapInfo, m_dataSAP.getSAPInfo() ); OverlayPeerInfoPtr replicaInfoPtr(ourReplicaInfo); //addReplica(replicaInfoPtr); m_replicas.push_back(replicaInfoPtr); this->printMembers(); //Bootstrap service! //m_ft->getOverlay()->getRuntime()->createLocalServiceReplica(m_sid,m_params,m_svcPtr); //debug /*ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: P3ReplicationGroup::open() - REPLICA() service lanuched (%@) iid=%s!\n"), m_svcPtr.get(),m_svcPtr->getIID()->toString().c_str()));*/ //remove this (just for remembering) //m_svcPtr->open(m_params,ServiceAbstract::FT_REPLICA); ReplicationGroupPtr rgPtr; m_ft->getReplicationGroup(this->getGroupUUID(), rgPtr); ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: P3ReplicationGroup::open() - REPLICA() middle replicaCount=%d\n"), m_replicas.size())); //ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: P3ReplicationGroup::open() - REPLICA() middle replicaCount=%d\n"), m_replicas.size())); m_svcPtr->setReplicationGroup(rgPtr); ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: P3ReplicationGroup::open() - REPLICA() final replicaCount=%d\n"), m_replicas.size())); }
void ServiceAbstract::handleClosedState(int newState) throw (ServiceException&) { switch (newState) { case NOT_INIT: case STARTING: case RUNNING: case SUSPENDING: case SUSPENDED: case FAULT: case CLOSING: case CLOSED: case RECOVERING: default: throw ServiceException(ServiceException::INVALID_STATE); } }
void ServiceAbstract::handleSuspendingState(int newState) throw (ServiceException&) { switch (newState) { case NOT_INIT: case STARTING: case RUNNING: case SUSPENDING: case FAULT: case CLOSED: default: throw ServiceException(ServiceException::INVALID_STATE); case SUSPENDED: case CLOSING: break; } }
void SthenoCore::removeService(UUIDPtr& sid, UUIDPtr& iid) throw (RuntimeException&, ServiceException&) { if (!isValid()) { throw RuntimeException(RuntimeException::INVALID_RUNTIME); } LocalServicePtr localService; if (m_serviceMap.find(sid, localService) == -1) { throw ServiceException(ServiceException::SERVICE_NOT_KNOWN); } ServiceAbstractPtr sPtr; try { localService->removeServiceInstance(iid); } catch (ServiceException& ex) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)SthenoCore:removeService: error on getInstance!\n"))); throw ex; } }
SoundEffectPtr ResourceLoader::load<SoundEffect>(std::string file){ SoundEffectPtr res = nullptr; vector<char> delimiters(3); delimiters.push_back('.'); delimiters.push_back('/'); delimiters.push_back('\\'); string file_ext = Utils::split(file,delimiters).back(); if(file_ext == "wav"){ res = loadWAV(file); }else{ throw ServiceException("Unimplemented resource loader"); } return res; }
void SthenoCore::getInstanceOfService(UUIDPtr& sid, UUIDPtr& iid, ServiceInstanceInfoPtr& info) throw (RuntimeException&, ServiceException&) { if (!isValid()) { throw RuntimeException(RuntimeException::INVALID_RUNTIME); } LocalServicePtr servicePtr; ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: SthenoCore::getInstanceOfService(sid,iid,info) - SID=%s IID=%s\n"), sid->toString().c_str(), iid->toString().c_str() )); if (m_serviceMap.find(sid, servicePtr) == -1) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)ERROR: SthenoCore::getInstanceOfService(sid,iid,info) - Error not found SID=%s\n"), sid->toString().c_str())); throw ServiceException(ServiceException::SERVICE_NOT_KNOWN); } //ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)after ifo S=%s\n"), sid->toString().c_str())); servicePtr->getInstancesOfServiceInfo(iid, info); ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: SthenoCore::getInstanceOfService(sid,iid,info) - Found SID=%s!!!\n"), sid->toString().c_str())); }
void SthenoCore::startService(UUIDPtr& sid, UUIDPtr& peerID, ServiceParamsPtr& params, UUIDPtr& iid) throw (RuntimeException&, ServiceException&) { ACE_Time_Value start = ACE_OS::gettimeofday(); FindPeerQuery* queryPeer = new FindPeerQuery(peerID); DiscoveryPtr discovery; try { m_overlay->getDiscovery(discovery); } catch (OverlayException& ex) { throw RuntimeException(RuntimeException::INVALID_OVERLAY); } DiscoveryQueryReply* replyPeer = discovery->executeQuery(queryPeer); FindPeerQueryReply* replyPeerNarrow = new FindPeerQueryReply(replyPeer); if (replyPeerNarrow->isException()) { printf("Peer is now known!\n"); throw ServiceException(ServiceException::SERVICE_NOT_KNOWN); } printf("Before service remote deployment SAP=%s\n", replyPeerNarrow->getPeerInfo()->getFID()->toString().c_str()); MeshPtr meshPtr; try { getOverlay()->getMesh(meshPtr); } catch (OverlayException& ex) { throw RuntimeException(RuntimeException::INVALID_OVERLAY); } try { meshPtr->createRemoteService(replyPeerNarrow->getPeerInfo()->getMeshSAP().get(), peerID, sid, params, iid); } catch (ServiceException& se) { delete replyPeerNarrow; throw se; } printf("After service remote deployment\n"); ACE_Time_Value end = ACE_OS::gettimeofday(); end -= start; if (trace()) { MeshPtr meshPtr; this->getOverlay()->getMesh(meshPtr); UUIDPtr fid; meshPtr->getFID(fid); if (params->getFTParams().null()) { TraceRuntimeSingleton::instance()->logRemoteServiceCreation(this->m_peerID, fid, sid, iid, end); } else { TraceRuntimeSingleton::instance()->logRemoteServiceCreationFT(this->m_peerID, fid, sid, iid, end); } } delete replyPeerNarrow; }
void SthenoCore::createServiceInstance(UUIDPtr& sid, UUIDPtr& iid, ServiceAbstractPtr& sPtr) throw (RuntimeException&, ServiceException&) { if (!isValid()) { throw RuntimeException(RuntimeException::INVALID_RUNTIME); } LocalServicePtr servicePtr; if (m_serviceMap.find(sid, servicePtr) == -1) { printf("INFO: createServiceInstance() - SID=%s not found service!\n", sid->toString().c_str()); LocalService* ls = new LocalService(sid); servicePtr.reset(ls); if (m_serviceMap.bind(sid, servicePtr) != 0) { throw ServiceException("Error on binding service"); } } printf("INFO: createServiceInstance() - SID=%s found service!\n", sid->toString().c_str()); ServiceAbstract* i = m_serviceFactory.getInstance(sid); i->setIID(iid); ServiceAbstractPtr iPtr(i); servicePtr->addServiceInstance(iPtr); sPtr = iPtr; }
void P3ReplicationGroup::open() throw (ServiceException&) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: P3ReplicationGroup::open()()\n"))); m_closed = false; list<QoSEndpoint> qosList; //QoSEndpoint hrt(QoS::HRT, CPUQoS::MED_RT_PRIO); QoSEndpoint hrt(QoS::HRT, CPUQoS::MAX_RT_PRIO); qosList.push_back(hrt); String itf; if (!P3Configuration::instance()->lookupValue("DEFAULT_INTERFACE", itf)) { throw ServiceException(ServiceException::INVALID_ARGUMENT); } m_dataSAP.open(itf, qosList); if (isPrimary()) { //open as primary openPrimary(); } else { //open as replica openReplica(); } }
void SthenoCore::changeIIDOfService(UUIDPtr& sid, UUIDPtr& iid, UUIDPtr& newIid) throw (RuntimeException&, ServiceException&) { if (!isValid()) { throw RuntimeException(RuntimeException::INVALID_RUNTIME); } LocalServicePtr servicePtr; if (m_serviceMap.find(sid, servicePtr) == -1) { throw ServiceException(ServiceException::SERVICE_NOT_KNOWN); } servicePtr->setIID(iid, newIid); ServiceInstanceInfoPtr info; servicePtr->getInstancesOfServiceInfo(newIid, info); //info has the newIid MeshPtr meshPtr; try { getOverlay()->getMesh(meshPtr); } catch (OverlayException& ex) { throw RuntimeException(RuntimeException::INVALID_OVERLAY); } meshPtr->onServiceUpdateIID(sid, iid, newIid); }
void MediaRendererDevice::onControlActionRequest(Upnp_Action_Request* pRequest) { //log::debug("Renderer: action request: %s", pRequest->ActionName); xml::Document requestDoc(pRequest->ActionRequest, xml::Document::NoOwnership); //log::debug(requestDoc.toString()); switch (serviceIdUrnStringToService(pRequest->ServiceID)) { case ServiceType::AVTransport: pRequest->ActionResult = m_AVTransport.onAction(pRequest->ActionName, requestDoc).getActionDocument(); break; case ServiceType::RenderingControl: pRequest->ActionResult = m_RenderingControl.onAction(pRequest->ActionName, requestDoc).getActionDocument(); break; case ServiceType::ConnectionManager: pRequest->ActionResult = m_ConnectionManager.onAction(pRequest->ActionName, requestDoc).getActionDocument(); break; default: throw ServiceException("Invalid subscribtionId", 401); } }