Updated control logic of Scene Resource.
authorjyong2.kim <jyong2.kim@samsung.com>
Wed, 24 Feb 2016 01:13:38 +0000 (10:13 +0900)
committerUze Choi <uzchoi@samsung.com>
Wed, 24 Feb 2016 11:40:40 +0000 (11:40 +0000)
Resource management logic is updated.
 (scene execution, scene resource creation, attributes setting)
Getting method of scene values is added in Scene Collection Resource class.
Setting method of resource name is added in Scene Resource class.
Get response of remote side request is added in Scene List class.
Callback of scene execution is called separated thread for prevent recursive function call.

Change-Id: Id7d66bc3216d51a46015b9653e254f93a0e68380
Signed-off-by: jyong2.kim <jyong2.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5151
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/scene-manager/src/SceneCollectionResource.cpp
service/scene-manager/src/SceneCollectionResource.h
service/scene-manager/src/SceneCommons.h
service/scene-manager/src/SceneListResource.cpp
service/scene-manager/src/SceneListResource.h
service/scene-manager/src/SceneMemberResource.cpp
service/scene-manager/src/SceneMemberResource.h

index d2e2117..72008b4 100644 (file)
@@ -23,6 +23,7 @@
 #include <atomic>
 #include "OCApi.h"
 #include "RCSRequest.h"
+#include "RCSSeparateResponse.h"
 
 namespace OIC
 {
@@ -36,41 +37,51 @@ namespace OIC
         SceneCollectionResource::Ptr
         SceneCollectionResource::createSceneCollectionObject()
         {
-            auto instance = new SceneCollectionResource();
-            SceneCollectionResource::Ptr newSceneCollectionObject;
-            newSceneCollectionObject.reset(instance);
+            SceneCollectionResource::Ptr newSceneCollectionObject(new SceneCollectionResource());
 
-            newSceneCollectionObject->m_Uri
+            newSceneCollectionObject->m_uri
                 = PREFIX_SCENE_COLLECTION_URI + "/" + std::to_string(numOfSceneCollection++);
 
-            newSceneCollectionObject->m_SceneCollectionResourceObj
+            newSceneCollectionObject->m_address = SceneUtils::getNetAddress();
+
+            newSceneCollectionObject->createResourceObject();
+
+            newSceneCollectionObject->setDefaultAttributes();
+
+            newSceneCollectionObject->initSetRequestHandler();
+
+            return newSceneCollectionObject;
+        }
+
+        void SceneCollectionResource::createResourceObject()
+        {
+            m_sceneCollectionResourceObj
                 = RCSResourceObject::Builder(
-                        newSceneCollectionObject->m_Uri,
-                        SCENE_COLLECTION_RT, OC_RSRVD_INTERFACE_DEFAULT).
+                        m_uri, SCENE_COLLECTION_RT, OC_RSRVD_INTERFACE_DEFAULT).
                         addInterface(OC::BATCH_INTERFACE).
                         setDiscoverable(true).setObservable(false).build();
+        }
 
-            auto collectionObj = newSceneCollectionObject->m_SceneCollectionResourceObj;
-            {
-                RCSResourceObject::LockGuard guard(collectionObj);
-                collectionObj->setAttribute(SCENE_KEY_LAST_SCENE, std::string());
-                collectionObj->setAttribute(SCENE_KEY_NAME, std::string());
-                collectionObj->setAttribute(SCENE_KEY_ID, SceneUtils::OICGenerateUUIDStr());
-                collectionObj->setAttribute(SCENE_KEY_RTS, SCENE_MEMBER_RT);
-                collectionObj->setAttribute(SCENE_KEY_SCENEVALUES, std::vector<std::string>());
-            }
+        void SceneCollectionResource::setDefaultAttributes()
+        {
+            m_sceneCollectionResourceObj->setAttribute(SCENE_KEY_LAST_SCENE, std::string());
+            m_sceneCollectionResourceObj->setAttribute(SCENE_KEY_NAME, std::string());
+            m_sceneCollectionResourceObj->setAttribute(
+                    SCENE_KEY_ID, SceneUtils::OICGenerateUUIDStr());
+            m_sceneCollectionResourceObj->setAttribute(SCENE_KEY_RTS, SCENE_MEMBER_RT);
+            m_sceneCollectionResourceObj->setAttribute(
+                    SCENE_KEY_SCENEVALUES, std::vector<std::string>());
+            m_sceneCollectionResourceObj->setAttribute(SCENE_KEY_URI, m_uri);
+        }
 
-            newSceneCollectionObject->m_RequestHandler.m_Owner
-                = std::weak_ptr<SceneCollectionResource>(newSceneCollectionObject);
+        void SceneCollectionResource::initSetRequestHandler()
+        {
+            m_requestHandler.m_owner
+                = std::weak_ptr<SceneCollectionResource>(shared_from_this());
 
-            collectionObj->setSetRequestHandler(std::bind(
+            m_sceneCollectionResourceObj->setSetRequestHandler(std::bind(
                     &SceneCollectionResource::SceneCollectionRequestHandler::onSetRequest,
-                    newSceneCollectionObject->m_RequestHandler,
-                    std::placeholders::_1, std::placeholders::_2));
-
-            newSceneCollectionObject->m_Address = SceneUtils::getNetAddress();
-
-            return newSceneCollectionObject;
+                    m_requestHandler, std::placeholders::_1, std::placeholders::_2));
         }
 
         void SceneCollectionResource::addScene(const std::string & newScene)
