void SceneUtils::getHostUriString( const std::string address, std::string *host, std::string *uri) { size_t nextStartIndex = 0; int indexOfStr = 3; if (address.find(COAP_TAG) == std::string::npos) { indexOfStr = 1; } for (int i = 0; i < indexOfStr; i++) { nextStartIndex = address.find_first_of("/", nextStartIndex); if (nextStartIndex == std::string::npos) { throw RCSInvalidParameterException("address is invalid"); } nextStartIndex += 1; } *host = address.substr(0, nextStartIndex - 1); *uri = address.substr(nextStartIndex - 1, std::string::npos); }
Scene::Ptr SceneCollection::getScene(const std::string& sceneName) const { auto sceneValues = m_sceneCollectionResource->getSceneValues(); auto it = std::find(sceneValues.begin(), sceneValues.end(), sceneName); if(it != sceneValues.end()) { throw RCSInvalidParameterException("Scene Name is Invalid!"); } return Scene::Ptr(new Scene(sceneName, m_sceneCollectionResource)); }
Scene::Ptr SceneCollection::addNewScene(const std::string& sceneName) { if(sceneName.empty()) { throw RCSInvalidParameterException("Scene name is an empty string"); } m_sceneCollectionResource->addScene(sceneName); return Scene::Ptr(new Scene(sceneName, m_sceneCollectionResource)); }
RCSRemoteResourceObject::Ptr RCSRemoteResourceObject::fromOCResource( std::shared_ptr< OC::OCResource > ocResource) { if (!ocResource) { throw RCSInvalidParameterException("the oc resource must not be nullptr."); } return std::make_shared< RCSRemoteResourceObject >( PrimitiveResource::create(ocResource)); }
RemoteScene::Ptr RemoteSceneCollection::getRemoteScene(const std::string &sceneName) const { std::lock_guard< std::mutex > scenelock(m_sceneLock); auto itr = m_remoteScenes.find(sceneName); if (itr == m_remoteScenes.end()) { throw RCSInvalidParameterException("Invalid scene name"); } return itr->second; }
void RCSResourceObject::bindResource(const RCSResourceObject::Ptr& resource) { if (!resource || resource.get() == this) { throw RCSInvalidParameterException("The resource is invalid!"); } invokeOCFunc(OC::OCPlatform::bindResource, m_resourceHandle, resource->m_resourceHandle); std::lock_guard< std:: mutex > lock{ m_mutexForBoundResources }; m_boundResources.push_back(resource); }
void RemoteSceneCollection::addNewScene (const std::string &name, AddNewSceneCallback clientCB) { if (name.empty()) { throw RCSInvalidParameterException("Scene name is an empty string"); } if (!clientCB) { throw RCSInvalidParameterException{ "addNewScene : Callback is NULL" }; } SceneCollectionResourceRequestor::InternalSceneRequestCallback internalCB = std::bind(&RemoteSceneCollection::onSceneAddedRemoved, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::move(clientCB)); m_requestor->requestSceneCreation(name, internalCB); }