# Source files and Targets
######################################################################
SCENE_SRC_DIR = './src/'
-scenemanager_src = [
- SCENE_SRC_DIR + 'SceneCollection.cpp',
- SCENE_SRC_DIR + 'SceneAction.cpp',
- SCENE_SRC_DIR + 'Scene.cpp',
- SCENE_SRC_DIR + 'SceneList.cpp',
- SCENE_SRC_DIR + 'SceneListResourceObject.cpp',
- SCENE_SRC_DIR + 'SceneCollectionResourceObject.cpp',
- SCENE_SRC_DIR + 'SceneMemberResourceObject.cpp',
- SCENE_SRC_DIR + 'SceneUtils.cpp',
- SCENE_SRC_DIR + 'SceneListResourceRequestor.cpp',
- SCENE_SRC_DIR + 'SceneCollectionResourceRequestor.cpp',
- SCENE_SRC_DIR + 'SceneMemberResourceRequestor.cpp'
- ]
+scenemanager_src = Glob(SCENE_SRC_DIR + '*.cpp')
if target_os in ['tizen','android'] :
scenemanagersdk = scenemanager_env.SharedLibrary('scene_manager', scenemanager_src)
scenemanager_env.InstallTarget(scenemanagersdk, 'libscene_manager')
scenemanager_env.UserInstallTargetLib(scenemanagersdk, 'libscene_manager')
-scenemanager_env.UserInstallTargetHeader('include/SceneList.h',\
- 'service/scene-manager', 'SceneList.h')
+scenemanager_env.UserInstallTargetHeader('include/SceneList.h', 'service/scene-manager', 'SceneList.h')
+scenemanager_env.UserInstallTargetHeader('include/SceneCollection.h', 'service/scene-manager', 'SceneCollection.h')
+scenemanager_env.UserInstallTargetHeader('include/Scene.h', 'service/scene-manager', 'Scene.h')
+scenemanager_env.UserInstallTargetHeader('include/SceneAction.h', 'service/scene-manager', 'SceneAction.h')
+scenemanager_env.UserInstallTargetHeader('include/RemoteSceneList.h', 'service/scene-manager', 'RemoteSceneList.h')
+scenemanager_env.UserInstallTargetHeader('include/RemoteSceneCollection.h', 'service/scene-manager', 'RemoteSceneCollection.h')
+scenemanager_env.UserInstallTargetHeader('include/RemoteScene.h', 'service/scene-manager', 'RemoteScene.h')
+scenemanager_env.UserInstallTargetHeader('include/RemoteSceneAction.h', 'service/scene-manager', 'RemoteSceneAction.h')
# Go to build Unit test
#if target_os == 'linux':
#include "RemoteSceneAction.h"
#include "RCSRemoteResourceObject.h"
-#include "RCSResourceAttributes.h"
namespace OIC
{
{
class SceneCollectionResourceRequestor;
class SceneMemberResourceRequestor;
+
class RemoteScene
{
public:
typedef std::shared_ptr< RemoteScene > Ptr;
- typedef std::function< void(const RemoteSceneAction::Ptr) >
+ typedef std::function< void(RemoteSceneAction::Ptr, int) >
AddNewSceneActionCallback;
- typedef std::function< void(const int eCode) > RemoveSceneActionCallback;
+ typedef std::function< void(const int eCode) >
+ RemoveSceneActionCallback;
+
+ typedef std::function< void(const std::string &sceneName, int eCode) >
+ RemoteSceneExecuteCallback;
- typedef std::function< void(const int eCode) > RemoteSceneExecuteCallback;
public:
- ~RemoteScene();
+ ~RemoteScene() = default;
void addNewSceneAction(RCSRemoteResourceObject::Ptr pTargetResource,
- const RCSResourceAttributes &attr,
+ const RCSResourceAttributes &attrs,
AddNewSceneActionCallback);
void addNewSceneAction(RCSRemoteResourceObject::Ptr pTargetResource,
const std::string &key,
std::vector< RemoteSceneAction::Ptr > getRemoteSceneActions() const;
std::vector< RemoteSceneAction::Ptr > getRemoteSceneAction
- (RCSRemoteResourceObject::Ptr pTargetResource) const;
+ (const RCSRemoteResourceObject::Ptr pTargetResource) const;
std::string getName() const;
void execute(RemoteSceneExecuteCallback);
+
private:
- RemoteScene(const std::string &name,
- std::shared_ptr< SceneCollectionResourceRequestor >);
+ RemoteScene
+ (const std::string &name, std::shared_ptr< SceneCollectionResourceRequestor >);
+
+ RemoteSceneAction::Ptr createRemoteSceneActionInstance
+ (const std::string &, const RCSResourceAttributes &);
+
+ void addExistingRemoteSceneAction(const std::string &, const std::string &,
+ const std::string &, const std::string &key,
+ const RCSResourceAttributes::Value &);
+
+ void onSceneActionAdded(
+ std::shared_ptr< SceneMemberResourceRequestor >,
+ int eCode, RCSRemoteResourceObject::Ptr,
+ const RCSResourceAttributes &, AddNewSceneActionCallback);
+
+ void onSceneExecuted(const int &reqType, const std::string &name,
+ int eCode, RemoteSceneExecuteCallback);
- void onSceneMemberAdded(const std::string &link, const std::string &id, int eCode);
private:
std::string m_name;
- std::map < std::string, std::vector< RemoteSceneAction::Ptr > >
- m_mapRemoteSceneActions;
+ std::map < const std::string, std::vector< RemoteSceneAction::Ptr > >
+ m_remoteSceneActions;
- std::shared_ptr< SceneCollectionResourceRequestor > m_pRequestor;
+ std::shared_ptr< SceneCollectionResourceRequestor > m_requestorPtr;
+
+ friend class RemoteSceneCollection;
};
+
}
}
#include <string>
#include "RCSRemoteResourceObject.h"
-#include "RCSResourceAttributes.h"
namespace OIC
{
namespace Service
{
+
+ class SceneMemberResourceRequestor;
+
class RemoteSceneAction
{
public:
typedef std::shared_ptr< RemoteSceneAction > Ptr;
- typedef std::function< void(int eCode) > UpdateActionCallback;
+ typedef std::function< void(int eCode) >
+ UpdateCallback;
public:
- ~RemoteSceneAction();
+ ~RemoteSceneAction() = default;
- void updateAction(const RCSResourceAttributes &attr, UpdateActionCallback);
- void updateAction(const std::string &key,
- const RCSResourceAttributes::Value &value,
- UpdateActionCallback);
+ void update(const RCSResourceAttributes &attr, UpdateCallback);
+ void update(const std::string &key,
+ const RCSResourceAttributes::Value &value,
+ UpdateCallback);
RCSResourceAttributes getAction() const;
RCSRemoteResourceObject::Ptr getRemoteResourceObject() const;
+
private:
- RemoteSceneAction(RCSRemoteResourceObject::Ptr pResource,
- const RCSResourceAttributes &attr);
- RemoteSceneAction(RCSRemoteResourceObject::Ptr pResource,
- const std::string &key,
- const RCSResourceAttributes::Value &value);
+ RemoteSceneAction(std::shared_ptr< SceneMemberResourceRequestor >,
+ const std::string &sceneName, const RCSResourceAttributes &);
+ RemoteSceneAction(std::shared_ptr< SceneMemberResourceRequestor >,
+ const std::string &sceneName,
+ const std::string &key, const RCSResourceAttributes::Value &);
+
+ void onUpdated(int, const RCSResourceAttributes &, const UpdateCallback &);
private:
+ std::string m_sceneName;
RCSResourceAttributes m_attributes;
- RCSRemoteResourceObject::Ptr m_pRemoteResourceObject;
+ std::shared_ptr< SceneMemberResourceRequestor > m_requestorPtr;
+
+ friend class RemoteScene;
};
+
}
}
-#endif /* SM_REMOTE_SCENEACTION_H_ */
+#endif /* SM_REMOTE_SCENEACTION_H_ */
\ No newline at end of file
{
namespace Service
{
+
class SceneCollectionResourceRequestor;
+
class RemoteSceneCollection
{
public:
typedef std::shared_ptr< RemoteSceneCollection > Ptr;
- typedef std::function< void(RemoteScene::Ptr, int) > AddNewSceneCallback;
+ typedef std::function< void(RemoteScene::Ptr, int) >
+ AddNewSceneCallback;
+
+ typedef std::function< void(int eCode) >
+ RemoveSceneCallback;
- typedef std::function< void(int eCode) > RemoveSceneCallback;
+ typedef std::function< void(int eCode) >
+ SetNameCallback;
- typedef std::function< void(int eCode) > SetNameCallback;
public:
- ~RemoteSceneCollection();
+ ~RemoteSceneCollection() = default;
void addNewScene(const std::string &name, AddNewSceneCallback);
void removeScene(const std::string &name, RemoveSceneCallback);
- std::map< std::string, RemoteScene::Ptr > getRemoteScenes() const;
+ std::map< const std::string, RemoteScene::Ptr > getRemoteScenes() const;
RemoteScene::Ptr getRemoteScene(const std::string &sceneName) const;
void setName(const std::string &name, SetNameCallback);
std::string getId() const;
+
private:
- RemoteSceneCollection(
- std::shared_ptr< SceneCollectionResourceRequestor > pRequestor,
- std::string id, std::string name);
+ RemoteSceneCollection
+ (std::shared_ptr< SceneCollectionResourceRequestor > pRequestor,
+ const std::string &id, const std::string &name);
+
+ void initializeRemoteSceneCollection(const std::vector< RCSRepresentation > &,
+ const std::string &);
+
+ RemoteScene::Ptr createRemoteSceneInstance(const std::string &);
void onSceneAddedRemoved(const int &reqType, const std::string &name, int eCode,
- AddNewSceneCallback);
+ const AddNewSceneCallback &, const RemoveSceneCallback &);
+
+ void onNameSet(int, const std::string &, const SetNameCallback &);
+
private:
std::string m_id;
std::string m_name;
- std::map< std::string, RemoteScene::Ptr > m_mapRemoteScenes;
+ std::map< const std::string, RemoteScene::Ptr > m_remoteScenes;
- std::shared_ptr< SceneCollectionResourceRequestor > m_pRequestor;
+ std::shared_ptr< SceneCollectionResourceRequestor > m_requestorPtr;
+
+ friend class RemoteSceneList;
};
+
}
}
#define SM_REMOTE_SCENELIST_H_
#include <memory>
+#include <vector>
#include <functional>
#include "RemoteSceneCollection.h"
{
namespace Service
{
+
class SceneListResourceRequestor;
+
class RemoteSceneList
+ : public std::enable_shared_from_this< RemoteSceneList >
{
public:
- typedef std::shared_ptr< RemoteSceneList > Ptr;
+ typedef std::unique_ptr< RemoteSceneList > Ptr;
- typedef std::function< void(RemoteSceneList::Ptr, int) > CreateInstanceCallback;
+ typedef std::function< void(RemoteSceneList::Ptr, int) >
+ CreateInstanceCallback;
typedef std::function< void(RemoteSceneCollection::Ptr, int) >
AddNewSceneCollectionCallback;
- typedef std::function< void(int eCode) > SetNameCallback;
+ typedef std::function< void(int eCode) >
+ SetNameCallback;
+
public:
- ~RemoteSceneList();
+ ~RemoteSceneList() = default;
static void createInstance
(RCSRemoteResourceObject::Ptr pSceneListResource, CreateInstanceCallback);
void setName(const std::string &name, SetNameCallback);
std::string getName() const;
+
+ private:
+ class GetResponseHandler
+ {
+ public:
+ typedef std::shared_ptr< GetResponseHandler > Ptr;
+
+ typedef std::function< void(int eCode) >
+ GetCallback;
+
+ GetResponseHandler(std::shared_ptr< RemoteSceneList > ptr);
+ ~GetResponseHandler() = default;
+
+ int m_numOfCollections;
+ int m_respondedCollections;
+ int m_errorCode;
+ std::weak_ptr< RemoteSceneList > m_owner;
+ GetCallback m_cb;
+
+ void startGetResponseHandler(const std::string &host, GetCallback cb);
+
+ void onGetCollectionAttrs(const HeaderOpts &, const RCSRepresentation &,
+ int eCode, RemoteSceneCollection::Ptr,
+ const std::string &);
+
+ void onGetListAttrs(const HeaderOpts &, const RCSRepresentation &, int,
+ const std::string &);
+ };
+
+
private:
- RemoteSceneList(std::shared_ptr< SceneListResourceRequestor > pRequestor,
- const std::string &name);
+ RemoteSceneList(std::shared_ptr< SceneListResourceRequestor > pRequestor);
+
+ static void onInstanceCreated(int, std::shared_ptr< RemoteSceneList >,
+ CreateInstanceCallback);
+
+ RemoteSceneCollection::Ptr createRemoteSceneCollectionInstance
+ (const std::string &link, const std::string &id, const std::string &name);
+
+ void setGetResponseHandler(const std::string &, GetResponseHandler::GetCallback);
void onSceneCollectionCreated
(const std::string &link, const std::string &id, const std::string &name,
- AddNewSceneCollectionCallback);
+ int eCode, AddNewSceneCollectionCallback);
+
+ void onNameSet(int, const std::string &, const SetNameCallback &);
+
private:
std::string m_name;
std::vector< RemoteSceneCollection::Ptr > m_remoteSceneCollections;
+ std::shared_ptr< SceneListResourceRequestor > m_requestorPtr;
- std::shared_ptr< SceneListResourceRequestor > m_pRequestor;
+ GetResponseHandler::Ptr m_getResponseHandler;
+
+ friend class GetResponseHandler;
};
+
}
}
--- /dev/null
+//******************************************************************
+//
+// 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 "RemoteScene.h"
+
+#include "SceneCommons.h"
+#include "RemoteSceneUtils.h"
+#include "SceneCollectionResourceRequestor.h"
+#include "SceneMemberResourceRequestor.h"
+#include "OCPlatform.h"
+
+namespace OIC
+{
+ namespace Service
+ {
+
+ RemoteScene::RemoteScene
+ (const std::string &name, std::shared_ptr< SceneCollectionResourceRequestor > pRequestor)
+ : m_name{ name }, m_requestorPtr{ pRequestor }
+ {
+ // TODO: check pRequestor not null
+ }
+
+ void RemoteScene::addNewSceneAction(
+ RCSRemoteResourceObject::Ptr, const RCSResourceAttributes &, AddNewSceneActionCallback)
+ {
+
+ }
+
+ void RemoteScene::addNewSceneAction
+ (RCSRemoteResourceObject::Ptr pTargetResource,
+ const std::string &key, const RCSResourceAttributes::Value &value,
+ AddNewSceneActionCallback clientCB)
+ {
+ // TODO: check pTargetResource not null
+ // TODO: check key not empty
+
+ RCSResourceAttributes attr;
+ attr[key] = RCSResourceAttributes::Value(value);
+
+ std::string targetLink = pTargetResource->getAddress() + pTargetResource->getUri();
+
+ auto sceneActions = m_remoteSceneActions.find(targetLink);
+
+ // if the target is not a scene member
+ if (sceneActions == m_remoteSceneActions.end())
+ {
+ SceneCollectionResourceRequestor::InternalAddMemberCallback internalCB
+ = std::bind(&RemoteScene::onSceneActionAdded, this,
+ std::placeholders::_1, std::placeholders::_2,
+ pTargetResource, attr, std::move(clientCB));
+
+ m_requestorPtr->requestAddSceneMember
+ (pTargetResource, m_name, attr, internalCB);
+ }
+ else
+ {
+ // check if sceneAction already exists
+ for (auto itr : sceneActions->second)
+ {
+ if (itr->getAction().contains(key))
+ {
+ // throw exception
+ break;
+ }
+ }
+
+ SceneMemberResourceRequestor::Ptr pMemberRequestor
+ = m_requestorPtr->getSceneMemberResourceRequestor(targetLink);
+
+ if (pMemberRequestor)
+ {
+ SceneMemberResourceRequestor::InternalAddSceneActionCallback internalCB
+ = std::bind(&RemoteScene::onSceneActionAdded, this,
+ nullptr,
+ std::placeholders::_1, pTargetResource,
+ attr, std::move(clientCB));
+
+ pMemberRequestor->
+ requestSceneActionCreation(m_name, attr, internalCB);
+ }
+ }
+ }
+
+ void RemoteScene::removeSceneAction(RemoteSceneAction::Ptr/* pRemoteSceneAction */,
+ RemoveSceneActionCallback /* clientCB */)
+ {
+
+ }
+
+ void RemoteScene::removeSceneAction(RCSRemoteResourceObject::Ptr/* pTargetResource*/,
+ RemoveSceneActionCallback /* clientCB */)
+ {
+
+ }
+
+ std::vector< RemoteSceneAction::Ptr > RemoteScene::getRemoteSceneActions() const
+ {
+ std::vector< RemoteSceneAction::Ptr > vecSceneActions;
+
+ for (auto itrMap : m_remoteSceneActions)
+ {
+ for (auto itrVec : itrMap.second)
+ {
+ vecSceneActions.push_back(itrVec);
+ }
+ }
+
+ return vecSceneActions;
+ }
+
+ std::vector< RemoteSceneAction::Ptr > RemoteScene::getRemoteSceneAction
+ (const RCSRemoteResourceObject::Ptr pTargetResource) const
+ {
+ auto itr = m_remoteSceneActions.find(
+ pTargetResource->getAddress() + pTargetResource->getUri());
+
+ if (itr == m_remoteSceneActions.end())
+ {
+ ;
+ // TODO: throw unadded scene action exception
+ }
+
+ return itr->second;
+ }
+
+ std::string RemoteScene::getName() const
+ {
+ return m_name;
+ }
+
+ void RemoteScene::execute(RemoteSceneExecuteCallback clientCB)
+ {
+ SceneCollectionResourceRequestor::InternalSceneRequestCallback internalCB
+ = std::bind(&RemoteScene::onSceneExecuted, this,
+ std::placeholders::_1, std::placeholders::_2,
+ std::placeholders::_3, std::move(clientCB));
+
+ m_requestorPtr->requestSceneExecution(m_name, internalCB);
+ }
+
+ RemoteSceneAction::Ptr RemoteScene::createRemoteSceneActionInstance
+ (const std::string &targetLink, const RCSResourceAttributes &attrs)
+ {
+ RemoteSceneAction::Ptr pNewSceneAction = nullptr;
+ SceneMemberResourceRequestor::Ptr pMemRequestor
+ = m_requestorPtr->getSceneMemberResourceRequestor(targetLink);
+ if (pMemRequestor)
+ {
+ pNewSceneAction.reset(new RemoteSceneAction(pMemRequestor, m_name, attrs));
+ m_remoteSceneActions[targetLink].push_back(pNewSceneAction);
+ }
+
+ return pNewSceneAction;
+ }
+
+ void RemoteScene::addExistingRemoteSceneAction
+ (const std::string &address, const std::string &targetLink,
+ const std::string &id, const std::string &key, const RCSResourceAttributes::Value &value)
+ {
+ SceneMemberResourceRequestor::Ptr pfoundMember
+ = m_requestorPtr->getSceneMemberResourceRequestor(targetLink);
+
+ if (pfoundMember == nullptr)
+ m_requestorPtr->createSceneMemberResourceRequestor(address, id, targetLink);
+
+ RCSResourceAttributes attrs;
+ attrs[key] = RCSResourceAttributes::Value(value);
+
+ createRemoteSceneActionInstance(targetLink, attrs);
+ }
+
+ void RemoteScene::onSceneActionAdded
+ (SceneMemberResourceRequestor::Ptr, int eCode, RCSRemoteResourceObject::Ptr target,
+ const RCSResourceAttributes &attrs,
+ AddNewSceneActionCallback clientCB)
+ {
+ int result = SCENE_CLIENT_BADREQUEST;
+ RemoteSceneAction::Ptr pNewRemoteSceneAction = nullptr;
+
+ if (eCode == SCENE_RESPONSE_SUCCESS)
+ {
+ std::string targetLink = target->getAddress() + target->getUri();
+
+ pNewRemoteSceneAction = createRemoteSceneActionInstance(targetLink, attrs);
+
+ if (pNewRemoteSceneAction)
+ result = SCENE_RESPONSE_SUCCESS;
+ }
+ else
+ {
+ // error
+ }
+
+ clientCB(pNewRemoteSceneAction, result);
+ }
+
+ void RemoteScene::onSceneExecuted(const int &, const std::string &sceneName,
+ const int eCode, RemoteSceneExecuteCallback clientCB)
+ {
+ clientCB(sceneName, eCode);
+ }
+
+ }
+}
\ No newline at end of file
--- /dev/null
+//******************************************************************
+//
+// 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 "RemoteSceneAction.h"
+
+#include "SceneCommons.h"
+#include "RemoteSceneUtils.h"
+#include "SceneMemberResourceRequestor.h"
+
+namespace OIC
+{
+ namespace Service
+ {
+
+ RemoteSceneAction::RemoteSceneAction
+ (std::shared_ptr< SceneMemberResourceRequestor > pRequestor,
+ const std::string &sceneName, const RCSResourceAttributes &attrs)
+ : m_sceneName{ sceneName }, m_attributes{ attrs }, m_requestorPtr{ pRequestor }
+ {
+ // TODO: check pRequestor not null
+ }
+
+ RemoteSceneAction::RemoteSceneAction
+ (std::shared_ptr< SceneMemberResourceRequestor > pRequestor,
+ const std::string &sceneName,
+ const std::string &key, const RCSResourceAttributes::Value &value)
+ : m_sceneName{ sceneName }, m_requestorPtr{ pRequestor }
+ {
+ // TODO: check pRequestor not null
+ m_attributes[key] = value;
+ }
+
+ void RemoteSceneAction::update(const RCSResourceAttributes &attr,
+ UpdateCallback clientCB)
+ {
+ SceneMemberResourceRequestor::InternalAddSceneActionCallback internalCB
+ = std::bind(&RemoteSceneAction::onUpdated, this,
+ std::placeholders::_1, attr, std::move(clientCB));
+
+ m_requestorPtr->requestSceneActionCreation(m_sceneName,
+ attr, internalCB);
+ }
+
+ void RemoteSceneAction::update(const std::string &key,
+ const RCSResourceAttributes::Value &value,
+ UpdateCallback clientCB)
+ {
+ RCSResourceAttributes attr;
+ attr[key] = RCSResourceAttributes::Value(value);
+
+ update(attr, std::move(clientCB));
+ }
+
+ RCSResourceAttributes RemoteSceneAction::getAction() const
+ {
+ return m_attributes;
+ }
+
+ RCSRemoteResourceObject::Ptr RemoteSceneAction::getRemoteResourceObject() const
+ {
+ return m_requestorPtr->getRemoteResourceObject();
+ }
+
+ void RemoteSceneAction::onUpdated(int eCode, const RCSResourceAttributes &attr,
+ const UpdateCallback &clientCB)
+ {
+ if (eCode == SCENE_RESPONSE_SUCCESS)
+ {
+ m_attributes = attr;
+ }
+
+ clientCB(eCode);
+ }
+
+ }
+}
\ No newline at end of file
--- /dev/null
+//******************************************************************
+//
+// 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 "RemoteSceneCollection.h"
+
+#include "SceneCommons.h"
+#include "RemoteSceneUtils.h"
+#include "SceneCollectionResourceRequestor.h"
+#include "OCPlatform.h"
+
+namespace OIC
+{
+ namespace Service
+ {
+
+ RemoteSceneCollection::RemoteSceneCollection
+ (std::shared_ptr< SceneCollectionResourceRequestor > pRequestor,
+ const std::string &id, const std::string &name)
+ : m_id{ id }, m_name{ name }, m_requestorPtr{ pRequestor }
+ {
+ // TODO: check pRequestor not null
+ }
+
+ void RemoteSceneCollection::addNewScene
+ (const std::string &name, AddNewSceneCallback clientCB)
+ {
+ if (m_remoteScenes.find(name) == m_remoteScenes.end())
+ {
+ SceneCollectionResourceRequestor::InternalSceneRequestCallback internalCB
+ = std::bind(&RemoteSceneCollection::onSceneAddedRemoved, this,
+ std::placeholders::_1, std::placeholders::_2,
+ std::placeholders::_3, std::move(clientCB), nullptr);
+
+ m_requestorPtr->requestSceneCreation(name, internalCB);
+ }
+ else
+ {
+ // TODO: throw duplication scene name exception
+ }
+ }
+
+ void RemoteSceneCollection::removeScene(const std::string &/* name */,
+ RemoveSceneCallback /* clientCB */)
+ {
+
+ }
+
+ std::map< const std::string, RemoteScene::Ptr >
+ RemoteSceneCollection::getRemoteScenes() const
+ {
+ return m_remoteScenes;
+ }
+
+ RemoteScene::Ptr RemoteSceneCollection::getRemoteScene(const std::string &sceneName) const
+ {
+ auto itr = m_remoteScenes.find(sceneName);
+
+ // TODO: throw unadded scene exception
+ return itr != m_remoteScenes.end() ? itr->second : nullptr;
+ }
+
+ void RemoteSceneCollection::setName(const std::string &name, SetNameCallback clientCB)
+ {
+ SceneCollectionResourceRequestor::InternalSetNameCallback internalCB
+ = std::bind(&RemoteSceneCollection::onNameSet, this,
+ std::placeholders::_1, name, std::move(clientCB));
+
+ m_requestorPtr->requestSetName(name, internalCB);
+ }
+
+ std::string RemoteSceneCollection::getName() const
+ {
+ return m_name;
+ }
+
+ std::string RemoteSceneCollection::getId() const
+ {
+ return m_id;
+ }
+
+ void RemoteSceneCollection::initializeRemoteSceneCollection(
+ const std::vector< RCSRepresentation > &MemberReps, const std::string &host)
+ {
+ try
+ {
+ for (const auto &itr : MemberReps)
+ {
+ RCSResourceAttributes attrs = itr.getAttributes();
+
+ for (const auto &mappingInfo :
+ attrs.at(SCENE_KEY_SCENEMAPPINGS).get
+ <std::vector< RCSResourceAttributes > >())
+ {
+ std::string sceneName
+ = mappingInfo.at(SCENE_KEY_SCENE).get< std::string >();
+ RemoteScene::Ptr pRemoteScene = nullptr;
+
+ auto remoteScene = m_remoteScenes.find(sceneName);
+ if (remoteScene == m_remoteScenes.end())
+ {
+ pRemoteScene = createRemoteSceneInstance(sceneName);
+ }
+ else
+ {
+ pRemoteScene = m_remoteScenes.at(sceneName);
+ }
+
+ pRemoteScene->addExistingRemoteSceneAction(
+ host + itr.getUri(),
+ attrs.at(SCENE_KEY_PAYLOAD_LINK).get< RCSResourceAttributes >().
+ at(SCENE_KEY_HREF).get< std::string >(),
+ attrs.at(SCENE_KEY_ID).get< std::string >(),
+ mappingInfo.at(SCENE_KEY_MEMBERPROPERTY).get< std::string >(),
+ RCSResourceAttributes::Value(mappingInfo.at(SCENE_KEY_MEMBERVALUE))
+ );
+ }
+ }
+ }
+ catch (const std::exception &)
+ {
+ // error
+ }
+ }
+
+ RemoteScene::Ptr RemoteSceneCollection::createRemoteSceneInstance
+ (const std::string &name)
+ {
+ RemoteScene::Ptr pNewRemoteScene
+ {
+ new RemoteScene(name, m_requestorPtr)
+ };
+
+ m_remoteScenes[name] = pNewRemoteScene;
+
+ return pNewRemoteScene;
+ }
+
+ void RemoteSceneCollection::onSceneAddedRemoved(const int &reqType,
+ const std::string &name, int eCode,
+ const AddNewSceneCallback &addCB, const RemoveSceneCallback &)
+ {
+ if (eCode == SCENE_RESPONSE_SUCCESS)
+ {
+ switch (reqType)
+ {
+ case SceneCollectionResourceRequestor::REQUEST_TYPE::ADD_SCENE:
+ addCB(createRemoteSceneInstance(name), SCENE_RESPONSE_SUCCESS);
+ break;
+
+ case SceneCollectionResourceRequestor::REQUEST_TYPE::REMOVE_SCENE:
+ break;
+ }
+ }
+ else
+ {
+ // error
+ }
+ }
+
+ void RemoteSceneCollection::onNameSet(int eCode, const std::string &name,
+ const SetNameCallback &clientCB)
+ {
+ if (eCode == SCENE_RESPONSE_SUCCESS)
+ m_name = name;
+
+ clientCB(eCode);
+ }
+
+ }
+}
\ No newline at end of file
--- /dev/null
+//******************************************************************
+//
+// 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 "RemoteSceneList.h"
+
+#include <map>
+
+#include "SceneCommons.h"
+#include "RemoteSceneUtils.h"
+#include "SceneListResourceRequestor.h"
+#include "SceneCollectionResourceRequestor.h"
+#include "OCPlatform.h"
+
+namespace OIC
+{
+ namespace Service
+ {
+
+ RemoteSceneList::RemoteSceneList(SceneListResourceRequestor::Ptr pRequestor)
+ : m_requestorPtr{ pRequestor }, m_getResponseHandler{}
+ {
+
+ }
+
+ void RemoteSceneList::createInstance(RCSRemoteResourceObject::Ptr pSceneListResource,
+ CreateInstanceCallback clientCB)
+ {
+ // TODO: check pRequestor not null
+
+ SceneListResourceRequestor::Ptr pRequestor =
+ std::make_shared< SceneListResourceRequestor >(pSceneListResource);
+
+ RemoteSceneList::Ptr newSceneList(new RemoteSceneList(pRequestor));
+
+ clientCB(std::move(newSceneList), SCENE_RESPONSE_SUCCESS);
+ }
+
+ void RemoteSceneList::addNewSceneCollection(AddNewSceneCollectionCallback clientCB)
+ {
+ SceneListResourceRequestor::InternalCreateSceneCollectionCallback internalCB
+ = std::bind(&RemoteSceneList::onSceneCollectionCreated, this,
+ std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
+ std::placeholders::_4, std::move(clientCB));
+
+ m_requestorPtr->requestSceneCollectionCreation("", internalCB);
+ }
+
+ void RemoteSceneList::removeSceneCollection(RemoteSceneCollection::Ptr)
+ {
+
+ }
+
+ std::vector< RemoteSceneCollection::Ptr >
+ RemoteSceneList::getRemoteSceneCollections() const
+ {
+ return m_remoteSceneCollections;
+ }
+
+ void RemoteSceneList::setName(const std::string &name, SetNameCallback clientCB)
+ {
+ SceneListResourceRequestor::InternalSetNameCallback internalCB
+ = std::bind(&RemoteSceneList::onNameSet, this,
+ std::placeholders::_1, name, std::move(clientCB));
+
+ m_requestorPtr->requestSetName(name, internalCB);
+ }
+
+ std::string RemoteSceneList::getName() const
+ {
+ return m_name;
+ }
+
+ RemoteSceneCollection::Ptr RemoteSceneList::createRemoteSceneCollectionInstance
+ (const std::string &link, const std::string &id, const std::string &name)
+ {
+ RemoteSceneCollection::Ptr pNewSceneCollection = nullptr;
+
+ std::vector< std::string > vecRT{ SCENE_COLLECTION_RT };
+ std::vector< std::string > vecIF{ SCENE_CLIENT_REQ_IF };
+
+ RCSRemoteResourceObject::Ptr pResource
+ = createRCSResourceObject(link, SCENE_CONNECTIVITY, vecRT, vecIF);
+
+ if (pResource)
+ {
+ SceneCollectionResourceRequestor::Ptr pRequestor
+ { new SceneCollectionResourceRequestor(pResource) };
+
+ pNewSceneCollection.reset(
+ new RemoteSceneCollection(pRequestor, id, name));
+
+ m_remoteSceneCollections.push_back(pNewSceneCollection);
+ }
+
+ return pNewSceneCollection;
+ }
+
+ void RemoteSceneList::setGetResponseHandler
+ (const std::string &host, GetResponseHandler::GetCallback cb)
+ {
+ m_getResponseHandler.reset(new GetResponseHandler(shared_from_this()));
+
+ m_getResponseHandler->startGetResponseHandler(host, std::move(cb));
+ }
+
+ void RemoteSceneList::onSceneCollectionCreated
+ (const std::string &link, const std::string &id, const std::string &name, int eCode,
+ AddNewSceneCollectionCallback clientCB)
+ {
+ int result = SCENE_CLIENT_BADREQUEST;
+ RemoteSceneCollection::Ptr pNewRemoteSceneCollection = nullptr;
+
+ if (eCode == SCENE_RESPONSE_SUCCESS)
+ {
+ pNewRemoteSceneCollection =
+ createRemoteSceneCollectionInstance(link, id, name);
+
+ // TODO: result type check
+ if (pNewRemoteSceneCollection)
+ result = SCENE_RESPONSE_SUCCESS;
+ }
+ clientCB(pNewRemoteSceneCollection, result);
+ }
+
+ void RemoteSceneList::onNameSet(int eCode, const std::string &name,
+ const SetNameCallback &clientCB)
+ {
+ if (eCode == SCENE_RESPONSE_SUCCESS)
+ m_name = name;
+
+ clientCB(eCode);
+ }
+
+ RemoteSceneList::GetResponseHandler::GetResponseHandler
+ (std::shared_ptr< RemoteSceneList > ptr)
+ : m_errorCode{ SCENE_RESPONSE_SUCCESS }, m_owner{ ptr }
+ {
+
+ }
+
+ void RemoteSceneList::GetResponseHandler::startGetResponseHandler
+ (const std::string &host, GetCallback cb)
+ {
+ RCSRemoteResourceObject::GetCallback ListGetCB
+ = std::bind(&GetResponseHandler::onGetListAttrs, this,
+ std::placeholders::_1, std::placeholders::_2,
+ std::placeholders::_3,
+ host);
+
+ m_cb = cb;
+
+ std::shared_ptr< RemoteSceneList > pList = m_owner.lock();
+
+ if (pList)
+ {
+ pList->m_requestorPtr->
+ requestGet(SCENE_CLIENT_CREATE_REQ_IF, ListGetCB);
+ }
+ }
+
+ void RemoteSceneList::GetResponseHandler::onGetListAttrs
+ (const HeaderOpts &, const RCSRepresentation &rep,
+ int eCode, const std::string &host)
+ {
+ if (eCode == SCENE_RESPONSE_SUCCESS)
+ {
+ std::shared_ptr< RemoteSceneList > pList = m_owner.lock();
+
+ if (pList)
+ {
+ pList->m_name
+ = rep.getAttributes().at(SCENE_KEY_NAME).get< std::string >();
+
+ std::vector< RCSRepresentation > childReps
+ = rep.getChildren();
+
+ if (childReps.size() > 0)
+ {
+ for (auto itr : childReps)
+ {
+ std::vector< std::string > childRTs = itr.getResourceTypes();
+ if (std::find(childRTs.begin(), childRTs.end(), SCENE_COLLECTION_RT)
+ != childRTs.end())
+ {
+ RCSResourceAttributes attr = itr.getAttributes();
+ RemoteSceneCollection::Ptr pNewSceneCollection
+ = pList->createRemoteSceneCollectionInstance(
+ host + rep.getUri(),
+ attr.at(SCENE_KEY_ID).get< std::string >(),
+ attr.at(SCENE_KEY_NAME).get< std::string >());
+
+ if (pNewSceneCollection == nullptr)
+ {
+ // error
+ continue;
+ }
+
+ RCSRemoteResourceObject::GetCallback handlerGetCB
+ = std::bind(&GetResponseHandler::onGetCollectionAttrs,
+ this, std::placeholders::_1,
+ std::placeholders::_2, std::placeholders::_3,
+ pNewSceneCollection, host);
+
+ pNewSceneCollection->m_requestorPtr->requestGet(
+ SCENE_CLIENT_REQ_IF, handlerGetCB);
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ // error
+ }
+ }
+
+ void RemoteSceneList::GetResponseHandler::onGetCollectionAttrs
+ (const HeaderOpts &, const RCSRepresentation &reps, int eCode,
+ RemoteSceneCollection::Ptr pRemoteSceneCollection, const std::string &host)
+ {
+ m_respondedCollections++;
+ if (eCode == SCENE_RESPONSE_SUCCESS)
+ {
+ pRemoteSceneCollection->
+ initializeRemoteSceneCollection(reps.getChildren(), std::string(host));
+ }
+ else
+ {
+ // error
+ m_errorCode = eCode;
+ }
+
+ if (m_respondedCollections == m_numOfCollections)
+ {
+ m_cb(eCode);
+ }
+ }
+
+ }
+}
\ No newline at end of file