@@ -80,7 +91,7 @@ namespace OIC
 
         void SceneCollectionResource::addScene(std::string && newScene)
         {
-            auto sceneValues = m_SceneCollectionResourceObj->getAttributeValue(
+            auto sceneValues = m_sceneCollectionResourceObj->getAttributeValue(
                     SCENE_KEY_SCENEVALUES).get< std::vector< std::string > >();
 
             auto foundScene
@@ -89,37 +100,28 @@ namespace OIC
             {
                 sceneValues.push_back(std::move(newScene));
 
-                RCSResourceObject::LockGuard guard(m_SceneCollectionResourceObj);
-                m_SceneCollectionResourceObj->setAttribute(
-                        SCENE_KEY_SCENEVALUES, sceneValues);
+                m_sceneCollectionResourceObj->setAttribute(SCENE_KEY_SCENEVALUES, sceneValues);
             }
         }
 
         void SceneCollectionResource::addSceneMember(
                 SceneMemberResource::Ptr newMember)
         {
-            std::unique_lock<std::mutex> memberlock(m_SceneMemberLock);
+            std::lock_guard<std::mutex> memberlock(m_sceneMemberLock);
 
-            struct FindMember
-            {
-                bool operator()(SceneMemberResource::Ptr ptr) const
-                {
-                    return ptr->getFullUri() == name;
-                }
-                std::string name;
-            };
-            FindMember fMember;
-            fMember.name = newMember->getFullUri();
-            auto foundmember = std::find_if(
-                    m_SceneMembers.begin(), m_SceneMembers.end(), fMember);
-            if (foundmember != m_SceneMembers.end())
+            auto foundmember = std::find_if(m_sceneMembers.begin(), m_sceneMembers.end(),
+                    [& newMember](const SceneMemberResource::Ptr & ptr) -> bool
+                    {
+                        return ptr->getFullUri() == newMember->getFullUri();
+                    });
+
+            if (foundmember != m_sceneMembers.end())
             {
-                // TODO will change to Scene Exception.
                 throw std::exception();
             }
 
-            m_SceneMembers.push_back(newMember);
-            m_SceneCollectionResourceObj->bindResource(newMember->getRCSResourceObject());
+            m_sceneMembers.push_back(newMember);
+            m_sceneCollectionResourceObj->bindResource(newMember->getRCSResourceObject());
         }
 
         void SceneCollectionResource::execute(std::string && sceneName)
@@ -141,17 +143,14 @@ namespace OIC
         void SceneCollectionResource::execute(
                 std::string && sceneName, SceneExecuteCallback executeCB)
         {
-            auto sceneValues = m_SceneCollectionResourceObj->getAttributeValue(
+            auto sceneValues = m_sceneCollectionResourceObj->getAttributeValue(
                     SCENE_KEY_SCENEVALUES).get< std::vector< std::string > >();
+
             auto foundSceneValue
                 = std::find(sceneValues.begin(), sceneValues.end(), sceneName);
-
-            if (foundSceneValue == sceneValues.end())
+            if (foundSceneValue == sceneValues.end() && executeCB)
             {
-                if (executeCB)
-                {
-                    executeCB(SCENE_CLIENT_BADREQUEST);
-                }
+                std::thread(executeCB, SCENE_CLIENT_BADREQUEST).detach();
                 return;
             }
 
@@ -159,66 +158,70 @@ namespace OIC
                 = SceneExecuteResponseHandler::createExecuteHandler(
                         shared_from_this(), std::move(executeCB));
 
-            std::unique_lock<std::mutex> handlerlock(m_ExecuteHandlerLock);
-            m_ExecuteHandlers.push_back(executeHandler);
-            handlerlock.unlock();
+            {
+                std::lock_guard<std::mutex> handlerlock(m_executeHandlerLock);
+                m_executeHandlers.push_back(executeHandler);
+            }
 
-            std::unique_lock<std::mutex> memberlock(m_SceneMemberLock);
-            for (unsigned int it = 0; it < m_SceneMembers.size(); ++it)
             {
-                m_SceneMembers[it]->execute(sceneName, std::bind(
-                        &SceneExecuteResponseHandler::onResponse, executeHandler,
-                        std::placeholders::_1, std::placeholders::_2));
+                std::lock_guard<std::mutex> memberlock(m_sceneMemberLock);
+                for (auto & it : m_sceneMembers)
+                {
+                    it->execute(sceneName, std::bind(
+                            &SceneExecuteResponseHandler::onResponse, executeHandler,
+                            std::placeholders::_1, std::placeholders::_2));
+                }
             }
-            memberlock.unlock();
 
-            RCSResourceObject::LockGuard guard(m_SceneCollectionResourceObj);
-            m_SceneCollectionResourceObj->setAttribute(SCENE_KEY_LAST_SCENE, sceneName);
+            m_sceneCollectionResourceObj->setAttribute(SCENE_KEY_LAST_SCENE, sceneName);
         }
 
         void SceneCollectionResource::onExecute(
                 int errorCode, SceneExecuteCallback cb, SceneExecuteResponseHandler::Ptr ptr)
         {
-            std::unique_lock<std::mutex> handlerlock(m_ExecuteHandlerLock);
-            m_ExecuteHandlers.remove(ptr);
-            handlerlock.unlock();
+            {
+                std::lock_guard<std::mutex> handlerlock(m_executeHandlerLock);
+                m_executeHandlers.remove(ptr);
+            }
 
-            cb(errorCode);
+            std::thread(cb, errorCode).detach();
         }
 
         std::string SceneCollectionResource::getId() const
         {
-            return m_SceneCollectionResourceObj->
-                    getAttributeValue(SCENE_KEY_ID).get<std::string>();
+            return m_sceneCollectionResourceObj->getAttributeValue(
+                    SCENE_KEY_ID).get<std::string>();
         }
 
         std::string SceneCollectionResource::getUri() const
         {
-            return m_Uri;
+            return m_uri;
         }
 
         std::string SceneCollectionResource::getAddress() const
         {
-            return m_Address;
+            return m_address;
         }
 
-        const std::vector<SceneMemberResource::Ptr>
-        SceneCollectionResource::getSceneMembers()
+        std::vector<std::string> SceneCollectionResource::getSceneValues() const
         {
-            std::unique_lock<std::mutex> memberlock(m_SceneMemberLock);
-            std::vector<SceneMemberResource::Ptr> retMembers(m_SceneMembers);
-            return retMembers;
+            return m_sceneCollectionResourceObj->getAttributeValue(
+                    SCENE_KEY_SCENEVALUES).get<std::vector<std::string>>();
+        }
+
+        std::vector<SceneMemberResource::Ptr> SceneCollectionResource::getSceneMembers() const
+        {
+            return m_sceneMembers;
         }
 
         RCSResourceObject::Ptr SceneCollectionResource::getRCSResourceObject() const
         {
-            return m_SceneCollectionResourceObj;
+            return m_sceneCollectionResourceObj;
         }
 
         void SceneCollectionResource::setName(std::string && sceneCollectionName)
         {
-            RCSResourceObject::LockGuard guard(m_SceneCollectionResourceObj);
-            m_SceneCollectionResourceObj->setAttribute(
+            m_sceneCollectionResourceObj->setAttribute(
                     SCENE_KEY_NAME, std::move(sceneCollectionName));
         }
 
@@ -229,7 +232,7 @@ namespace OIC
 
         std::string SceneCollectionResource::getName() const
         {
-            return m_SceneCollectionResourceObj->getAttributeValue(
+            return m_sceneCollectionResourceObj->getAttributeValue(
                     SCENE_KEY_NAME).get<std::string>();
         }
 
@@ -251,92 +254,85 @@ namespace OIC
                 return executeSceneRequest(request, attributes);
             }
 
-            return RCSSetResponse::create(attributes, (int)SCENE_CLIENT_BADREQUEST)
-            .setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
+            if (attributes.contains(SCENE_KEY_NAME))
+            {
+                return setSceneCollectionName(request, attributes);
+            }
+
+            return RCSSetResponse::create(attributes, (int)SCENE_CLIENT_BADREQUEST).
+                    setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
         }
 
         RCSSetResponse SceneCollectionResource::SceneCollectionRequestHandler::
         addSceneRequest(const RCSRequest & /*request*/, RCSResourceAttributes & attributes)
         {
-            SceneCollectionResource::Ptr ptr = m_Owner.lock();
+            SceneCollectionResource::Ptr ptr = m_owner.lock();
             if (ptr == nullptr)
             {
-                return RCSSetResponse::create(
-                        RCSResourceAttributes(attributes), SCENE_CLIENT_BADREQUEST).
+                return RCSSetResponse::create(attributes, SCENE_CLIENT_BADREQUEST).
                         setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
             }
 
-            auto scenes = attributes.at(SCENE_KEY_SCENEVALUES).get<std::vector<std::string>>();
-
-            for(unsigned int it = 0; it < scenes.size(); ++it)
-            {
-                ptr->addScene(scenes[it]);
-            }
+            auto values = attributes.at(SCENE_KEY_SCENEVALUES).get<std::vector<std::string>>();
+            std::for_each (values.begin(), values.end(),
+                    [& ptr](const std::string & value)
+                    {
+                        ptr->addScene(value);
+                    });
 
-            return RCSSetResponse::create(RCSResourceAttributes(attributes)).
+            return RCSSetResponse::create(attributes).
                     setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
         }
 
         RCSSetResponse SceneCollectionResource::SceneCollectionRequestHandler::
-        executeSceneRequest(const RCSRequest & /*request*/, RCSResourceAttributes & attributes)
+        executeSceneRequest(const RCSRequest & request, RCSResourceAttributes & attributes)
         {
-            SceneCollectionResource::Ptr ptr = m_Owner.lock();
+            SceneCollectionResource::Ptr ptr = m_owner.lock();
             if (ptr == nullptr)
             {
-                return RCSSetResponse::create(
-                        RCSResourceAttributes(attributes), SCENE_CLIENT_BADREQUEST).
+                return RCSSetResponse::create(attributes, SCENE_CLIENT_BADREQUEST).
                         setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
             }
 
-            auto request_key = attributes.at(SCENE_KEY_LAST_SCENE).get<std::string>();
-            ptr->execute(std::string(request_key), std::bind(
+            auto requestKey = attributes.at(SCENE_KEY_LAST_SCENE).get<std::string>();
+
+            RCSRequest req(request.getResourceObject().lock(), request.getOCRequest());
+            ptr->execute(std::string(requestKey), std::bind(
                     &SceneCollectionResource::SceneCollectionRequestHandler::onExecute, this,
-                    std::placeholders::_1,
-                    attributes));
+                    std::placeholders::_1, req, attributes));
 
-            // TODO slow response
-            return RCSSetResponse::create(RCSResourceAttributes(attributes))
-            .setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
+            return RCSSetResponse::separate();
         }
 
         RCSSetResponse SceneCollectionResource::SceneCollectionRequestHandler::
         createSceneMemberRequest(const RCSRequest & /*request*/, RCSResourceAttributes & attributes)
         {
-            SceneCollectionResource::Ptr ptr = m_Owner.lock();
+            SceneCollectionResource::Ptr ptr = m_owner.lock();
             if (ptr == nullptr || !attributes.contains(SCENE_KEY_PAYLOAD_LINK))
             {
-                return RCSSetResponse::create(
-                        RCSResourceAttributes(attributes), SCENE_CLIENT_BADREQUEST).
+                return RCSSetResponse::create(attributes, SCENE_CLIENT_BADREQUEST).
                         setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
             }
 
             auto linkAtt = attributes.at(SCENE_KEY_PAYLOAD_LINK).get<RCSResourceAttributes>();
-
-            auto memberObj
-                = SceneMemberResource::createSceneMemberResource(linkAtt);
-
-            try
+            if (!linkAtt.contains(SCENE_KEY_HREF) ||
+                    !linkAtt.contains(SCENE_KEY_RT) || !linkAtt.contains(SCENE_KEY_IF))
             {
-                ptr->addSceneMember(memberObj);
-            } catch (...)
+                return RCSSetResponse::create(attributes, SCENE_CLIENT_BADREQUEST).
+                        setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
+            }
+
+            auto memberObj = createSceneMemberFromRemote(linkAtt);
+            if (memberObj == nullptr)
             {
-                memberObj.reset();
-                return RCSSetResponse::create(
-                        RCSResourceAttributes(attributes), SCENE_CLIENT_BADREQUEST).
+                return RCSSetResponse::create(attributes, SCENE_CLIENT_BADREQUEST).
                         setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
             }
 
             if (attributes.contains(SCENE_KEY_SCENEMAPPINGS))
             {
-                auto sceneMappings
-                    = attributes.at(SCENE_KEY_SCENEMAPPINGS).get<std::vector<RCSResourceAttributes>>();
-                for (unsigned int it = 0; it < sceneMappings.size(); ++it)
-                {
-                    memberObj->addMappingInfo(SceneMemberResource::MappingInfo(
-                            sceneMappings[it].at(SCENE_KEY_SCENE).get<std::string>(),
-                            sceneMappings[it].at(SCENE_KEY_MEMBERPROPERTY).get<std::string>(),
-                            sceneMappings[it].at(SCENE_KEY_MEMBERVALUE)));
-                }
+                addMemberInfoFromRemote(memberObj, attributes.at(
+                        SCENE_KEY_SCENEMAPPINGS).get<std::vector<RCSResourceAttributes>>());
             }
 
             RCSResourceAttributes responseAtt(attributes);
@@ -344,14 +340,64 @@ namespace OIC
             responseAtt[SCENE_KEY_CREATEDLINK]
                         = RCSResourceAttributes::Value(memberObj->getFullUri());
 
-            return RCSSetResponse::create(responseAtt)
-            .setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
+            return RCSSetResponse::create(responseAtt).
+                    setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
+        }
+
+        RCSSetResponse
+        SceneCollectionResource::SceneCollectionRequestHandler::setSceneCollectionName(
+                const RCSRequest & /*request*/, RCSResourceAttributes & attr)
+        {
+            SceneCollectionResource::Ptr ptr = m_owner.lock();
+            if (ptr == nullptr)
+            {
+                return RCSSetResponse::create(attr, SCENE_CLIENT_BADREQUEST).
+                        setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
+            }
+
+            ptr->setName(attr.at(SCENE_KEY_NAME).get<std::string>());
+
+            return RCSSetResponse::create(attr).
+                    setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
+        }
+
+        SceneMemberResource::Ptr
+        SceneCollectionResource::SceneCollectionRequestHandler::createSceneMemberFromRemote(
+                RCSResourceAttributes & linkAtt)
+        {
+            auto memberObj = SceneMemberResource::createSceneMemberResource(linkAtt);
+
+            try
+            {
+                SceneCollectionResource::Ptr ptr = m_owner.lock();
+                ptr->addSceneMember(memberObj);
+            } catch (...)
+            {
+                return nullptr;
+            }
+
+            return memberObj;
+        }
+
+        void SceneCollectionResource::SceneCollectionRequestHandler::addMemberInfoFromRemote(
+                SceneMemberResource::Ptr memberObj, std::vector<RCSResourceAttributes> mInfo)
+        {
+            std::for_each (mInfo.begin(), mInfo.end(),
+                    [& memberObj](const RCSResourceAttributes & att)
+                    {
+                        memberObj->addMappingInfo(SceneMemberResource::MappingInfo(
+                                att.at(SCENE_KEY_SCENE).get<std::string>(),
+                                att.at(SCENE_KEY_MEMBERPROPERTY).get<std::string>(),
+                                att.at(SCENE_KEY_MEMBERVALUE)));
+                    });
         }
 
         void SceneCollectionResource::SceneCollectionRequestHandler::
-        onExecute(int /*errorCode*/, /*const RCSRequest & request,*/ RCSResourceAttributes & /*att*/)
+        onExecute(int /*errorCode*/, const RCSRequest & request, RCSResourceAttributes & /*att*/)
         {
-            // TODO slow response
+            // TODO need to set error code.
+            // and need to set specific attr' but this attr not to be apply to RCSResourceObject.
+            RCSSeparateResponse(request).set();
         }
 
         void SceneCollectionResource::SceneExecuteResponseHandler::
@@ -364,7 +410,7 @@ namespace OIC
             }
             if (m_responseMembers == m_numOfMembers)
             {
-                m_Cb(m_errorCode);
+                m_cb(m_errorCode);
             }
         }
 
