From 0ef91ba0e785e07034aec84c2069cbf4073817bd Mon Sep 17 00:00:00 2001 From: Minji Park Date: Thu, 4 Feb 2016 20:22:40 +0900 Subject: [PATCH] Add Scene List Resource Requestor class for scene manager client It is the scene manager remote-side requestor class which sends request for scene collection creation to local-side scene list resource object. Change-Id: I2c11cc635417feb1c97b81812a7659f7189b8269 Signed-off-by: Minji Park Reviewed-on: https://gerrit.iotivity.org/gerrit/4941 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- service/scene-manager/SConscript | 5 +- .../src/SceneListResourceRequestor.cpp | 109 +++++++++++++++++++++ .../scene-manager/src/SceneListResourceRequestor.h | 78 +++++++++++++++ 3 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 service/scene-manager/src/SceneListResourceRequestor.cpp create mode 100644 service/scene-manager/src/SceneListResourceRequestor.h diff --git a/service/scene-manager/SConscript b/service/scene-manager/SConscript index 85295c8..a1d1feb 100755 --- a/service/scene-manager/SConscript +++ b/service/scene-manager/SConscript @@ -87,7 +87,10 @@ scenemanager_src = [ SCENE_SRC_DIR + 'SceneListResourceObject.cpp', SCENE_SRC_DIR + 'SceneCollectionResourceObject.cpp', SCENE_SRC_DIR + 'SceneMemberResourceObject.cpp', - SCENE_SRC_DIR + 'SceneUtils.cpp' + SCENE_SRC_DIR + 'SceneUtils.cpp', + SCENE_SRC_DIR + 'SceneListResourceRequestor.cpp', + SCENE_SRC_DIR + 'SceneCollectionResourceRequestor.cpp', + SCENE_SRC_DIR + 'SceneMemberResourceRequestor.cpp' ] if target_os in ['tizen','android'] : diff --git a/service/scene-manager/src/SceneListResourceRequestor.cpp b/service/scene-manager/src/SceneListResourceRequestor.cpp new file mode 100644 index 0000000..b63594b --- /dev/null +++ b/service/scene-manager/src/SceneListResourceRequestor.cpp @@ -0,0 +1,109 @@ +//****************************************************************** +// +// Copyright 2016 Samsung Electronics All Rights Reserved. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +#include "SceneListResourceRequestor.h" +#include "RemoteSceneUtils.h" + +namespace OIC +{ + namespace Service + { + + SceneListResourceRequestor::SceneListResourceRequestor + (RCSRemoteResourceObject::Ptr pSceneList) + : m_SceneListResourcePtr{ pSceneList } + { + SCENE_CLIENT_ASSERT_NOT_NULL(pSceneList); + } + + SceneListResourceRequestor::~SceneListResourceRequestor() + { + + } + + void SceneListResourceRequestor::requestSceneCollectionCreation + (const std::string &name, InternalCreateSceneCollectionCallback internalCB) + { + RCSResourceAttributes attrs; + attrs[SCENE_KEY_NAME] = name; + + RCSRemoteResourceObject::SetCallback setRequestCB + = std::bind(&SceneListResourceRequestor::onSceneCollectionCreated, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, + name, std::move(internalCB), + SceneListResourceRequestor::wPtr(shared_from_this())); + + RCSQueryParams queryParams; + queryParams.setResourceInterface(SCENE_CLIENT_CREATE_REQ_IF); + + m_SceneListResourcePtr->set(queryParams, std::move(attrs), std::move(setRequestCB)); + } + + void SceneListResourceRequestor::requestSetName + (const std::string &, InternalSetNameCallback) + { + + } + + void SceneListResourceRequestor::onSceneCollectionCreated + (const HeaderOpts &headOpts, const RCSRepresentation &rep, int eCode, + const std::string &name, const InternalCreateSceneCollectionCallback &cb, + SceneListResourceRequestor::wPtr ptr) + { + SceneListResourceRequestor::Ptr listPtr = ptr.lock(); + + if (listPtr) + listPtr->onSceneCollectionCreated_impl(headOpts, std::move(rep), eCode, + name, std::move(cb)); + } + + void SceneListResourceRequestor::onSceneCollectionCreated_impl + (const HeaderOpts &, const RCSRepresentation &rep, int eCode, + const std::string &name, const InternalCreateSceneCollectionCallback &internalCB) + { + // TODO: error code + int result = SCENE_CLIENT_BADREQUEST; + std::string link, id; + + if (eCode == SCENE_RESPONSE_SUCCESS) + { + try + { + RCSResourceAttributes attrs = rep.getAttributes(); + + if (attrs.at(SCENE_KEY_NAME).get< std::string >().compare(name) == 0) + { + link = attrs.at(SCENE_KEY_PAYLOAD_LINK).get< std::string >(); + id = attrs.at(SCENE_KEY_ID).get< std::string >(); + result = SCENE_RESPONSE_SUCCESS; + } + } + catch (const std::exception &e) + { + SCENE_CLIENT_PRINT_LOG(e.what()); + result = SCENE_SERVER_INTERNALSERVERERROR; + } + } + + internalCB(link, id, name, result); + } + + } +} \ No newline at end of file diff --git a/service/scene-manager/src/SceneListResourceRequestor.h b/service/scene-manager/src/SceneListResourceRequestor.h new file mode 100644 index 0000000..5754106 --- /dev/null +++ b/service/scene-manager/src/SceneListResourceRequestor.h @@ -0,0 +1,78 @@ +//****************************************************************** +// +// Copyright 2016 Samsung Electronics All Rights Reserved. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +#ifndef SM_SCENELIST_RESOURCE_REQUESTOR_H_ +#define SM_SCENELIST_RESOURCE_REQUESTOR_H_ + +#include "SceneCommons.h" +#include "RCSRemoteResourceObject.h" +#include "RCSRepresentation.h" + +namespace OIC +{ + namespace Service + { + + class SceneListResourceRequestor + : public std::enable_shared_from_this< SceneListResourceRequestor > + { + public: + typedef std::shared_ptr< SceneListResourceRequestor > Ptr; + typedef std::weak_ptr< SceneListResourceRequestor > wPtr; + + typedef std::function + < void(const std::string &link, const std::string &id, + const std::string &name, int eCode) > + InternalCreateSceneCollectionCallback; + + typedef std::function + < void(int eCode) > InternalSetNameCallback; + + + public: + SceneListResourceRequestor(RCSRemoteResourceObject::Ptr pSceneList); + ~SceneListResourceRequestor(); + + void requestSceneCollectionCreation + (const std::string &name, InternalCreateSceneCollectionCallback); + + void requestSetName(const std::string &, InternalSetNameCallback); + + + private: + static void onSceneCollectionCreated + (const HeaderOpts &, const RCSRepresentation &, int eCode, + const std::string &name, const InternalCreateSceneCollectionCallback &, + SceneListResourceRequestor::wPtr); + + void onSceneCollectionCreated_impl + (const HeaderOpts &, const RCSRepresentation &, int eCode, + const std::string &name, const InternalCreateSceneCollectionCallback &); + + + private: + RCSRemoteResourceObject::Ptr m_SceneListResourcePtr; + }; + + } +} + +#endif /* SM_SCENELIST_RESOURCE_REQUESTOR_H_ */ + -- 2.7.4