# Build resource-encapsulation project
SConscript('resource-encapsulation/SConscript')
+ # Build scene-manager project
+ if target_os in ['linux']:
+ SConscript('scene-manager/SConscript')
+
# Build resource-container project
if target_os not in ['android']:
SConscript('resource-container/SConscript')
--- /dev/null
+#******************************************************************
+#
+# Copyright 2015 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.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+##
+# NotificationManager build script
+##
+
+Import('env')
+
+if env.get('RELEASE'):
+ env.AppendUnique(CCFLAGS = ['-Os'])
+ env.AppendUnique(CPPDEFINES = ['NDEBUG'])
+else:
+ env.AppendUnique(CCFLAGS = ['-g'])
+
+if env.get('LOGGING'):
+ env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+scenemanager_env = lib_env.Clone()
+
+target_os = env.get('TARGET_OS')
+######################################################################
+# Build flags
+######################################################################
+scenemanager_env.AppendUnique(CPPPATH = ['./include'])
+scenemanager_env.AppendUnique(CPPPATH = ['./src'])
+scenemanager_env.AppendUnique(CPPPATH = ['../resource-encapsulation/include'])
+scenemanager_env.AppendUnique(CPPPATH = ['../resource-encapsulation/src/common/primitiveResource/include'])
+scenemanager_env.AppendUnique(CPPPATH = ['../resource-encapsulation/src/common/expiryTimer/include'])
+
+scenemanager_env.PrependUnique(LIBS = [
+ 'rcs_client',
+ 'rcs_server',
+ 'rcs_common',
+ 'oc',
+ 'octbstack',
+ 'oc_logger',
+ 'connectivity_abstraction',
+ 'libcoap'
+ ])
+
+if target_os not in ['windows', 'winrt']:
+ scenemanager_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])
+
+if target_os not in ['darwin', 'ios', 'windows', 'winrt']:
+ scenemanager_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])
+
+if target_os == 'linux':
+ scenemanager_env.AppendUnique(LIBS = ['pthread'])
+
+if target_os == 'android':
+ scenemanager_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
+ scenemanager_env.AppendUnique(LIBS = ['gnustl_shared','log'])
+
+ if not env.get('RELEASE'):
+ scenemanager_env.AppendUnique(LIBS = ['log'])
+
+######################################################################
+# Source files and Targets
+######################################################################
+SCENE_SRC_DIR = './src/'
+scenemanager_src = [
+ SCENE_SRC_DIR + 'SceneCollection.cpp',
+ SCENE_SRC_DIR + 'SceneMemberObject.cpp',
+ SCENE_SRC_DIR + 'SceneAction.cpp',
+ SCENE_SRC_DIR + 'Scene.cpp',
+ SCENE_SRC_DIR + 'SceneList.cpp'
+ ]
+
+if target_os in ['tizen','android'] :
+ scenemanagersdk = scenemanager_env.SharedLibrary('scene_manager', scenemanager_src)
+else :
+ scenemanagersdk = scenemanager_env.StaticLibrary('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')
+
+# Go to build Unit test
+#if target_os == 'linux':
+# SConscript('src/unittest/SConscript')
+
+# Go to build sample apps
+SConscript('sampleapp/SConscript')
--- /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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#ifndef SM_SCENE_H_
+#define SM_SCENE_H_
+
+#include "RCSRemoteResourceObject.h"
+#include "RCSResourceObject.h"
+#include "SceneAction.h"
+
+#include <vector>
+#include <memory>
+
+namespace OIC
+{
+ namespace Service
+ {
+ class Scene
+ {
+ public:
+ typedef std::shared_ptr< Scene > Ptr;
+ typedef std::function< void(const RCSResourceAttributes&, int) > ExecuteCallback;
+ public:
+ Scene (const std::string&);
+ Scene(const std::string&, ExecuteCallback);
+ ~Scene();
+
+ bool addSceneAction(const std::shared_ptr< SceneAction >&);
+ bool removeSceneAction(const std::shared_ptr< SceneAction >&);
+
+ bool execute();
+
+ void setCallback(ExecuteCallback);
+
+ std::string getName() const;
+ void setName(const std::string);
+
+ private:
+ void onSceneActionExecuteResult(const RCSResourceAttributes& attributes, int);
+
+ private:
+ std::string m_sceneName;
+ std::vector< std::shared_ptr< SceneAction > > m_sceneActionList;
+ ExecuteCallback m_callback;
+ };
+
+ } /* namespace Service */
+} /* namespace OIC */
+
+#endif /* RH_HOSTINGOBJECT_H_ */
+
--- /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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#ifndef SM_SCENEACTION_H_
+#define SM_SCENEACTION_H_
+
+#include "SceneMemberObject.h"
+
+namespace OIC
+{
+ namespace Service
+ {
+ class SceneAction
+ {
+ public:
+ typedef std::shared_ptr< SceneAction > Ptr;
+ typedef std::function< void(const RCSResourceAttributes&, int) > ExecuteCallback;
+
+ public:
+ SceneAction(const SceneMemberObject::Ptr&, const std::string&,
+ const RCSResourceAttributes::Value&);
+
+ bool execute();
+
+ void setCallback(ExecuteCallback);
+
+ private:
+ RCSResourceAttributes m_attr;
+ SceneMemberObject::Ptr m_sceneMemberPtr;
+ ExecuteCallback m_callback;
+ };
+ } /* namespace Service */
+} /* namespace OIC */
+
+#endif /* SM_SCENEACTION_H_ */
+
--- /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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#ifndef SM_SCENELIST_H_
+#define SM_SCENELIST_H_
+
+#include <SceneCollection.h>
+
+#include <string>
+#include <memory>
+
+namespace OIC
+{
+ namespace Service
+ {
+// class RCSResourceObject;
+ class RCSRemoteResourceObject;
+
+ class SceneList
+ {
+ public:
+ typedef std::shared_ptr< RCSRemoteResourceObject > RemoteObjectPtr;
+
+ private:
+ SceneList();
+ ~SceneList() = default;
+
+ public:
+ static SceneList * getInstance();
+ SceneCollection::Ptr createSceneCollection();
+
+ void setName(const std::string&);
+ std::string getName() const;
+ };
+ } /* namespace Service */
+} /* namespace OIC */
+#endif /* SM_SCENELIST_H_ */
--- /dev/null
+##
+# Examples build script
+##
+Import('env')
+
+target_os = env.get('TARGET_OS')
+if target_os == 'linux':
+ SConscript('linux/SConscript')
+elif target_os == 'arduino':
+ SConscript('arduino/SConscript')
\ No newline at end of file
--- /dev/null
+##
+# GroupManager build script
+##
+
+Import('env')
+
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+scenemanager_sample_env = lib_env.Clone()
+
+######################################################################
+# Build flags
+######################################################################
+scenemanager_sample_env.AppendUnique(CPPPATH = ['../../include', '../../src'])
+scenemanager_sample_env.AppendUnique(CPPPATH = ['../../../resource-encapsulation/include'])
+scenemanager_sample_env.AppendUnique(CPPPATH = ['../../../../extlibs/cjson'])
+scenemanager_sample_env.AppendUnique(CPPPATH = ['../../../../resource/csdk/connectivity/api'])
+scenemanager_sample_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])
+
+scenemanager_sample_env.AppendUnique(LIBS = [
+ 'scene_manager',
+ 'rcs_client',
+ 'rcs_server',
+ 'rcs_common',
+ 'oc',
+ 'octbstack',
+ 'oc_logger',
+ 'connectivity_abstraction',
+ 'coap',
+ 'pthread'
+ ])
+
+if env.get('SECURED') == '1':
+ scenemanager_sample_env.AppendUnique(LIBS = ['tinydtls'])
+
+if 'rt' in scenemanager_sample_env.get('LIBS'):
+ scenemanager_sample_env.Append(LIBS = ['rt'])
+
+####################################################################
+# Source files and Targets
+######################################################################
+sceneserver = scenemanager_sample_env.Program('sceneserver', 'sceneserver.cpp')
+lightserver = scenemanager_sample_env.Program('lightserver', 'lightserver.cpp')
+#groupclient = scenemanager_sample_env.Program('groupclient', 'groupclient.cpp')
+
+#scenemanager_sample_env.InstallTarget(sampleprovider, 'sampleprovider')
+#scenemanager_sample_env.InstallTarget(sampleconsumer, 'sampleconsumer')
+#scenemanager_env.InstallTarget(samplescenemanager, 'samplescenemanager')
--- /dev/null
+//******************************************************************
+//
+// Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
+// Copyright 2014 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+///
+/// This sample provides steps to define an interface for a resource
+/// (properties and methods) and host this resource on the server.
+///
+
+#include <functional>
+
+#include <pthread.h>
+#include <mutex>
+#include <condition_variable>
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+
+using namespace OC;
+using namespace std;
+namespace PH = std::placeholders;
+
+int gObservation = 0;
+void * ChangeLightRepresentation(void *param);
+void * handleSlowResponse(void *param, std::shared_ptr< OCResourceRequest > pRequest);
+
+// Specifies secure or non-secure
+// false: non-secure resource
+// true: secure resource
+bool isSecure = false;
+
+/// Specifies whether Entity handler is going to do slow response or not
+bool isSlowResponse = false;
+
+// Forward declaring the entityHandler
+
+/// This class represents a single resource named 'lightResource'. This resource has
+/// two simple properties named 'state' and 'power'
+
+class LightResource
+{
+
+public:
+ /// Access this property from a TB client
+ std::string m_power;
+ std::string m_lightUri;
+ OCResourceHandle m_resourceHandle;
+ OCRepresentation m_lightRep;
+
+public:
+ /// Constructor
+ LightResource() :
+ m_power(""), m_lightUri("/a/light"), m_resourceHandle(0)
+ {
+ // Initialize representation
+ m_lightRep.setUri(m_lightUri);
+
+ m_lightRep.setValue("power", m_power);
+ }
+
+ /* Note that this does not need to be a member function: for classes you do not have
+ access to, you can accomplish this with a free function: */
+
+ /// This function internally calls registerResource API.
+ void createResource()
+ {
+ std::string resourceURI = m_lightUri; //URI of the resource
+ std::string resourceTypeName = "core.light"; //resource type name. In this case, it is light
+ std::string resourceInterface = DEFAULT_INTERFACE; // resource interface.
+
+ EntityHandler cb = std::bind(&LightResource::entityHandler, this, PH::_1);
+
+ // This will internally create and register the resource.
+ OCStackResult result = OCPlatform::registerResource(m_resourceHandle, resourceURI,
+ resourceTypeName, resourceInterface, cb, OC_DISCOVERABLE | OC_OBSERVABLE);
+
+ if (OC_STACK_OK != result)
+ {
+ cout << "Resource creation was unsuccessful\n";
+ }
+ else
+ {
+ cout << "Resource URI : " << resourceURI << endl;
+ cout << "\tResource Type Name : " << resourceTypeName << endl;
+ cout << "\tResource Interface : " << DEFAULT_INTERFACE << endl;
+ cout << "\tResource creation is successful with resource handle : " << m_resourceHandle
+ << endl;
+ }
+ }
+
+ OCResourceHandle getHandle()
+ {
+ return m_resourceHandle;
+ }
+
+ // Puts representation.
+ // Gets values from the representation and
+ // updates the internal state
+ void put(OCRepresentation& rep)
+ {
+ try
+ {
+ if (rep.getValue("power", m_power))
+ {
+ cout << "\t\t\t\t" << "power: " << m_power << endl;
+ }
+ else
+ {
+ cout << "\t\t\t\t" << "power not found in the representation" << endl;
+ }
+ }
+ catch (exception& e)
+ {
+ cout << e.what() << endl;
+ }
+
+ }
+
+ // Post representation.
+ // Post can create new resource or simply act like put.
+ // Gets values from the representation and
+ // updates the internal state
+ OCRepresentation post(OCRepresentation& rep)
+ {
+ put(rep);
+ return get();
+ }
+
+ // gets the updated representation.
+ // Updates the representation with latest internal state before
+ // sending out.
+ OCRepresentation get()
+ {
+ m_lightRep.setValue("power", m_power);
+
+ return m_lightRep;
+ }
+
+ void addType(const std::string& type) const
+ {
+ OCStackResult result = OCPlatform::bindTypeToResource(m_resourceHandle, type);
+ if (OC_STACK_OK != result)
+ {
+ cout << "Binding TypeName to Resource was unsuccessful\n";
+ }
+ }
+
+ void addInterface(const std::string& interface) const
+ {
+ OCStackResult result = OCPlatform::bindInterfaceToResource(m_resourceHandle, interface);
+ if (OC_STACK_OK != result)
+ {
+ cout << "Binding TypeName to Resource was unsuccessful\n";
+ }
+ }
+
+private:
+// This is just a sample implementation of entity handler.
+// Entity handler can be implemented in several ways by the manufacturer
+ OCEntityHandlerResult entityHandler(std::shared_ptr< OCResourceRequest > request)
+ {
+ cout << "\tIn Server CPP entity handler:\n";
+ OCEntityHandlerResult ehResult = OC_EH_ERROR;
+ if (request)
+ {
+ // Get the request type and request flag
+ std::string requestType = request->getRequestType();
+ int requestFlag = request->getRequestHandlerFlag();
+
+ if (requestFlag & RequestHandlerFlag::RequestFlag)
+ {
+ cout << "\t\trequestFlag : Request\n";
+ auto pResponse = std::make_shared< OC::OCResourceResponse >();
+ pResponse->setRequestHandle(request->getRequestHandle());
+ pResponse->setResourceHandle(request->getResourceHandle());
+
+ // If the request type is GET
+ if (requestType == "GET")
+ {
+ cout << "\t\t\trequestType : GET\n";
+ if (isSlowResponse) // Slow response case
+ {
+ static int startedThread = 0;
+ if (!startedThread)
+ {
+ std::thread t(handleSlowResponse, (void *) this, request);
+ startedThread = 1;
+ t.detach();
+ }
+ ehResult = OC_EH_SLOW;
+ }
+ else // normal response case.
+ {
+ pResponse->setErrorCode(200);
+ pResponse->setResponseResult(OC_EH_OK);
+ pResponse->setResourceRepresentation(get());
+ if (OC_STACK_OK == OCPlatform::sendResponse(pResponse))
+ {
+ ehResult = OC_EH_OK;
+ }
+ }
+ }
+ else if (requestType == "PUT")
+ {
+ cout << "\t\t\trequestType : PUT\n";
+ OCRepresentation rep = request->getResourceRepresentation();
+
+ // Do related operations related to PUT request
+ // Update the lightResource
+ put(rep);
+ pResponse->setErrorCode(200);
+ pResponse->setResponseResult(OC_EH_OK);
+ pResponse->setResourceRepresentation(get());
+ if (OC_STACK_OK == OCPlatform::sendResponse(pResponse))
+ {
+ ehResult = OC_EH_OK;
+ }
+ }
+ else if (requestType == "POST")
+ {
+ cout << "\t\t\trequestType : POST\n";
+
+ OCRepresentation rep = request->getResourceRepresentation();
+
+ // Do related operations related to POST request
+ OCRepresentation rep_post = post(rep);
+ pResponse->setResourceRepresentation(rep_post);
+ pResponse->setErrorCode(200);
+ if (rep_post.hasAttribute("createduri"))
+ {
+ pResponse->setResponseResult(OC_EH_RESOURCE_CREATED);
+ pResponse->setNewResourceUri(
+ rep_post.getValue< std::string >("createduri"));
+ }
+
+ if (OC_STACK_OK == OCPlatform::sendResponse(pResponse))
+ {
+ ehResult = OC_EH_OK;
+ }
+ }
+ else if (requestType == "DELETE")
+ {
+ // DELETE request operations
+ }
+ }
+ }
+ else
+ {
+ std::cout << "Request invalid" << std::endl;
+ }
+
+ return ehResult;
+ }
+};
+
+void * handleSlowResponse(void *param, std::shared_ptr< OCResourceRequest > pRequest)
+{
+ // This function handles slow response case
+ LightResource* lightPtr = (LightResource*) param;
+ // Induce a case for slow response by using sleep
+ std::cout << "SLOW response" << std::endl;
+ sleep(10);
+
+ auto pResponse = std::make_shared< OC::OCResourceResponse >();
+ pResponse->setRequestHandle(pRequest->getRequestHandle());
+ pResponse->setResourceHandle(pRequest->getResourceHandle());
+ pResponse->setResourceRepresentation(lightPtr->get());
+ pResponse->setErrorCode(200);
+ pResponse->setResponseResult(OC_EH_OK);
+
+ // Set the slow response flag back to false
+ isSlowResponse = false;
+ OCPlatform::sendResponse(pResponse);
+ return NULL;
+}
+
+int main()
+{
+ // Create PlatformConfig object
+ PlatformConfig cfg
+ { OC::ServiceType::InProc, OC::ModeType::Server, "0.0.0.0",
+ // By setting to "0.0.0.0", it binds to all available interfaces
+ 0,// Uses randomly available port
+ OC::QualityOfService::LowQos };
+
+ OCPlatform::Configure(cfg);
+ try
+ {
+ // Create the instance of the resource class
+ // (in this case instance of class 'LightResource').
+ LightResource myLight;
+
+ // Invoke createResource function of class light.
+ myLight.createResource();
+
+ // A condition variable will free the mutex it is given, then do a non-
+ // intensive block until 'notify' is called on it. In this case, since we
+ // don't ever call cv.notify, this should be a non-processor intensive version
+ // of while(true);
+ std::mutex blocker;
+ std::condition_variable cv;
+ std::unique_lock < std::mutex > lock(blocker);
+ cv.wait(lock);
+ }
+ catch (OCException e)
+ {
+ //log(e.what());
+ }
+
+ // No explicit call to stop the platform.
+ // When OCPlatform::destructor is invoked, internally we do platform cleanup
+
+ return 0;
+}
--- /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 <iostream>
+#include <vector>
+
+#include "OCPlatform.h"
+#include "RCSDiscoveryManager.h"
+#include "RCSRemoteResourceObject.h"
+#include "RCSResourceAttributes.h"
+#include "RCSAddress.h"
+#include "SceneList.h"
+
+using namespace OC;
+using namespace OIC::Service;
+
+constexpr int CREATE_SCENE = 1;
+constexpr int EXECUTE_SCENE = 2;
+
+struct CloseApp {};
+
+const std::string resourceType = "core.light";
+const std::string relativetUri = OC_RSRVD_WELL_KNOWN_URI;
+
+std::mutex mtx;
+std::condition_variable cond;
+
+RCSRemoteResourceObject::Ptr g_selectedResource;
+std::shared_ptr<RCSRemoteResourceObject> g_discoveredResources;
+
+std::vector<RCSRemoteResourceObject::Ptr> g_foundResourceList;
+
+std::vector<RCSResourceObject::Ptr> g_memberResourceList;
+
+SceneCollection::Ptr g_sceneColObj;
+Scene::Ptr g_scene;
+std::vector<SceneMemberObject::Ptr> g_sceneMemObj;
+
+typedef std::function<void(std::shared_ptr<RCSRemoteResourceObject>)> DiscoveryCallback;
+typedef std::function<void (const RCSResourceAttributes&, int)> ExecuteCallback;
+
+void onExecute(const RCSResourceAttributes& attrs, int /*Code*/)
+{
+ std::cout << __func__ << std::endl;
+}
+
+void configurePlatform()
+{
+ PlatformConfig config
+ {
+ OC::ServiceType::InProc, ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos
+ };
+ OCPlatform::Configure(config);
+}
+
+int processUserInput(int min, int max)
+{
+ assert(min <= max);
+
+ int input;
+
+ std::cin >> input;
+
+ if (!std::cin.fail())
+ {
+ if(input == max + 1) throw CloseApp();
+ if(min <= input && input <= max) return input;
+ }
+
+ std::cin.clear();
+ std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
+
+ throw std::runtime_error("Invalid Input, please try again");
+}
+
+void onResourceDiscovered(std::shared_ptr<RCSRemoteResourceObject> foundResource)
+{
+ std::cout << "onResourceDiscovered callback" << std::endl;
+
+ std::string resourceURI = foundResource->getUri();
+ std::string hostAddress = foundResource->getAddress();
+
+ std::cout << "\t\tResource URI : " << resourceURI << std::endl;
+ std::cout << "\t\tResource Host : " << hostAddress << std::endl;
+
+ g_foundResourceList.push_back(foundResource);
+
+ cond.notify_all();
+}
+
+bool discoverResource()
+{
+ std::cout << "Wait 2 seconds until discovered." << std::endl;
+
+ try
+ {
+ RCSDiscoveryManager::getInstance()->discoverResourceByType(RCSAddress::multicast(),
+ relativetUri, "core.light", &onResourceDiscovered);
+ }
+ catch(const RCSPlatformException& e)
+ {
+ std::cout << e.what() << std::endl;
+ }
+ std::unique_lock<std::mutex> lck(mtx);
+ cond.wait_for(lck, std::chrono::seconds(2));
+
+ return g_discoveredResources != nullptr;
+}
+
+void createScene()
+{
+ if(g_foundResourceList.size() == 0)
+ {
+ std::cout << "First, find a light resource" << std::endl;
+ return ;
+ }
+
+ g_sceneColObj = SceneList::getInstance()->createSceneCollection();
+
+ g_scene = g_sceneColObj->addScene("allbulbsson");
+ g_scene->setCallback(onExecute);
+
+ for(const auto &it : g_foundResourceList)
+ {
+ g_sceneMemObj.push_back(g_sceneColObj->addSceneMember(it));
+ g_scene->addSceneAction(std::make_shared< SceneAction >(g_sceneMemObj.at(0), "power", "off"));
+ }
+}
+
+void executeScene()
+{
+ if(g_scene != nullptr)
+ g_scene->execute();
+}
+
+int main()
+{
+ configurePlatform();
+
+ discoverResource();
+
+ int command;
+
+ while (true)
+ {
+ try
+ {
+ std::cout << "========================================================\n";
+ std::cout << CREATE_SCENE << ". Create a Scene \n";
+ std::cout << EXECUTE_SCENE << ". Execute a Scene \n";
+ std::cout << "========================================================\n";
+
+ command = processUserInput(CREATE_SCENE, EXECUTE_SCENE);
+
+ switch(command)
+ {
+ case CREATE_SCENE:
+ createScene();
+ break;
+ case EXECUTE_SCENE:
+ executeScene();
+ break;
+ }
+ }
+ catch (const std::exception& e)
+ {
+ std::cout << e.what() << std::endl;
+ }
+ catch (const CloseApp&)
+ {
+ break;
+ }
+ }
+
+ std::cout << "Stopping the client" << std::endl;
+
+ return 0;
+}
--- /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 "Scene.h"
+
+#include <iostream>
+
+namespace OIC
+{
+ namespace Service
+ {
+
+ Scene::Scene(const std::string& sceneName, ExecuteCallback cb) :
+ m_sceneName(sceneName), m_callback(std::move(cb))
+ {
+ }
+
+ Scene::Scene(const std::string& sceneName) :
+ m_sceneName(sceneName)
+ {
+ }
+
+ Scene::~Scene()
+ {
+ m_sceneActionList.clear();
+ }
+
+ bool Scene::addSceneAction(const SceneAction::Ptr& newSceneAction)
+ {
+ if(newSceneAction == nullptr)
+ {
+ throw RCSInvalidParameterException { "SceneAction is empty!" };
+ }
+
+ newSceneAction->setCallback(
+ std::bind(&Scene::onSceneActionExecuteResult, this, std::placeholders::_1,
+ std::placeholders::_2));
+ m_sceneActionList.push_back(newSceneAction);
+
+ return true;
+ }
+ bool Scene::removeSceneAction(const SceneAction::Ptr& sceneAction)
+ {
+ // TODO
+ }
+
+ void Scene::setCallback(ExecuteCallback cb)
+ {
+ if(cb == nullptr)
+ {
+ throw RCSInvalidParameterException { "callback is empty!" };
+ }
+
+ m_callback = std::move(cb);
+ }
+
+ bool Scene::execute()
+ {
+ for (const auto& it : m_sceneActionList)
+ {
+ if (it->execute() == false)
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ std::string Scene::getName() const
+ {
+ return m_sceneName;
+ }
+
+ void Scene::setName(const std::string name)
+ {
+ m_sceneName = name;
+ }
+
+ void Scene::onSceneActionExecuteResult(const RCSResourceAttributes& attributes, int eCode)
+ {
+ if (attributes.empty())
+ {
+ std::cout << "\tattributes is empty" << std::endl;
+ }
+
+ for (const auto& attr : attributes)
+ {
+ std::cout << "\tkey : " << attr.key() << std::endl << "\tvalue : "
+ << attr.value().toString() << std::endl;
+
+ if (m_callback != nullptr)
+ {
+ m_callback(attributes, eCode);
+ }
+ }
+ }
+
+ } /* namespace Service */
+} /* namespace OIC */
+
--- /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 "SceneAction.h"
+
+namespace OIC
+{
+ namespace Service
+ {
+ SceneAction::SceneAction(const SceneMemberObject::Ptr& SceneMemberObjectPtr,
+ const std::string& key, const RCSResourceAttributes::Value& value) :
+ m_sceneMemberPtr(SceneMemberObjectPtr)
+ {
+ m_attr[key] = RCSResourceAttributes::Value(value);
+ }
+
+ void SceneAction::setCallback(ExecuteCallback cb)
+ {
+ if (cb == nullptr)
+ {
+ throw RCSInvalidParameterException { "Callback is empty!" };
+ }
+
+ m_callback = std::move(cb);
+ }
+
+ bool SceneAction::execute()
+ {
+ m_sceneMemberPtr->getRemoteResourceObject()->setRemoteAttributes(m_attr, m_callback);
+ return true;
+ }
+ } /* namespace Service */
+} /* namespace OIC */
+
--- /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 "SceneCollection.h"
+
+#include "uuid/uuid.h"
+#include "octypes.h"
+#include "ocrandom.h"
+
+namespace OIC
+{
+ namespace Service
+ {
+ namespace
+ {
+ unsigned int numSceneCollection = 0;
+
+ const std::string PREFIX_SCENE_COLLECTION_URI = "/a/sceneCollection/";
+ const std::string LAST_SCENE = "lastScene";
+ const std::string SCENE_VALUES = "sceneValues";
+ const std::string SCENE_COLLECTION_NAME = "n";
+ const std::string SCENE_COLLECTION_ID = "id";
+ const std::string SCENE_RTS = "rts";
+ const std::string SCENE_RTS_VALUE = "oic.r.scenemember";
+ const std::string SCENE_PAYLOAD_LINK = "link";
+
+ const std::string SCENE_COLLECTION_RT = "oic.wk.scenecollection";
+
+
+ std::string OICGenerateUUIDStr()
+ {
+ uint8_t uuid[UUID_SIZE] = { 0, };
+ char uuidStr[UUID_STRING_SIZE] = { 0, };
+ if(RAND_UUID_OK == OCGenerateUuid(uuid))
+ {
+ if(RAND_UUID_OK == OCConvertUuidToString(uuid, uuidStr))
+ {
+ return std::string(uuidStr);
+ }
+ }
+ return "";
+ }
+ }
+
+ SceneCollection::SceneCollection()
+ : m_Id(), m_Uri(PREFIX_SCENE_COLLECTION_URI + std::to_string(numSceneCollection++))
+ {
+ m_Id = OICGenerateUUIDStr();
+ if(m_Id == "")
+ {
+ // TODO handle uuid creation fail.
+ }
+
+ m_sceneCollectionResourcePtr = RCSResourceObject::Builder(m_Uri, SCENE_COLLECTION_RT,
+ OC_RSRVD_INTERFACE_DEFAULT).setDiscoverable(true).setObservable(true).build();
+
+ m_sceneCollectionResourcePtr->setAttribute(LAST_SCENE, "");
+ m_sceneCollectionResourcePtr->setAttribute(SCENE_VALUES, std::vector<std::string>());
+ m_sceneCollectionResourcePtr->setAttribute(SCENE_COLLECTION_NAME, "");
+ m_sceneCollectionResourcePtr->setAttribute(SCENE_COLLECTION_ID, m_Id);
+ m_sceneCollectionResourcePtr->setAttribute(SCENE_RTS, SCENE_RTS_VALUE);
+
+
+ m_sceneCollectionResourcePtr->setSetRequestHandler(
+ std::bind(
+ &SceneCollection::setRequestHandler, this,
+ std::placeholders::_1, std::placeholders::_2));
+ }
+
+ const std::vector< Scene::Ptr >& SceneCollection::getSceneList()
+ {
+ return m_SceneList;
+ }
+
+ void SceneCollection::setName(const std::string& sceneCollectionName)
+ {
+ m_sceneCollectionResourcePtr->setAttribute(SCENE_COLLECTION_NAME, sceneCollectionName);
+ }
+
+ std::string SceneCollection::getName() const
+ {
+ return m_sceneCollectionResourcePtr->
+ getAttributeValue(SCENE_COLLECTION_NAME).get<std::string>();
+ }
+
+ std::string SceneCollection::getUri() const
+ {
+ return m_Uri;
+ }
+
+ std::string SceneCollection::getId() const
+ {
+ return m_Id;
+ }
+
+ Scene::Ptr SceneCollection::addScene(const std::string& sceneName)
+ {
+ Scene::Ptr m_scene = std::make_shared < Scene > (sceneName);
+ m_SceneList.push_back(m_scene);
+ return m_scene;
+ }
+
+ bool SceneCollection::removeScene(const Scene::Ptr& it)
+ {
+ // remove scene
+ // remove scene Name list
+ }
+
+ SceneMemberObject::Ptr SceneCollection::addSceneMember(
+ const RCSRemoteResourceObject::Ptr& it)
+ {
+ auto newSceneMemberObj = std::make_shared < SceneMemberObject > (it);
+ m_SceneMemberObjectList.push_back(newSceneMemberObj);
+ return newSceneMemberObj;
+ }
+
+ bool SceneCollection::removeSceneMember(SceneMemberObject::Ptr it)
+ {
+ }
+
+ const std::vector< SceneMemberObject::Ptr >& SceneCollection::getSceneMemberList()
+ {
+ return m_SceneMemberObjectList;
+ }
+
+ RCSSetResponse
+ SceneCollection::setRequestHandler(
+ const RCSRequest & request, RCSResourceAttributes & attributes)
+ {
+ if(attributes.contains(SCENE_PAYLOAD_LINK))
+ {
+ return createSceneMemberRequestHandler(request, attributes);
+ }
+
+ if(attributes.contains(SCENE_VALUES))
+ {
+ return createSceneRequestHandler(request, attributes);
+ }
+
+ if(attributes.contains(LAST_SCENE))
+ {
+ return executeSceneRequestHandler(request, attributes);
+ }
+
+
+ return RCSSetResponse::create(attributes, (int)OC_STACK_ERROR)
+ .setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
+ }
+
+ RCSSetResponse
+ SceneCollection::createSceneMemberRequestHandler(
+ const RCSRequest &, RCSResourceAttributes & attributes)
+ {
+ std::string request_key = attributes.at(SCENE_PAYLOAD_LINK).get<std::string>();
+ // TODO create scene member
+
+ attributes.at(SCENE_COLLECTION_ID) = m_Id;
+
+ return RCSSetResponse::create(attributes)
+ .setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
+ }
+
+ RCSSetResponse
+ SceneCollection::createSceneRequestHandler(
+ const RCSRequest &, RCSResourceAttributes & attributes)
+ {
+ std::vector<std::string> request_key
+ = attributes.at(SCENE_VALUES).get<std::vector<std::string>>();
+
+ std::vector<std::string> newScene;
+ std::vector<std::string>::iterator iter = request_key.begin();
+ std::vector<Scene::Ptr>::iterator foundScene;
+
+ struct FindSceneName
+ {
+ bool operator()(Scene::Ptr scene) const { return scene->getName() == name; }
+ std::string name;
+ };
+
+ while(iter != request_key.end())
+ {
+ FindSceneName fScene;
+ fScene.name = *iter;
+ foundScene = std::find_if(m_SceneList.begin(), m_SceneList.end(), fScene);
+ if(foundScene == m_SceneList.end())
+ {
+ newScene.push_back(*iter);
+ }
+ iter++;
+ }
+
+ for(unsigned int i = 0; i < newScene.size(); ++i)
+ {
+ // TODO create scene
+ newScene[i]; //Scene Value
+ }
+
+
+ // success
+ return RCSSetResponse::create(attributes)
+ .setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
+ }
+
+ RCSSetResponse
+ SceneCollection::executeSceneRequestHandler(
+ const RCSRequest &, RCSResourceAttributes & attributes)
+ {
+ std::string request_key = attributes.at(LAST_SCENE).get<std::string>();
+ m_sceneCollectionResourcePtr->setAttribute(LAST_SCENE, request_key);
+
+ // TODO execute scene
+
+ // success
+ return RCSSetResponse::create(attributes)
+ .setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
+ }
+ } /* namespace Service */
+} /* namespace OIC */
+
--- /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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#ifndef SM_SCENECOLLECTION_H_
+#define SM_SCENECOLLECTION_H_
+
+#include <functional>
+#include <memory>
+
+#include "RCSResourceObject.h"
+#include "RCSRemoteResourceObject.h"
+#include "SceneMemberObject.h"
+#include "Scene.h"
+
+namespace OIC
+{
+ namespace Service
+ {
+ class Scene;
+ class SceneCollection
+ {
+ public:
+ typedef std::shared_ptr< SceneCollection > Ptr;
+
+ public:
+ SceneCollection();
+
+ void setName(const std::string&);
+ std::string getName() const;
+
+ std::string getUri() const;
+ std::string getId() const;
+
+ Scene::Ptr addScene(const std::string&);
+ const std::vector< Scene::Ptr >& getSceneList();
+ bool removeScene(const Scene::Ptr&);
+
+ SceneMemberObject::Ptr addSceneMember(const RCSRemoteResourceObject::Ptr&);
+ const std::vector< SceneMemberObject::Ptr >& getSceneMemberList();
+ bool removeSceneMember(SceneMemberObject::Ptr);
+
+ private:
+ RCSSetResponse setRequestHandler(const RCSRequest&, RCSResourceAttributes&);
+ RCSSetResponse createSceneRequestHandler(const RCSRequest&, RCSResourceAttributes&);
+ RCSSetResponse executeSceneRequestHandler(const RCSRequest&, RCSResourceAttributes&);
+ RCSSetResponse createSceneMemberRequestHandler(const RCSRequest&,
+ RCSResourceAttributes&);
+
+ private:
+ std::string m_Id;
+ std::string m_Uri;
+
+ std::vector< Scene::Ptr > m_SceneList;
+ std::vector< SceneMemberObject::Ptr > m_SceneMemberObjectList;
+
+ RCSResourceObject::Ptr m_sceneCollectionResourcePtr;
+ };
+ } /* namespace Service */
+} /* namespace OIC */
+
+#endif /* SM_SCENECOLLECTION_H_ */
+
--- /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 "SceneList.h"
+
+#include "RCSRequest.h"
+#include "PrimitiveResource.h"
+#include "OCPlatform.h"
+
+namespace OIC
+{
+ namespace Service
+ {
+ namespace
+ {
+ const std::string SCENE_LIST_NAME = "n";
+ const std::string SCENE_LIST_ID = "id";
+ const std::string SCENE_LIST_LINK = "link";
+ const std::string SCENE_LIST_RTS = "rts";
+ const std::string SCENE_LIST_RTS_VALUE = "oic.wk.scenecollection";
+ const std::string SCENE_LIST_RT_NAME = "oic.wk.scenelist";
+ const std::string SCENE_LIST_URI = "/SceneListResURI";
+ const std::string SCENE_LIST_DEFAULT_NAME = "list of scene Collections";
+ const std::string COAP_TAG = "coap://";
+
+ RCSResourceObject::Ptr sceneListResourcePtr;
+ // < std::string uri, SceneCollection::Ptr collection_instance >
+ std::map< std::string, SceneCollection::Ptr > sceneCollections;
+
+ RCSSetResponse setRequestHandler(const RCSRequest & /*request*/,
+ RCSResourceAttributes & attributes)
+ {
+ auto newObject = SceneList::getInstance()->createSceneCollection();
+
+ if (newObject == nullptr)
+ {
+ return RCSSetResponse::create(attributes, (int) OC_STACK_ERROR).setAcceptanceMethod(
+ RCSSetResponse::AcceptanceMethod::IGNORE);
+ }
+
+ newObject->setName(attributes.at(SCENE_LIST_NAME).get< std::string >());
+
+ attributes.at(SCENE_LIST_ID) = newObject->getId();
+ attributes.at(SCENE_LIST_LINK) = COAP_TAG + newObject->getUri();
+
+ return RCSSetResponse::create(attributes).setAcceptanceMethod(
+ RCSSetResponse::AcceptanceMethod::IGNORE);
+ }
+ }
+
+ SceneList::SceneList()
+ {
+ sceneListResourcePtr = RCSResourceObject::Builder(SCENE_LIST_URI, SCENE_LIST_RT_NAME,
+ OC_RSRVD_INTERFACE_DEFAULT).setDiscoverable(true).setObservable(false).build();
+
+ sceneListResourcePtr->setAttribute(SCENE_LIST_NAME, SCENE_LIST_DEFAULT_NAME);
+ sceneListResourcePtr->setAttribute(SCENE_LIST_RTS, SCENE_LIST_RTS_VALUE);
+ sceneListResourcePtr->setSetRequestHandler(&setRequestHandler);
+ }
+
+ SceneList* SceneList::getInstance()
+ {
+ static SceneList instance;
+ return &instance;
+ }
+
+ SceneCollection::Ptr SceneList::createSceneCollection()
+ {
+ auto newSceneCollectionObj = std::make_shared< SceneCollection >();
+
+ if (newSceneCollectionObj != nullptr)
+ {
+ sceneCollections.insert(
+ std::make_pair(newSceneCollectionObj->getUri(), newSceneCollectionObj));
+ // TODO : bind resource!!
+ return newSceneCollectionObj;
+ }
+ return nullptr;
+ }
+
+ void SceneList::setName(const std::string& name)
+ {
+ sceneListResourcePtr->setAttribute(SCENE_LIST_NAME, name);
+ }
+
+ std::string SceneList::getName() const
+ {
+ return sceneListResourcePtr->getAttributeValue(SCENE_LIST_NAME).toString();
+ }
+
+ } /* namespace Service */
+} /* namespace OIC */
+
--- /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 "SceneMemberObject.h"
+
+namespace OIC
+{
+ namespace Service
+ {
+ namespace
+ {
+ unsigned int m_numSceneMember = 0;
+
+ const std::string SCENE_MEMBER_RT = "oic.r.scenemember";
+ }
+
+ SceneMemberObject::SceneMemberObject(RCSRemoteResourceObject::Ptr it) :
+ link{ it->getUri() }
+ {
+ RemoteObjectPtr = it;
+
+ std::string resourceUri = "/a/sceneMember" + std::to_string(m_numSceneMember++);
+ sceneMemberResourcePtr = RCSResourceObject::Builder(resourceUri, SCENE_MEMBER_RT,
+ OC_RSRVD_INTERFACE_DEFAULT).setDiscoverable(true).setObservable(true).build();
+
+ sceneMemberResourcePtr->setAutoNotifyPolicy(RCSResourceObject::AutoNotifyPolicy::NEVER);
+ sceneMemberResourcePtr->setSetRequestHandlerPolicy(
+ RCSResourceObject::SetRequestHandlerPolicy::NEVER);
+
+ sceneMemberResourcePtr->setAttribute("link", it->getUri());
+ }
+
+ void SceneMemberObject::setName(std::string sceneMemberName)
+ {
+ name = sceneMemberName;
+ sceneMemberResourcePtr->setAttribute("name", sceneMemberName);
+ }
+
+ std::string SceneMemberObject::getName()
+ {
+ return name;
+ }
+
+ RCSResourceAttributes SceneMemberObject::getSceneMappingItem(std::string sceneName)
+ {
+ for (const auto& it : sceneMapping)
+ {
+ if (it.first == sceneName)
+ return it.second;
+ }
+ }
+
+ std::map< std::string, RCSResourceAttributes > SceneMemberObject::getSceneMapping()
+ {
+ return sceneMapping;
+ }
+
+ bool SceneMemberObject::hasSceneMappingitem(std::string sceneName)
+ {
+ if (sceneMapping.find(sceneName) == sceneMapping.end())
+ return false;
+ return true;
+ }
+
+ RCSRemoteResourceObject::Ptr SceneMemberObject::getRemoteResourceObject()
+ {
+ return RemoteObjectPtr;
+ }
+
+ } /* namespace Service */
+} /* namespace OIC */
+
--- /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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#ifndef SM_SCENEMEMBEROBJECT_H_
+#define SM_SCENEMEMBEROBJECT_H_
+
+#include <cstdbool>
+#include <list>
+#include <functional>
+#include <string>
+#include <map>
+
+#include "octypes.h"
+
+#include "RCSRemoteResourceObject.h"
+#include "RCSResourceObject.h"
+
+namespace OIC
+{
+ namespace Service
+ {
+ class SceneMemberObject
+ {
+ public:
+ typedef std::shared_ptr< SceneMemberObject > Ptr;
+
+ public:
+ SceneMemberObject(RCSRemoteResourceObject::Ptr);
+
+ public:
+ void setName(std::string);
+ std::string getName();
+
+ RCSResourceAttributes getSceneMappingItem(std::string);
+ std::map< std::string, RCSResourceAttributes > getSceneMapping();
+ bool hasSceneMappingitem(std::string);
+ RCSRemoteResourceObject::Ptr getRemoteResourceObject();
+
+ private:
+ unsigned int Id;
+ std::string name;
+ std::string link;
+ std::map< std::string, RCSResourceAttributes > sceneMapping;
+
+ RCSRemoteResourceObject::Ptr RemoteObjectPtr;
+ RCSResourceObject::Ptr sceneMemberResourcePtr;
+ };
+ } /* namespace Service */
+} /* namespace OIC */
+#endif /* SM_SCENEMEMBEROBJECT_H_ */