@@ -374,14 +420,14 @@ namespace OIC
         {
             auto executeHandler = std::make_shared<SceneExecuteResponseHandler>();
 
-            executeHandler->m_numOfMembers = ptr->m_SceneMembers.size();
+            executeHandler->m_numOfMembers = ptr->m_sceneMembers.size();
             executeHandler->m_responseMembers = 0;
 
-            executeHandler->m_Cb = std::bind(
+            executeHandler->m_cb = std::bind(
                     &SceneCollectionResource::onExecute, ptr,
                     std::placeholders::_1, std::move(executeCB), executeHandler);
 
-            executeHandler->m_Owner
+            executeHandler->m_owner
                 = std::weak_ptr<SceneCollectionResource>(ptr);
             executeHandler->m_errorCode  = SCENE_RESPONSE_SUCCESS;
 
@@ -389,3 +435,4 @@ namespace OIC
         }
     }
 }
+
index acc2ec5..55c396e 100644 (file)
@@ -55,13 +55,15 @@ namespace OIC
             void setName(std::string &&);
             void setName(const std::string &);
 
+            std::vector<std::string> getSceneValues() const;
+
             std::string getName() const;
 
             std::string getId() const;
             std::string getUri() const;
             std::string getAddress() const;
 
-            const std::vector<SceneMemberResource::Ptr> getSceneMembers();
+            std::vector<SceneMemberResource::Ptr> getSceneMembers() const;
 
             RCSResourceObject::Ptr getRCSResourceObject() const;
 
@@ -71,14 +73,15 @@ namespace OIC
             public:
                 typedef std::shared_ptr<SceneExecuteResponseHandler> Ptr;
 
-                SceneExecuteResponseHandler() = default;
+                SceneExecuteResponseHandler()
+                : m_numOfMembers(0), m_responseMembers(0), m_errorCode(0) { }
                 ~SceneExecuteResponseHandler() = default;
 
                 int m_numOfMembers;
                 int m_responseMembers;
                 int m_errorCode;
-                std::weak_ptr<SceneCollectionResource> m_Owner;
-                SceneExecuteCallback m_Cb;
+                std::weak_ptr<SceneCollectionResource> m_owner;
+                SceneExecuteCallback m_cb;
 
                 static SceneExecuteResponseHandler::Ptr createExecuteHandler(
                         const SceneCollectionResource::Ptr, SceneExecuteCallback);
@@ -91,11 +94,11 @@ namespace OIC
                 SceneCollectionRequestHandler() = default;
                 ~SceneCollectionRequestHandler() = default;
 
-                std::weak_ptr<SceneCollectionResource> m_Owner;
+                std::weak_ptr<SceneCollectionResource> m_owner;
 
                 RCSSetResponse onSetRequest(
                         const RCSRequest &, RCSResourceAttributes &);
-                void onExecute(int, /*const RCSRequest &,*/ RCSResourceAttributes &);
+                void onExecute(int, const RCSRequest &, RCSResourceAttributes &);
 
             private:
                 RCSSetResponse addSceneRequest(
@@ -104,18 +107,24 @@ namespace OIC
                         const RCSRequest &, RCSResourceAttributes &);
                 RCSSetResponse createSceneMemberRequest(
                         const RCSRequest &, RCSResourceAttributes &);
+                RCSSetResponse setSceneCollectionName(
+                        const RCSRequest &, RCSResourceAttributes &);
+
+                SceneMemberResource::Ptr createSceneMemberFromRemote(RCSResourceAttributes &);
+                void addMemberInfoFromRemote(SceneMemberResource::Ptr,
+                        std::vector<RCSResourceAttributes>);
             };
 
-            std::string m_Uri;
-            std::string m_Address;
+            std::string m_uri;
+            std::string m_address;
 
-            RCSResourceObject::Ptr m_SceneCollectionResourceObj;
-            std::mutex m_SceneMemberLock;
-            std::vector<SceneMemberResource::Ptr> m_SceneMembers;
+            RCSResourceObject::Ptr m_sceneCollectionResourceObj;
+            std::mutex m_sceneMemberLock;
+            std::vector<SceneMemberResource::Ptr> m_sceneMembers;
 
-            SceneCollectionRequestHandler m_RequestHandler;
-            std::mutex m_ExecuteHandlerLock;
-            std::list<SceneExecuteResponseHandler::Ptr> m_ExecuteHandlers;
+            SceneCollectionRequestHandler m_requestHandler;
+            std::mutex m_executeHandlerLock;
+            std::list<SceneExecuteResponseHandler::Ptr> m_executeHandlers;
 
             SceneCollectionResource() = default;
 
@@ -124,9 +133,13 @@ namespace OIC
                     const SceneCollectionResource &) = delete;
 
             SceneCollectionResource(SceneCollectionResource &&) = delete;
-            SceneCollectionResource && operator = (
+            SceneCollectionResource & operator = (
                     SceneCollectionResource &&) = delete;
 
+            void createResourceObject();
+            void setDefaultAttributes();
+            void initSetRequestHandler();
+
             void onExecute(int, SceneExecuteCallback, SceneExecuteResponseHandler::Ptr);
         };
     }
@@ -134,3 +147,4 @@ namespace OIC
 
 
 #endif // SCENE_COLLECTION_RESOURCE_OBJECT_H
+
index d2ee298..677e99b 100644 (file)
@@ -50,6 +50,9 @@ namespace OIC
         const std::string SCENE_KEY_MEMBERVALUE = "memberValue";
         const std::string SCENE_KEY_CREATEDLINK = "createdlink";
 
+        const std::string SCENE_KEY_URI = "uri";
+        const std::string SCENE_KEY_CHILD = "child";
+
         const std::string SCENE_LIST_RT = "oic.wk.scenelist";
         const std::string SCENE_MEMBER_RT = "oic.r.scenemember";
         const std::string SCENE_COLLECTION_RT = "oic.wk.scenecollection";
index 5eb20fb..2c56d1f 100644 (file)
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
+#include "SceneListResource.h"
+
 #include "RCSRequest.h"
 #include "OCApi.h"
-#include "SceneListResource.h"
 
 namespace OIC
 {
     namespace Service
     {
         SceneListResource::SceneListResource()
-        : m_SceneListName(), m_SceneListObj(), m_RequestHandler()
+        : m_sceneListName(), m_sceneListObj()
         {
-            m_SceneListObj = RCSResourceObject::Builder(
+            m_sceneListObj = RCSResourceObject::Builder(
                     SCENE_LIST_URI, SCENE_LIST_RT, OC_RSRVD_INTERFACE_DEFAULT).
                             addInterface(OC::BATCH_INTERFACE).
                             setDiscoverable(true).setObservable(false).build();
 
-            {
-                RCSResourceObject::LockGuard guard(m_SceneListObj);
-                m_SceneListObj->setAttribute(SCENE_KEY_NAME, SCENE_LIST_DEFAULT_NAME);
-                m_SceneListObj->setAttribute(SCENE_KEY_RTS, SCENE_LIST_RT);
-            }
+            m_sceneListObj->setAttribute(SCENE_KEY_NAME, SCENE_LIST_DEFAULT_NAME);
+            m_sceneListObj->setAttribute(SCENE_KEY_RTS, SCENE_LIST_RT);
 
-            m_SceneListObj->setSetRequestHandler(&SceneListRequestHandler::onSetRequest);
+            m_sceneListObj->setSetRequestHandler(&SceneListRequestHandler::onSetRequest);
+            m_sceneListObj->setGetRequestHandler(&SceneListRequestHandler::onGetRequest);
         }
 
         SceneListResource * SceneListResource::getInstance()
@@ -52,22 +51,22 @@ namespace OIC
         void SceneListResource::addSceneCollectionResource(
                 SceneCollectionResource::Ptr newObject)
         {
-            std::unique_lock<std::mutex> collectionlock(m_SceneCollectionLock);
-            m_SceneCollections.push_back(newObject);
-            m_SceneListObj->bindResource(newObject->getRCSResourceObject());
+            std::lock_guard<std::mutex> collectionlock(m_sceneCollectionLock);
+            m_sceneCollections.push_back(newObject);
+            m_sceneListObj->bindResource(newObject->getRCSResourceObject());
         }
 
         std::string SceneListResource::getName() const
         {
-            return m_SceneListName;
+            return m_sceneListName;
         }
 
         void SceneListResource::setName(std::string && newName)
         {
-            m_SceneListName = newName;
+            m_sceneListName = std::move(newName);
 
-            RCSResourceObject::LockGuard guard(m_SceneListObj);
-            m_SceneListObj->setAttribute(SCENE_KEY_NAME, m_SceneListName);
+            RCSResourceObject::LockGuard guard(m_sceneListObj);
+            m_sceneListObj->setAttribute(SCENE_KEY_NAME, m_sceneListName);
         }
 
         void SceneListResource::setName(const std::string & newName)
@@ -75,44 +74,102 @@ namespace OIC
             setName(std::string(newName));
         }
 
-        const std::vector<SceneCollectionResource::Ptr>
-        SceneListResource::getSceneCollections()
+        std::vector<SceneCollectionResource::Ptr> SceneListResource::getSceneCollections() const
         {
-            std::unique_lock<std::mutex> collectionlock(m_SceneCollectionLock);
-            std::vector<SceneCollectionResource::Ptr> retCollections(m_SceneCollections);
-            return retCollections;
+            return m_sceneCollections;
         }
 
-        RCSSetResponse
-        SceneListResource::SceneListRequestHandler::onSetRequest(
+        std::vector<RCSResourceAttributes> SceneListResource::getChildrenAttributes() const
+        {
+            std::vector<RCSResourceAttributes> childrenAttrs;
+
+            auto sceneCollections = getSceneCollections();
+
+            std::for_each(sceneCollections.begin(), sceneCollections.end(),
+                    [& childrenAttrs](const SceneCollectionResource::Ptr & pCollection)
+                    {
+                        RCSResourceAttributes collectionAttr;
+                        {
+                            RCSResourceObject::LockGuard guard(
+                                    pCollection->getRCSResourceObject());
+                            collectionAttr = pCollection->getRCSResourceObject()->getAttributes();
+                        }
+
+                        auto sceneMembers = pCollection->getSceneMembers();
+                        std::vector<RCSResourceAttributes> membersAttrs;
+
+                        std::for_each(sceneMembers.begin(), sceneMembers.end(),
+                                [& membersAttrs](const SceneMemberResource::Ptr & pMember)
+                                {
+                                    RCSResourceObject::LockGuard guard(pMember->getRCSResourceObject());
+                                    membersAttrs.push_back(pMember->getRCSResourceObject()->getAttributes());
+                                });
+
+                        collectionAttr[SCENE_KEY_CHILD] = membersAttrs;
+
+                        childrenAttrs.push_back(collectionAttr);
+                    });
+
+            return childrenAttrs;
+        }
+
+        RCSSetResponse SceneListResource::SceneListRequestHandler::onSetRequest(
                 const RCSRequest & request, RCSResourceAttributes & attributes)
         {
-            if (request.getInterface() != OC::BATCH_INTERFACE)
+            if(request.getInterface() == OC::BATCH_INTERFACE)
             {
-                return RCSSetResponse::create(attributes, SCENE_CLIENT_BADREQUEST).
+                auto newObject
+                    = SceneCollectionResource::createSceneCollectionObject();
+
+                if (attributes.contains(SCENE_KEY_NAME))
+                {
+                    newObject->setName(attributes.at(SCENE_KEY_NAME).get<std::string>());
+                }
+
+                SceneListResource::getInstance()->addSceneCollectionResource(newObject);
+
+                auto responseAtt = attributes;
+                responseAtt[SCENE_KEY_NAME] = RCSResourceAttributes::Value(newObject->getName());
+                responseAtt[SCENE_KEY_ID] = RCSResourceAttributes::Value(newObject->getId());
+
+                auto uri = COAP_TAG + newObject->getAddress() + newObject->getUri();
+                responseAtt[SCENE_KEY_PAYLOAD_LINK]
+                            = RCSResourceAttributes::Value(uri);
+
+                return RCSSetResponse::create(responseAtt, SCENE_RESPONSE_SUCCESS).
                         setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
             }
 
-            auto newObject
-                = SceneCollectionResource::createSceneCollectionObject();
-
             if (attributes.contains(SCENE_KEY_NAME))
             {
-                newObject->setName(attributes.at(SCENE_KEY_NAME).get<std::string>());
+                SceneListResource::getInstance()->setName(
+                        attributes.at(SCENE_KEY_NAME).get<std::string>());
+                return RCSSetResponse::create(attributes, SCENE_RESPONSE_SUCCESS).
+                        setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
             }
 
-            SceneListResource::getInstance()->addSceneCollectionResource(newObject);
+            return RCSSetResponse::create(attributes, SCENE_CLIENT_BADREQUEST).
+                    setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
+        }
+
+        RCSGetResponse SceneListResource::SceneListRequestHandler::onGetRequest(
+                const RCSRequest & request, RCSResourceAttributes & attributes)
+        {
+
+            if(request.getInterface() != OC::DEFAULT_INTERFACE)
+            {
+                return RCSGetResponse::defaultAction();
+            }
 
-            auto responseAtt = attributes;
-            responseAtt[SCENE_KEY_NAME] = RCSResourceAttributes::Value(newObject->getName());
-            responseAtt[SCENE_KEY_ID] = RCSResourceAttributes::Value(newObject->getId());
+            auto childrenAttrs = SceneListResource::getInstance()->getChildrenAttributes();
 
-            auto uri = COAP_TAG + newObject->getAddress() + newObject->getUri();
-            responseAtt[SCENE_KEY_PAYLOAD_LINK]
-                        = RCSResourceAttributes::Value(uri);
+            RCSResourceAttributes retAttr =  attributes;
+            if (childrenAttrs.size())
+            {
+                retAttr[SCENE_KEY_CHILD] = childrenAttrs;
+            }
 
-            return RCSSetResponse::create(responseAtt, SCENE_RESPONSE_SUCCESS).
-                    setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
+            return RCSGetResponse::create(retAttr);
         }
     }
 }
index b425c20..f54dfb4 100644 (file)
@@ -72,7 +72,9 @@ namespace OIC
             /**
              * Returns all of Scene Collection Resource object.
              */
-            const std::vector<SceneCollectionResource::Ptr> getSceneCollections();
+            std::vector<SceneCollectionResource::Ptr> getSceneCollections() const;
+
+            std::vector<RCSResourceAttributes> getChildrenAttributes() const;
 
         private:
             class SceneListRequestHandler
@@ -82,13 +84,13 @@ namespace OIC
                 ~SceneListRequestHandler() = default;
 
                 static RCSSetResponse onSetRequest(const RCSRequest &, RCSResourceAttributes &);
+                static RCSGetResponse onGetRequest(const RCSRequest &, RCSResourceAttributes &);
             };
 
-            std::string m_SceneListName;
-            RCSResourceObject::Ptr m_SceneListObj;
-            SceneListRequestHandler m_RequestHandler;
-            std::mutex m_SceneCollectionLock;
-            std::vector<SceneCollectionResource::Ptr> m_SceneCollections;
+            std::string m_sceneListName;
+            RCSResourceObject::Ptr m_sceneListObj;
+            std::mutex m_sceneCollectionLock;
+            std::vector<SceneCollectionResource::Ptr> m_sceneCollections;
 
             SceneListResource();
             ~SceneListResource() = default;
@@ -97,10 +99,9 @@ namespace OIC
             SceneListResource & operator = (const SceneListResource &) = delete;
 
             SceneListResource(SceneListResource &&) = delete;
-            SceneListResource && operator = (SceneListResource &&) = delete;
+            SceneListResource & operator = (SceneListResource &&) = delete;
         };
     }
 }
 
-
 #endif // SCENE_LIST_RESOURCE_OBJECT_H
index 7d82f0c..d99691d 100644 (file)
@@ -36,43 +36,16 @@ namespace OIC
         SceneMemberResource::createSceneMemberResource(
                 RCSRemoteResourceObject::Ptr remoteObject)
         {
-            auto instance = new SceneMemberResource();
-            SceneMemberResource::Ptr newSceneMemberObject;
-            newSceneMemberObject.reset(instance);
+            SceneMemberResource::Ptr newSceneMemberObject(new SceneMemberResource());
 
-            newSceneMemberObject->m_Uri = PREFIX_SCENE_MEMBER_URI + "/" +
+            newSceneMemberObject->m_uri = PREFIX_SCENE_MEMBER_URI + "/" +
                 std::to_string(numOfSceneMember++);
-            newSceneMemberObject->m_SceneMemberResourceObj
-                = RCSResourceObject::Builder(
-                        newSceneMemberObject->m_Uri,
-                        SCENE_MEMBER_RT, OC_RSRVD_INTERFACE_DEFAULT).
-                        setDiscoverable(true).setObservable(false).build();
-            newSceneMemberObject->m_RequestHandler.m_Owner
-                = std::weak_ptr<SceneMemberResource>(newSceneMemberObject);
-
-            newSceneMemberObject->m_RemoteMemberObj = remoteObject;
-
-            auto resourceObj = newSceneMemberObject->m_SceneMemberResourceObj;
-
-            RCSResourceObject::LockGuard guard(resourceObj);
-            resourceObj->setAttribute(SCENE_KEY_ID, SceneUtils::OICGenerateUUIDStr());
-            resourceObj->setAttribute(SCENE_KEY_NAME, std::string());
-
-            RCSResourceAttributes subAtt;
-            subAtt[SCENE_KEY_HREF]
-                    = RCSResourceAttributes::Value(
-                            remoteObject->getAddress() + remoteObject->getUri());
-            subAtt[SCENE_KEY_IF] = RCSResourceAttributes::Value(remoteObject->getInterfaces());
-            subAtt[SCENE_KEY_RT] = RCSResourceAttributes::Value(remoteObject->getTypes());
-            resourceObj->setAttribute(SCENE_KEY_PAYLOAD_LINK, subAtt);
 
-            resourceObj->setAttribute(
-                    SCENE_KEY_SCENEMAPPINGS, std::vector<RCSResourceAttributes>());
+            newSceneMemberObject->m_remoteMemberObj = remoteObject;
 
-            resourceObj->setSetRequestHandler(std::bind(
-                    &SceneMemberResource::SceneMemberRequestHandler::onSetRequest,
-                    newSceneMemberObject->m_RequestHandler,
-                    std::placeholders::_1, std::placeholders::_2));
+            newSceneMemberObject->createResourceObject();
+            newSceneMemberObject->initSetRequestHandler();
+            newSceneMemberObject->setDefaultAttributes();
 
             return newSceneMemberObject;
         }
@@ -102,32 +75,59 @@ namespace OIC
             return createSceneMemberResource(RCSRemoteResourceObject::fromOCResource(ocResourcePtr));
         }
 
+        void SceneMemberResource::createResourceObject()
+        {
+            m_sceneMemberResourceObj
+                = RCSResourceObject::Builder(
+                        m_uri, SCENE_MEMBER_RT, OC_RSRVD_INTERFACE_DEFAULT).
+                        setDiscoverable(true).setObservable(false).build();
+        }
+
+        void SceneMemberResource::setDefaultAttributes()
+        {
+            m_sceneMemberResourceObj->setAttribute(SCENE_KEY_ID, SceneUtils::OICGenerateUUIDStr());
+            m_sceneMemberResourceObj->setAttribute(SCENE_KEY_NAME, std::string());
+
+            RCSResourceAttributes subAtt;
+            subAtt[SCENE_KEY_HREF]
+                    = RCSResourceAttributes::Value(
+                            m_remoteMemberObj->getAddress() + m_remoteMemberObj->getUri());
+            subAtt[SCENE_KEY_IF] = RCSResourceAttributes::Value(m_remoteMemberObj->getInterfaces());
+            subAtt[SCENE_KEY_RT] = RCSResourceAttributes::Value(m_remoteMemberObj->getTypes());
+            m_sceneMemberResourceObj->setAttribute(SCENE_KEY_PAYLOAD_LINK, subAtt);
+
+            m_sceneMemberResourceObj->setAttribute(
+                    SCENE_KEY_SCENEMAPPINGS, std::vector<RCSResourceAttributes>());
+            m_sceneMemberResourceObj->setAttribute(SCENE_KEY_URI, m_uri);
+        }
+
+        void SceneMemberResource::initSetRequestHandler()
+        {
+            m_requestHandler.m_owner = std::weak_ptr<SceneMemberResource>(shared_from_this());
+            m_sceneMemberResourceObj->setSetRequestHandler(std::bind(
+                    &SceneMemberResource::SceneMemberRequestHandler::onSetRequest,
+                    m_requestHandler, std::placeholders::_1, std::placeholders::_2));
+        }
+
         void SceneMemberResource::addMappingInfo(MappingInfo && mInfo)
         {
             RCSResourceAttributes newAtt;
             {
-                RCSResourceObject::LockGuard guard(m_SceneMemberResourceObj);
-                newAtt = m_SceneMemberResourceObj->getAttributes();
+                RCSResourceObject::LockGuard guard(m_sceneMemberResourceObj);
+                newAtt = m_sceneMemberResourceObj->getAttributes();
             }
 
             auto mappingInfo = newAtt.at(SCENE_KEY_SCENEMAPPINGS).
                     get<std::vector<RCSResourceAttributes>>();
 
-            struct FindSceneName
-            {
-                bool operator()(RCSResourceAttributes att) const
-                {
-                    return att.at(SCENE_KEY_SCENE).get<std::string>() == name;
-                }
-                std::string name;
-            };
-
-            FindSceneName fScene;
-            fScene.name = mInfo.sceneName;
-            auto foundMInfo = std::find_if(mappingInfo.begin(), mappingInfo.end(), fScene);
-
-            if (foundMInfo != mappingInfo.end() &&
-                    (* foundMInfo).at(SCENE_KEY_MEMBERPROPERTY).get<std::string>() == mInfo.key)
+            auto foundMInfo = std::find_if(mappingInfo.begin(), mappingInfo.end(),
+                    [& mInfo](const RCSResourceAttributes & att) -> bool
+                    {
+                        return (att.at(SCENE_KEY_SCENE).get<std::string>() == mInfo.sceneName) &&
+                                (att.at(SCENE_KEY_MEMBERPROPERTY).get<std::string>() == mInfo.key);
+                    });
+
+            if (foundMInfo != mappingInfo.end())
             {
                 mappingInfo.erase(foundMInfo);
             }
@@ -137,8 +137,7 @@ namespace OIC
             newMapInfo[SCENE_KEY_MEMBERVALUE] = mInfo.value;
             mappingInfo.push_back(newMapInfo);
 
-            RCSResourceObject::LockGuard guard(m_SceneMemberResourceObj);
-            m_SceneMemberResourceObj->setAttribute(SCENE_KEY_SCENEMAPPINGS, mappingInfo);
+            m_sceneMemberResourceObj->setAttribute(SCENE_KEY_SCENEMAPPINGS, mappingInfo);
         }
 
         void SceneMemberResource::addMappingInfo(const MappingInfo & mInfo)
@@ -146,46 +145,42 @@ namespace OIC
             addMappingInfo(MappingInfo(mInfo));
         }
 
-        std::vector<SceneMemberResource::MappingInfo>
-        SceneMemberResource::getMappingInfo()
+        std::vector<SceneMemberResource::MappingInfo> SceneMemberResource::getMappingInfo()
         {
-            auto mappingInfo
-                = m_SceneMemberResourceObj->getAttributeValue(SCENE_KEY_SCENEMAPPINGS).
-                  get<std::vector<RCSResourceAttributes>>();
-
             std::vector<MappingInfo> retMInfo;
-            for(unsigned int it = 0; it < mappingInfo.size(); ++it)
-            {
-                MappingInfo info(mappingInfo[it].at(
-                                         SCENE_KEY_SCENE).get<std::string>(),
-                                 mappingInfo[it].at(
-                                         SCENE_KEY_MEMBERPROPERTY).get<std::string>(),
-                                 mappingInfo[it].at(
-                                         SCENE_KEY_MEMBERVALUE));
-                retMInfo.push_back(info);
-            }
+
+            auto mInfo = m_sceneMemberResourceObj->getAttributeValue(SCENE_KEY_SCENEMAPPINGS).
+                    get<std::vector<RCSResourceAttributes>>();
+            std::for_each(mInfo.begin(), mInfo.end(),
+                    [& retMInfo](const RCSResourceAttributes & att)
+                    {
+                        MappingInfo info(att.at(SCENE_KEY_SCENE).get<std::string>(),
+                                att.at(SCENE_KEY_MEMBERPROPERTY).get<std::string>(),
+                                att.at(SCENE_KEY_MEMBERVALUE));
+                        retMInfo.push_back(info);
+                    });
 
             return retMInfo;
         }
 
         std::string SceneMemberResource::getId() const
         {
-            return m_SceneMemberResourceObj->getAttributeValue(SCENE_KEY_ID).get<std::string>();
+            return m_sceneMemberResourceObj->getAttributeValue(SCENE_KEY_ID).get<std::string>();
         }
 
         std::string SceneMemberResource::getFullUri() const
         {
-            return std::string(COAP_TAG + SceneUtils::getNetAddress() + m_Uri);
+            return std::string(COAP_TAG + SceneUtils::getNetAddress() + m_uri);
         }
 
         RCSRemoteResourceObject::Ptr SceneMemberResource::getRemoteResourceObject() const
         {
-            return m_RemoteMemberObj;
+            return m_remoteMemberObj;
         }
 
         RCSResourceObject::Ptr SceneMemberResource::getRCSResourceObject() const
         {
-            return m_SceneMemberResourceObj;
+            return m_sceneMemberResourceObj;
         }
 
         void SceneMemberResource::execute(std::string && sceneName)
@@ -198,60 +193,106 @@ namespace OIC
             execute(std::string(sceneName));
         }
 
-        void SceneMemberResource::execute(
-                std::string && sceneName, executeCallback executeCB)
+        void SceneMemberResource::execute(std::string && sceneName, MemberexecuteCallback executeCB)
         {
-            bool hasScene = false;
-            auto mInfo = getMappingInfo();
+            RCSResourceAttributes setAtt;
 
-            for (unsigned int it = 0; it < mInfo.size(); ++it)
-            {
-                if (mInfo[it].sceneName == sceneName)
-                {
-                    hasScene = true;
-
-                    RCSResourceAttributes setAtt;
-                    setAtt[mInfo[it].key] = mInfo[it].value;
-                    m_RemoteMemberObj->setRemoteAttributes(setAtt, executeCB);
-                }
-            }
-            if (!hasScene && executeCB != nullptr)
+            auto mInfo = getMappingInfo();
+            std::for_each (mInfo.begin(), mInfo.end(),
+                    [& setAtt, & sceneName](const MappingInfo & info)
+                    {
+                        if(info.sceneName == sceneName)
+                        {
+                            setAtt[info.key] = info.value;
+                        }
+                    });
+
+            if (setAtt.empty() && executeCB != nullptr)
             {
                 executeCB(RCSResourceAttributes(), SCENE_RESPONSE_SUCCESS);
             }
+
+            m_remoteMemberObj->setRemoteAttributes(setAtt, executeCB);
         }
 
         void SceneMemberResource::execute(
-                const std::string & sceneName, executeCallback executeCB)
+                const std::string & sceneName, MemberexecuteCallback executeCB)
         {
             execute(std::string(sceneName), std::move(executeCB));
         }
 
+        void SceneMemberResource::setName(const std::string & name)
+        {
+            setName(std::string(name));
+        }
+
+        void SceneMemberResource::setName(std::string && name)
+        {
+            m_sceneMemberResourceObj->setAttribute(SCENE_KEY_NAME, std::move(name));
+        }
+
+        std::string SceneMemberResource::getName() const
+        {
+            return m_sceneMemberResourceObj->getAttributeValue(SCENE_KEY_NAME).toString();
+        }
+
         RCSSetResponse SceneMemberResource::SceneMemberRequestHandler::
-        onSetRequest(const RCSRequest & /*request*/, RCSResourceAttributes & attributes)
+        onSetRequest(const RCSRequest & request, RCSResourceAttributes & attributes)
         {
-            auto ptr = m_Owner.lock();
+            if (attributes.contains(SCENE_KEY_SCENEMAPPINGS))
+            {
+                addMappingInfos(request, attributes);
+            }
+
+            if (attributes.contains(SCENE_KEY_NAME))
+            {
+                setSceneMemberName(request, attributes);
+            }
+
+            return RCSSetResponse::create(attributes, SCENE_CLIENT_BADREQUEST).
+                    setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
+        }
+
+        RCSSetResponse
+        SceneMemberResource::SceneMemberRequestHandler::addMappingInfos(
+                const RCSRequest & /*request*/, RCSResourceAttributes & attributes)
+        {
+            auto ptr = m_owner.lock();
             if (!ptr)
             {
-                return RCSSetResponse::create(
-                        RCSResourceAttributes(attributes), SCENE_CLIENT_BADREQUEST).
+                return RCSSetResponse::create(attributes, SCENE_CLIENT_BADREQUEST).
                         setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
             }
 
-            if (attributes.contains(SCENE_KEY_SCENEMAPPINGS))
+            auto mInfo = attributes.at(SCENE_KEY_SCENEMAPPINGS).
+                    get<std::vector<RCSResourceAttributes>>();
+            std::for_each (mInfo.begin(), mInfo.end(),
+                    [& ptr](const RCSResourceAttributes & att)
+                    {
+                        ptr->addMappingInfo(SceneMemberResource::MappingInfo(
+                                att.at(SCENE_KEY_SCENE).get<std::string>(),
+                                att.at(SCENE_KEY_MEMBERPROPERTY).get<std::string>(),
+                                att.at(SCENE_KEY_MEMBERVALUE)));
+                    });
+
+            return RCSSetResponse::create(attributes).
+                    setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
+        }
+
+        RCSSetResponse
+        SceneMemberResource::SceneMemberRequestHandler::setSceneMemberName(
+                const RCSRequest & /*request*/, RCSResourceAttributes & attributes)
+        {
+            auto ptr = m_owner.lock();
+            if (!ptr)
             {
-                auto sceneMappings
-                    = attributes.at(SCENE_KEY_SCENEMAPPINGS).get<std::vector<RCSResourceAttributes>>();
-                for (unsigned int it = 0; it < sceneMappings.size(); ++it)
-                {
-                    ptr->addMappingInfo(SceneMemberResource::MappingInfo(
-                            sceneMappings[it].at(SCENE_KEY_SCENE).get<std::string>(),
-                            sceneMappings[it].at(SCENE_KEY_MEMBERPROPERTY).get<std::string>(),
-                            sceneMappings[it].at(SCENE_KEY_MEMBERVALUE)));
-                }
+                return RCSSetResponse::create(attributes, SCENE_CLIENT_BADREQUEST).
+                        setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
             }
 
-            return RCSSetResponse::create(RCSResourceAttributes(attributes)).
+            ptr->setName(attributes.at(SCENE_KEY_NAME).get<std::string>());
+
+            return RCSSetResponse::create(attributes).
                     setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
         }
     }
index aae3963..524920a 100644 (file)
@@ -50,7 +50,7 @@ namespace OIC
              * @see RCSRemoteResourceObject::setRemoteAttributes
              */
             typedef std::function< void(const RCSResourceAttributes & attrs, int eCode) >
-                executeCallback;
+                MemberexecuteCallback;
 
             /**
              * A Mapping information about each scene values.
@@ -58,12 +58,14 @@ namespace OIC
             struct MappingInfo
             {
                 MappingInfo(
-                        std::string scene,
-                        std::string keyName,
-                        RCSResourceAttributes::Value val)
+                        const std::string & scene,
+                        const std::string & keyName,
+                        const RCSResourceAttributes::Value & val)
                 :sceneName(scene), key(keyName), value(val) { }
+
                 MappingInfo(MappingInfo &&) = default;
                 MappingInfo(const MappingInfo &) = default;
+
                 std::string sceneName;              ///< name of scene value
                 std::string key;                    ///< key to set at attributes of remote resource
                 RCSResourceAttributes::Value value; ///< val to set at attributes of remote resource
@@ -138,12 +140,12 @@ namespace OIC
              * @param sceneValue scene value to execute
              * @param cb callback to response
              */
-            void execute(std::string && sceneValue, executeCallback cb);
+            void execute(std::string && sceneValue, MemberexecuteCallback cb);
 
             /**
              * @overload
              */
-            void execute(const std::string &, executeCallback);
+            void execute(const std::string &, MemberexecuteCallback);
 
             /**
              * Execute of Scene Action (without callback for response).
@@ -157,6 +159,11 @@ namespace OIC
              */
             void execute(const std::string &);
 
+            void setName(const std::string &);
+            void setName(std::string &&);
+
+            std::string getName() const;
+
         private:
             class SceneMemberRequestHandler
             {
@@ -164,15 +171,18 @@ namespace OIC
                 SceneMemberRequestHandler() = default;
                 ~SceneMemberRequestHandler() = default;
 
-                std::weak_ptr<SceneMemberResource> m_Owner;
+                std::weak_ptr<SceneMemberResource> m_owner;
 
                 RCSSetResponse onSetRequest(const RCSRequest & , RCSResourceAttributes &);
+
+                RCSSetResponse addMappingInfos(const RCSRequest & , RCSResourceAttributes &);
+                RCSSetResponse setSceneMemberName(const RCSRequest & , RCSResourceAttributes &);
             };
 
-            std::string m_Uri;
-            RCSResourceObject::Ptr m_SceneMemberResourceObj;
-            RCSRemoteResourceObject::Ptr m_RemoteMemberObj;
-            SceneMemberRequestHandler m_RequestHandler;
+            std::string m_uri;
+            RCSResourceObject::Ptr m_sceneMemberResourceObj;
+            RCSRemoteResourceObject::Ptr m_remoteMemberObj;
+            SceneMemberRequestHandler m_requestHandler;
 
             SceneMemberResource() = default;
 
@@ -180,7 +190,11 @@ namespace OIC
             SceneMemberResource & operator = (const SceneMemberResource &) = delete;
 
             SceneMemberResource(SceneMemberResource &&) = delete;
-            SceneMemberResource && operator = (SceneMemberResource &&) = delete;
+            SceneMemberResource & operator = (SceneMemberResource &&) = delete;
+
+            void createResourceObject();
+            void setDefaultAttributes();
+            void initSetRequestHandler();
         };
     }
 }