SConscript(build_dir + 'resource/SConscript')
# Build 'service' sub-project
-#SConscript(build_dir + 'service/SConscript')
+SConscript(build_dir + 'service/SConscript')
# Append targets information to the help information, to see help info, execute command line:
# $ scon [options] -h
######################################################################
# Build flags
######################################################################
-things_manager_env.AppendUnique(CPPPATH = ['tgm/inc'])
-things_manager_env.AppendUnique(CPPPATH = ['sdk/inc'])
+things_manager_env.AppendUnique(CPPPATH = ['sdk/inc', 'sdk/src'])
if target_os not in ['windows', 'winrt']:
things_manager_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])
######################################################################
# Source files and Targets
######################################################################
-tgmsdk = things_manager_env.StaticLibrary('TGMSDKLibrary', 'sdk/src/TGMClient.cpp')
+tgm_src = env.Glob('sdk/src/*.cpp')
+tgmsdk = things_manager_env.StaticLibrary('TGMSDKLibrary', tgm_src)
things_manager_env.InstallTarget(tgmsdk, 'libTGMSDK')
#Go to build sample apps
-SConscript('sampleapp/SConscript')
\ No newline at end of file
+SConscript('sampleapp/SConscript')
+++ /dev/null
-.PHONY : pre resource sdk sampleapp
-#.PHONY : lib tgm sdk sampleapp
-all: .PHONY
-
-pre:
- -mkdir release
-
-resource:
- cd ../../../../resource && $(MAKE)
-
-
-sdk:
- cd ../../sdk/build/linux && $(MAKE)
- cp -Rdp ../../sdk/build/linux/*.a release/
-
-
-sampleapp:
-# cd ../../sampleapp/linux/tgmclient && $(MAKE)
-# cp -Rdp ../../sampleapp/linux/tgmclient/tgmclient release/
-
-clean:
- cd ../../sdk/build/linux && $(MAKE) clean
- cd ../../sampleapp/linux/tgmclient && $(MAKE) clean
-
- rm -rf ./release/*
--- /dev/null
+.PHONY : pre resource sdk sampleapp
+#.PHONY : lib tgm sdk sampleapp
+all: .PHONY
+
+pre:
+ -mkdir release
+
+resource:
+ cd ../../../../resource && $(MAKE)
+
+
+sdk:
+ cd ../../sdk/build/linux && $(MAKE)
+ cp -Rdp ../../sdk/build/linux/*.a release/
+
+sampleapp:
+ cd ../../sampleapp/linux && $(MAKE)
+ cp -Rdp ../../sampleapp/linux/configuration/con-server release/
+ cp -Rdp ../../sampleapp/linux/configuration/con-client release/
+ cp -Rdp ../../sampleapp/linux/configuration/bootstrapserver release/
+ cp -Rdp ../../sampleapp/linux/groupaction/groupserver release/
+ cp -Rdp ../../sampleapp/linux/groupaction/bookmark release/
+ cp -Rdp ../../sampleapp/linux/groupaction/lightserver release/
+ cp -Rdp ../../sampleapp/linux/groupsyncaction/group release/
+ cp -Rdp ../../sampleapp/linux/groupsyncaction/musicplayer release/
+ cp -Rdp ../../sampleapp/linux/groupsyncaction/phone release/
+ cp -Rdp ../../sampleapp/linux/groupsyncaction/speaker release/
+
+clean:
+ cd ../../sdk/build/linux && $(MAKE) clean
+ cd ../../sampleapp/linux && $(MAKE) clean
+ rm -rf ./release
--- /dev/null
+##
+# sampleapp build script
+##
+
+Import('env')
+
+# Add third party libraries
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+sample_env = lib_env.Clone()
+target_os = env.get('TARGET_OS')
+
+######################################################################
+# Build flags
+######################################################################
+
+######################################################################
+# Source files and Targets
+######################################################################
+if target_os == 'linux' :
+ # Build linux sample app
+ SConscript('linux/configuration/SConscript')
+ SConscript('linux/groupaction/SConscript')
+ SConscript('linux/groupsyncaction/SConscript')
--- /dev/null
+//******************************************************************
+//
+// 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 shows how one could create a resource (collection) with children.
+///
+
+#include <functional>
+#include <thread>
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "ThingsManager.h"
+#include "ConfigurationCollection.h"
+
+using namespace OC;
+
+/// This function internally calls registerResource API.
+void ConfigurationCollection::createResources(ResourceEntityHandler callback)
+{
+ using namespace OC::OCPlatform;
+
+ if (callback == NULL)
+ {
+ std::cout << "callback should be binded\t";
+ return;
+ }
+
+ // This will internally create and register the resource.
+ OCStackResult result = registerResource(m_configurationHandle, m_configurationUri,
+ m_configurationTypes[0], m_configurationInterfaces[0], callback,
+ OC_DISCOVERABLE | OC_OBSERVABLE);
+
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Resource creation (configuration) was unsuccessful\n";
+ }
+
+ result = bindInterfaceToResource(m_configurationHandle, m_configurationInterfaces[1]);
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Binding TypeName to Resource was unsuccessful\n";
+ }
+
+ result = bindInterfaceToResource(m_configurationHandle, m_configurationInterfaces[2]);
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Binding TypeName to Resource was unsuccessful\n";
+ }
+
+ result = registerResource(m_regionHandle, m_regionUri, m_regionTypes[0], m_regionInterfaces[0],
+ callback, OC_DISCOVERABLE | OC_OBSERVABLE);
+
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Resource creation (region) was unsuccessful\n";
+ }
+
+ result = registerResource(m_timeHandle, m_timeUri, m_timeTypes[0], m_timeInterfaces[0],
+ callback, OC_DISCOVERABLE | OC_OBSERVABLE);
+
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Resource creation (time) was unsuccessful\n";
+ }
+
+ result = registerResource(m_networkHandle, m_networkUri, m_networkTypes[0],
+ m_networkInterfaces[0], callback, OC_DISCOVERABLE | OC_OBSERVABLE);
+
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Resource creation (network) was unsuccessful\n";
+ }
+
+ result = registerResource(m_securityHandle, m_securityUri, m_securityTypes[0],
+ m_securityInterfaces[0], callback, OC_DISCOVERABLE | OC_OBSERVABLE);
+
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Resource creation (security) was unsuccessful\n";
+ }
+
+ result = bindResource(m_configurationHandle, m_regionHandle);
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Binding region resource to room was unsuccessful\n";
+ }
+
+ result = bindResource(m_configurationHandle, m_timeHandle);
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Binding time resource to room was unsuccessful\n";
+ }
+
+ result = bindResource(m_configurationHandle, m_networkHandle);
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Binding network resource to room was unsuccessful\n";
+ }
+
+ result = bindResource(m_configurationHandle, m_securityHandle);
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Binding security resource to room was unsuccessful\n";
+ }
+
+ std::cout << "Configuration Collection is Created!(URI: " << m_configurationUri << ") \n";
+
+ myTimeCollection->createResources(callback);
+ myNetworkCollection->createResources(callback);
+ mySecurityCollection->createResources(callback);
+
+}
+
+void ConfigurationCollection::setConfigurationRepresentation(OCRepresentation& rep)
+{
+ string value;
+
+ if (rep.getValue("value", value))
+ {
+ m_configurationValue = value;
+
+ std::cout << "\t\t\t\t" << "m_configurationValue: " << m_configurationValue << std::endl;
+ }
+}
+
+void ConfigurationCollection::setTimeRepresentation(OCRepresentation& rep)
+{
+ string value;
+
+ if (rep.getValue("link", value))
+ {
+ // NOT ALLOWED
+
+ std::cout << "\t\t\t\t" << "link: " << m_timeLink << std::endl;
+ }
+}
+
+void ConfigurationCollection::setNetworkRepresentation(OCRepresentation& rep)
+{
+ string value;
+
+ if (rep.getValue("link", value))
+ {
+ // NOT ALLOWED
+
+ std::cout << "\t\t\t\t" << "link: " << m_networkLink << std::endl;
+ }
+}
+
+void ConfigurationCollection::setSecurityRepresentation(OCRepresentation& rep)
+{
+ string value;
+
+ if (rep.getValue("link", value))
+ {
+ // NOT ALLOWED
+
+ std::cout << "\t\t\t\t" << "link: " << m_securityLink << std::endl;
+ }
+}
+
+void ConfigurationCollection::setRegionRepresentation(OCRepresentation& rep)
+{
+ string value;
+
+ if (rep.getValue("value", value))
+ {
+ m_regionValue = value;
+
+ std::cout << "\t\t\t\t" << "value: " << m_regionValue << std::endl;
+ }
+}
+
+OCRepresentation ConfigurationCollection::getTimeRepresentation()
+{
+ m_timeRep.setValue("link", m_timeLink);
+
+ return m_timeRep;
+}
+
+OCRepresentation ConfigurationCollection::getNetworkRepresentation()
+{
+ m_networkRep.setValue("link", m_networkLink);
+
+ return m_networkRep;
+}
+
+OCRepresentation ConfigurationCollection::getSecurityRepresentation()
+{
+ m_securityRep.setValue("link", m_securityLink);
+
+ return m_securityRep;
+}
+
+OCRepresentation ConfigurationCollection::getRegionRepresentation()
+{
+ m_regionRep.setValue("value", m_regionValue);
+
+ return m_regionRep;
+}
+
+OCRepresentation ConfigurationCollection::getConfigurationRepresentation()
+{
+ m_configurationRep.clearChildren();
+
+ m_configurationRep.addChild(getRegionRepresentation());
+ m_configurationRep.addChild(getTimeRepresentation());
+ m_configurationRep.addChild(getNetworkRepresentation());
+ m_configurationRep.addChild(getSecurityRepresentation());
+
+ m_configurationRep.setValue("value", m_configurationValue);
+
+ return m_configurationRep;
+}
+
+std::string ConfigurationCollection::getConfigurationUri()
+{
+ return m_configurationUri;
+}
+
+std::string ConfigurationCollection::getTimeUri()
+{
+ return m_timeUri;
+}
+
+std::string ConfigurationCollection::getNetworkUri()
+{
+ return m_networkUri;
+}
+
+std::string ConfigurationCollection::getSecurityUri()
+{
+ return m_securityUri;
+}
+
+std::string ConfigurationCollection::getRegionUri()
+{
+ return m_regionUri;
+}
+
+void ConfigurationCollection::factoryReset()
+{
+ m_configurationValue = defaultConfigurationValue;
+ m_regionValue = defaultRegionValue;
+ m_timeLink = defaultTimeLink;
+ m_networkLink = defaultNetworkLink;
+ m_securityLink = defaultSecurityLink;
+
+ myTimeCollection->factoryReset();
+ myNetworkCollection->factoryReset();
+ mySecurityCollection->factoryReset();
+}
+
+/// This function internally calls registerResource API.
+void TimeCollection::createResources(ResourceEntityHandler callback)
+{
+ using namespace OC::OCPlatform;
+
+ if (callback == NULL)
+ {
+ std::cout << "callback should be binded\t";
+ return;
+ }
+
+ // This will internally create and register the resource.
+ OCStackResult result = registerResource(m_timeHandle, m_timeUri, m_timeTypes[0],
+ m_timeInterfaces[0], callback, OC_DISCOVERABLE | OC_OBSERVABLE);
+
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Resource creation (time) was unsuccessful\n";
+ }
+
+ result = bindInterfaceToResource(m_timeHandle, m_timeInterfaces[1]);
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Binding TypeName to Resource was unsuccessful\n";
+ }
+
+ result = bindInterfaceToResource(m_timeHandle, m_timeInterfaces[2]);
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Binding TypeName to Resource was unsuccessful\n";
+ }
+
+ result = registerResource(m_currentTimeHandle, m_currentTimeUri, m_currentTimeTypes[0],
+ m_currentTimeInterfaces[0], callback, OC_DISCOVERABLE | OC_OBSERVABLE);
+
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Resource creation (currentTime) was unsuccessful\n";
+ }
+
+ result = bindResource(m_timeHandle, m_currentTimeHandle);
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Binding currentTime resource to room was unsuccessful\n";
+ }
+
+ std::cout << "Time Collection is Created!(URI: " << m_timeUri << ") \n";
+}
+
+void TimeCollection::setTimeRepresentation(OCRepresentation& rep)
+{
+ string value;
+
+ if (rep.getValue("value", value))
+ {
+ m_timeValue = value;
+
+ std::cout << "\t\t\t\t" << "m_timeValue: " << m_timeValue << std::endl;
+ }
+}
+
+void TimeCollection::setCurrentTimeRepresentation(OCRepresentation& rep)
+{
+ string value;
+
+ if (rep.getValue("currentTime", value))
+ {
+ m_currentTimeValue = value;
+
+ std::cout << "\t\t\t\t" << "value: " << m_currentTimeValue << std::endl;
+ }
+}
+
+OCRepresentation TimeCollection::getCurrentTimeRepresentation()
+{
+ m_currentTimeRep.setValue("value", m_currentTimeValue);
+
+ return m_currentTimeRep;
+}
+
+OCRepresentation TimeCollection::getTimeRepresentation()
+{
+ m_timeRep.clearChildren();
+
+ m_timeRep.addChild(getCurrentTimeRepresentation());
+
+ m_timeRep.setValue("value", m_timeValue);
+
+ return m_timeRep;
+}
+
+std::string TimeCollection::getTimeUri()
+{
+ return m_timeUri;
+}
+
+std::string TimeCollection::getCurrentTimeUri()
+{
+ return m_currentTimeUri;
+}
+
+void TimeCollection::factoryReset()
+{
+ m_timeValue = defaultTimeValue;
+ m_currentTimeValue = defaultCurrentTimeValue;
+}
+
+/// This function internally calls registerResource API.
+void NetworkCollection::createResources(ResourceEntityHandler callback)
+{
+ using namespace OC::OCPlatform;
+
+ if (callback == NULL)
+ {
+ std::cout << "callback should be binded\t";
+ return;
+ }
+
+ // This will internally create and register the resource.
+ OCStackResult result = registerResource(m_networkHandle, m_networkUri, m_networkTypes[0],
+ m_networkInterfaces[0], callback, OC_DISCOVERABLE | OC_OBSERVABLE);
+
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Resource creation (network) was unsuccessful\n";
+ }
+
+ result = bindInterfaceToResource(m_networkHandle, m_networkInterfaces[1]);
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Binding TypeName to Resource was unsuccessful\n";
+ }
+
+ result = bindInterfaceToResource(m_networkHandle, m_networkInterfaces[2]);
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Binding TypeName to Resource was unsuccessful\n";
+ }
+
+ result = registerResource(m_IPAddressHandle, m_IPAddressUri, m_IPAddressTypes[0],
+ m_IPAddressInterfaces[0], callback, OC_DISCOVERABLE | OC_OBSERVABLE);
+
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Resource creation (IPAddress) was unsuccessful\n";
+ }
+
+ result = bindResource(m_networkHandle, m_IPAddressHandle);
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Binding IPAddress resource to room was unsuccessful\n";
+ }
+
+ std::cout << "Network Collection is Created!(URI: " << m_networkUri << ") \n";
+}
+
+void NetworkCollection::setNetworkRepresentation(OCRepresentation& rep)
+{
+ string value;
+
+ if (rep.getValue("value", value))
+ {
+ m_networkValue = value;
+
+ std::cout << "\t\t\t\t" << "m_networkValue: " << m_networkValue << std::endl;
+ }
+}
+
+void NetworkCollection::setIPAddressRepresentation(OCRepresentation& rep)
+{
+ string value;
+
+ if (rep.getValue("IPAddress", value))
+ {
+ m_IPAddressValue = value;
+
+ std::cout << "\t\t\t\t" << "value: " << m_IPAddressValue << std::endl;
+ }
+}
+OCRepresentation NetworkCollection::getIPAddressRepresentation()
+{
+ m_IPAddressRep.setValue("value", m_IPAddressValue);
+
+ return m_IPAddressRep;
+}
+
+OCRepresentation NetworkCollection::getNetworkRepresentation()
+{
+ m_networkRep.clearChildren();
+
+ m_networkRep.addChild(getIPAddressRepresentation());
+
+ m_networkRep.setValue("value", m_networkValue);
+
+ return m_networkRep;
+}
+
+std::string NetworkCollection::getNetworkUri()
+{
+ return m_networkUri;
+}
+
+std::string NetworkCollection::getIPAddressUri()
+{
+ return m_IPAddressUri;
+}
+
+void NetworkCollection::factoryReset()
+{
+ m_networkValue = defaultNetworkValue;
+ m_IPAddressValue = defaultIPAddressValue;
+}
+
+/// This function internally calls registerResource API.
+void SecurityCollection::createResources(ResourceEntityHandler callback)
+{
+ using namespace OC::OCPlatform;
+
+ if (callback == NULL)
+ {
+ std::cout << "callback should be binded\t";
+ return;
+ }
+
+ // This will internally create and register the resource.
+ OCStackResult result = registerResource(m_securityHandle, m_securityUri, m_securityTypes[0],
+ m_securityInterfaces[0], callback, OC_DISCOVERABLE | OC_OBSERVABLE);
+
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Resource creation (security) was unsuccessful\n";
+ }
+
+ result = bindInterfaceToResource(m_securityHandle, m_securityInterfaces[1]);
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Binding TypeName to Resource was unsuccessful\n";
+ }
+
+ result = bindInterfaceToResource(m_securityHandle, m_securityInterfaces[2]);
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Binding TypeName to Resource was unsuccessful\n";
+ }
+
+ result = registerResource(m_modeHandle, m_modeUri, m_modeTypes[0], m_modeInterfaces[0],
+ callback, OC_DISCOVERABLE | OC_OBSERVABLE);
+
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Resource creation (mode) was unsuccessful\n";
+ }
+
+ result = bindResource(m_securityHandle, m_modeHandle);
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Binding mode resource to room was unsuccessful\n";
+ }
+
+ std::cout << "Security Collection is Created!(URI: " << m_securityUri << ") \n";
+}
+
+void SecurityCollection::setSecurityRepresentation(OCRepresentation& rep)
+{
+ string value;
+
+ if (rep.getValue("value", value))
+ {
+ m_securityValue = value;
+
+ std::cout << "\t\t\t\t" << "m_securityValue: " << m_securityValue << std::endl;
+ }
+}
+
+void SecurityCollection::setModeRepresentation(OCRepresentation& rep)
+{
+ string value;
+
+ if (rep.getValue("mode", value))
+ {
+ m_modeValue = value;
+
+ std::cout << "\t\t\t\t" << "value: " << m_modeValue << std::endl;
+ }
+}
+
+OCRepresentation SecurityCollection::getModeRepresentation()
+{
+ m_modeRep.setValue("value", m_modeValue);
+
+ return m_modeRep;
+}
+
+OCRepresentation SecurityCollection::getSecurityRepresentation()
+{
+ m_securityRep.clearChildren();
+
+ m_securityRep.addChild(getModeRepresentation());
+
+ m_securityRep.setValue("value", m_securityValue);
+
+ return m_securityRep;
+}
+
+std::string SecurityCollection::getSecurityUri()
+{
+ return m_securityUri;
+}
+
+std::string SecurityCollection::getModeUri()
+{
+ return m_modeUri;
+}
+
+void SecurityCollection::factoryReset()
+{
+ m_securityValue = defaultSecurityValue;
+ m_modeValue = defaultModeValue;
+}
+
--- /dev/null
+//******************************************************************
+//
+// 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 shows how one could create a resource (collection) with children.
+///
+
+#include <functional>
+#include <thread>
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "ThingsManager.h"
+
+#pragma once
+
+using namespace OC;
+
+typedef std::function< OCEntityHandlerResult(std::shared_ptr< OCResourceRequest > request) > ResourceEntityHandler;
+
+static std::string defaultURIPrefix = "/oic/con";
+static std::string defaultResourceTypePrefix = "oic.con";
+
+extern std::string defaultTimeValue;
+extern std::string defaultCurrentTimeValue;
+
+class TimeCollection
+{
+public:
+
+ // diagnostics members
+ std::string m_timeUri;
+ std::string m_timeValue;
+ std::vector< std::string > m_timeTypes;
+ std::vector< std::string > m_timeInterfaces;
+ OCResourceHandle m_timeHandle;
+ OCRepresentation m_timeRep;
+
+ // factory reset members
+ std::string m_currentTimeUri;
+ std::string m_currentTimeValue;
+ std::vector< std::string > m_currentTimeTypes;
+ std::vector< std::string > m_currentTimeInterfaces;
+ OCResourceHandle m_currentTimeHandle;
+ OCRepresentation m_currentTimeRep;
+
+public:
+ /// Constructor
+ TimeCollection() :
+ m_timeValue(defaultTimeValue), m_currentTimeValue(defaultCurrentTimeValue)
+ {
+ m_currentTimeUri = defaultURIPrefix + "/time/0/currentTime"; // URI of the resource
+ m_currentTimeTypes.push_back("oic.con.time.currentTime"); // resource type name.
+ m_currentTimeInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+
+ m_currentTimeRep.setUri(m_currentTimeUri);
+ m_currentTimeRep.setResourceTypes(m_currentTimeTypes);
+ m_currentTimeRep.setResourceInterfaces(m_currentTimeInterfaces);
+ m_currentTimeRep.setValue("value", m_currentTimeValue);
+ m_currentTimeHandle = NULL;
+
+ m_timeUri = defaultURIPrefix + "/time"; // URI of the resource
+ m_timeTypes.push_back("oic.con.time"); // resource type name.
+ m_timeInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+ m_timeInterfaces.push_back(BATCH_INTERFACE); // resource interface.
+ m_timeInterfaces.push_back(LINK_INTERFACE); // resource interface.
+ m_timeRep.setValue("value", m_timeValue);
+ m_timeRep.setUri(m_timeUri);
+ m_timeRep.setResourceTypes(m_timeTypes);
+ m_timeRep.setResourceInterfaces(m_timeInterfaces);
+ m_timeHandle = NULL;
+ }
+ ;
+
+ /// Constructor
+ TimeCollection(std::string URIPrefix, std::string ResourceTypePrefix) :
+ m_timeValue(defaultTimeValue), m_currentTimeValue(defaultCurrentTimeValue)
+ {
+ m_currentTimeUri = URIPrefix + "/time/0/currentTime"; // URI of the resource
+ m_currentTimeTypes.push_back(ResourceTypePrefix + ".time.currentTime"); // type name.
+ m_currentTimeInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+
+ m_currentTimeRep.setUri(m_currentTimeUri);
+ m_currentTimeRep.setResourceTypes(m_currentTimeTypes);
+ m_currentTimeRep.setResourceInterfaces(m_currentTimeInterfaces);
+ m_currentTimeRep.setValue("value", m_currentTimeValue);
+ m_currentTimeHandle = NULL;
+
+ m_timeUri = URIPrefix + "/time"; // URI of the resource
+ m_timeTypes.push_back(ResourceTypePrefix + ".time"); // resource type name.
+ m_timeInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+ m_timeInterfaces.push_back(BATCH_INTERFACE); // resource interface.
+ m_timeInterfaces.push_back(LINK_INTERFACE); // resource interface.
+ m_timeRep.setValue("value", m_timeValue);
+ m_timeRep.setUri(m_timeUri);
+ m_timeRep.setResourceTypes(m_timeTypes);
+ m_timeRep.setResourceInterfaces(m_timeInterfaces);
+ m_timeHandle = NULL;
+ }
+ ;
+
+ /// This function internally calls registerResource API.
+ void createResources(ResourceEntityHandler callback);
+
+ void setTimeRepresentation(OCRepresentation& rep);
+ void setCurrentTimeRepresentation(OCRepresentation& rep);
+
+ OCRepresentation getTimeRepresentation();
+ OCRepresentation getCurrentTimeRepresentation();
+
+ std::string getTimeUri();
+ std::string getCurrentTimeUri();
+
+ void factoryReset();
+
+};
+
+extern std::string defaultNetworkValue;
+extern std::string defaultIPAddressValue;
+
+class NetworkCollection
+{
+public:
+
+ // diagnostics members
+ std::string m_networkUri;
+ std::string m_networkValue;
+ std::vector< std::string > m_networkTypes;
+ std::vector< std::string > m_networkInterfaces;
+ OCResourceHandle m_networkHandle;
+ OCRepresentation m_networkRep;
+
+ // factory reset members
+ std::string m_IPAddressUri;
+ std::string m_IPAddressValue;
+ std::vector< std::string > m_IPAddressTypes;
+ std::vector< std::string > m_IPAddressInterfaces;
+ OCResourceHandle m_IPAddressHandle;
+ OCRepresentation m_IPAddressRep;
+
+public:
+
+ /// Constructor
+ NetworkCollection() :
+ m_networkValue(defaultNetworkValue), m_IPAddressValue(defaultIPAddressValue)
+ {
+ m_IPAddressUri = defaultURIPrefix + "/network/0/IPAddress"; // URI of the resource
+ m_IPAddressTypes.push_back("oic.con.network.IPAddress"); // resource type name.
+ m_IPAddressInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+
+ m_IPAddressRep.setUri(m_IPAddressUri);
+ m_IPAddressRep.setResourceTypes(m_IPAddressTypes);
+ m_IPAddressRep.setResourceInterfaces(m_IPAddressInterfaces);
+ m_IPAddressRep.setValue("value", m_IPAddressValue);
+ m_IPAddressHandle = NULL;
+
+ m_networkUri = defaultURIPrefix + "/network"; // URI of the resource
+ m_networkTypes.push_back("oic.con.network"); // resource type name.
+ m_networkInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+ m_networkInterfaces.push_back(BATCH_INTERFACE); // resource interface.
+ m_networkInterfaces.push_back(LINK_INTERFACE); // resource interface.
+ m_networkRep.setValue("value", m_networkValue);
+ m_networkRep.setUri(m_networkUri);
+ m_networkRep.setResourceTypes(m_networkTypes);
+ m_networkRep.setResourceInterfaces(m_networkInterfaces);
+ m_networkHandle = NULL;
+ }
+ ;
+
+ /// Constructor
+ NetworkCollection(std::string URIPrefix, std::string ResourceTypePrefix) :
+ m_networkValue(defaultNetworkValue), m_IPAddressValue(defaultIPAddressValue)
+ {
+ m_IPAddressUri = URIPrefix + "/network/0/IPAddress"; // URI of the resource
+ m_IPAddressTypes.push_back(ResourceTypePrefix + "network.IPAddress"); // resource type name.
+ m_IPAddressInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+
+ m_IPAddressRep.setUri(m_IPAddressUri);
+ m_IPAddressRep.setResourceTypes(m_IPAddressTypes);
+ m_IPAddressRep.setResourceInterfaces(m_IPAddressInterfaces);
+ m_IPAddressRep.setValue("value", m_IPAddressValue);
+ m_IPAddressHandle = NULL;
+
+ m_networkUri = URIPrefix + "/network"; // URI of the resource
+ m_networkTypes.push_back(ResourceTypePrefix + ".network"); // resource type name.
+ m_networkInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+ m_networkInterfaces.push_back(BATCH_INTERFACE); // resource interface.
+ m_networkInterfaces.push_back(LINK_INTERFACE); // resource interface.
+ m_networkRep.setValue("value", m_networkValue);
+ m_networkRep.setUri(m_networkUri);
+ m_networkRep.setResourceTypes(m_networkTypes);
+ m_networkRep.setResourceInterfaces(m_networkInterfaces);
+ m_networkHandle = NULL;
+ }
+ ;
+
+ /// This function internally calls registerResource API.
+ void createResources(ResourceEntityHandler callback);
+
+ void setNetworkRepresentation(OCRepresentation& rep);
+ void setIPAddressRepresentation(OCRepresentation& rep);
+
+ OCRepresentation getNetworkRepresentation();
+ OCRepresentation getIPAddressRepresentation();
+
+ std::string getNetworkUri();
+ std::string getIPAddressUri();
+
+ void factoryReset();
+
+};
+
+extern std::string defaultSecurityValue;
+extern std::string defaultModeValue;
+
+class SecurityCollection
+{
+public:
+
+ // diagnostics members
+ std::string m_securityUri;
+ std::string m_securityValue;
+ std::vector< std::string > m_securityTypes;
+ std::vector< std::string > m_securityInterfaces;
+ OCResourceHandle m_securityHandle;
+ OCRepresentation m_securityRep;
+
+ // factory reset members
+ std::string m_modeUri;
+ std::string m_modeValue;
+ std::vector< std::string > m_modeTypes;
+ std::vector< std::string > m_modeInterfaces;
+ OCResourceHandle m_modeHandle;
+ OCRepresentation m_modeRep;
+
+public:
+ /// Constructor
+ SecurityCollection() :
+ m_securityValue(defaultSecurityValue), m_modeValue(defaultModeValue)
+ {
+ m_modeUri = defaultURIPrefix + "/security/0/mode"; // URI of the resource
+ m_modeTypes.push_back("oic.con.security.mode"); // resource type name.
+ m_modeInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+
+ m_modeRep.setUri(m_modeUri);
+ m_modeRep.setResourceTypes(m_modeTypes);
+ m_modeRep.setResourceInterfaces(m_modeInterfaces);
+ m_modeRep.setValue("value", m_modeValue);
+ m_modeHandle = NULL;
+
+ m_securityUri = defaultURIPrefix + "/security"; // URI of the resource
+ m_securityTypes.push_back("oic.con.security"); // resource type name.
+ m_securityInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+ m_securityInterfaces.push_back(BATCH_INTERFACE); // resource interface.
+ m_securityInterfaces.push_back(LINK_INTERFACE); // resource interface.
+ m_securityRep.setValue("value", m_securityValue);
+ m_securityRep.setUri(m_securityUri);
+ m_securityRep.setResourceTypes(m_securityTypes);
+ m_securityRep.setResourceInterfaces(m_securityInterfaces);
+ m_securityHandle = NULL;
+ }
+ ;
+
+ /// Constructor
+ SecurityCollection(std::string URIPrefix, std::string ResourceTypePrefix) :
+ m_securityValue(defaultSecurityValue), m_modeValue(defaultModeValue)
+ {
+ m_modeUri = URIPrefix + "/security/0/mode"; // URI of the resource
+ m_modeTypes.push_back(ResourceTypePrefix + ".security.mode"); // resource type name.
+ m_modeInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+
+ m_modeRep.setUri(m_modeUri);
+ m_modeRep.setResourceTypes(m_modeTypes);
+ m_modeRep.setResourceInterfaces(m_modeInterfaces);
+ m_modeRep.setValue("value", m_modeValue);
+ m_modeHandle = NULL;
+
+ m_securityUri = URIPrefix + "/security"; // URI of the resource
+ m_securityTypes.push_back(ResourceTypePrefix + ".security"); // resource type name.
+ m_securityInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+ m_securityInterfaces.push_back(BATCH_INTERFACE); // resource interface.
+ m_securityInterfaces.push_back(LINK_INTERFACE); // resource interface.
+ m_securityRep.setValue("value", m_securityValue);
+ m_securityRep.setUri(m_securityUri);
+ m_securityRep.setResourceTypes(m_securityTypes);
+ m_securityRep.setResourceInterfaces(m_securityInterfaces);
+ m_securityHandle = NULL;
+ }
+ ;
+
+ /// This function internally calls registerResource API.
+ void createResources(ResourceEntityHandler callback);
+
+ void setSecurityRepresentation(OCRepresentation& rep);
+ void setModeRepresentation(OCRepresentation& rep);
+
+ OCRepresentation getSecurityRepresentation();
+ OCRepresentation getModeRepresentation();
+
+ std::string getSecurityUri();
+ std::string getModeUri();
+
+ void factoryReset();
+
+};
+
+extern std::string defaultConfigurationValue;
+extern std::string defaultRegionValue;
+static std::string defaultTimeLink = "/con/con/0/time";
+static std::string defaultNetworkLink = "/con/con/0/network";
+static std::string defaultSecurityLink = "/con/con/0/security";
+
+class ConfigurationCollection
+{
+public:
+ TimeCollection *myTimeCollection;
+ NetworkCollection *myNetworkCollection;
+ SecurityCollection *mySecurityCollection;
+
+public:
+ // Configuration members
+ std::string m_configurationUri;
+ std::string m_configurationValue;
+ std::vector< std::string > m_configurationTypes;
+ std::vector< std::string > m_configurationInterfaces;
+ OCResourceHandle m_configurationHandle;
+ OCRepresentation m_configurationRep;
+
+ // Security members
+ std::string m_regionUri;
+ std::string m_regionValue;
+ std::vector< std::string > m_regionTypes;
+ std::vector< std::string > m_regionInterfaces;
+ OCResourceHandle m_regionHandle;
+ OCRepresentation m_regionRep;
+
+ // Time members
+ std::string m_timeUri;
+ std::string m_timeLink;
+ std::vector< std::string > m_timeTypes;
+ std::vector< std::string > m_timeInterfaces;
+ OCResourceHandle m_timeHandle;
+ OCRepresentation m_timeRep;
+
+ // Network members
+ std::string m_networkUri;
+ std::string m_networkLink;
+ std::vector< std::string > m_networkTypes;
+ std::vector< std::string > m_networkInterfaces;
+ OCResourceHandle m_networkHandle;
+ OCRepresentation m_networkRep;
+
+ // Security members
+ std::string m_securityUri;
+ std::string m_securityLink;
+ std::vector< std::string > m_securityTypes;
+ std::vector< std::string > m_securityInterfaces;
+ OCResourceHandle m_securityHandle;
+ OCRepresentation m_securityRep;
+
+public:
+ /// Constructor
+ ConfigurationCollection() :
+ m_configurationValue(defaultConfigurationValue), m_regionValue(defaultRegionValue), m_timeLink(
+ defaultTimeLink), m_networkLink(defaultNetworkLink), m_securityLink(
+ defaultSecurityLink)
+ {
+ m_regionUri = defaultURIPrefix + "/0/region"; // URI of the resource
+ m_regionTypes.push_back(defaultResourceTypePrefix + ".region"); // resource type name.
+ m_regionInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+
+ m_regionRep.setUri(m_regionUri);
+ m_regionRep.setResourceTypes(m_regionTypes);
+ m_regionRep.setResourceInterfaces(m_regionInterfaces);
+ m_regionRep.setValue("value", m_regionValue);
+ m_regionHandle = NULL;
+
+ m_timeUri = defaultURIPrefix + "/0/time"; // URI of the resource
+ m_timeTypes.push_back(defaultResourceTypePrefix + ".time"); // resource type name.
+ m_timeInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+
+ m_timeRep.setUri(m_timeUri);
+ m_timeRep.setResourceTypes(m_timeTypes);
+ m_timeRep.setResourceInterfaces(m_timeInterfaces);
+ m_timeRep.setValue("link", m_timeLink);
+ m_timeHandle = NULL;
+
+ m_networkUri = defaultURIPrefix + "/0/net"; // URI of the resource
+ m_networkTypes.push_back(defaultResourceTypePrefix + ".net"); // resource type name.
+ m_networkInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+
+ m_networkRep.setUri(m_networkUri);
+ m_networkRep.setResourceTypes(m_networkTypes);
+ m_networkRep.setResourceInterfaces(m_networkInterfaces);
+ m_networkRep.setValue("link", m_networkLink);
+ m_networkHandle = NULL;
+
+ m_securityUri = defaultURIPrefix + "/0/sec"; // URI of the resource
+ m_securityTypes.push_back(defaultResourceTypePrefix + ".sec"); // resource type name.
+ m_securityInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+
+ m_securityRep.setUri(m_securityUri);
+ m_securityRep.setResourceTypes(m_securityTypes);
+ m_securityRep.setResourceInterfaces(m_securityInterfaces);
+ m_securityRep.setValue("link", m_securityLink);
+ m_securityHandle = NULL;
+
+ m_configurationUri = defaultURIPrefix + ""; // URI of the resource
+ m_configurationTypes.push_back(defaultResourceTypePrefix + ""); // resource type name.
+ m_configurationInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+ m_configurationInterfaces.push_back(BATCH_INTERFACE); // resource interface.
+ m_configurationInterfaces.push_back(LINK_INTERFACE); // resource interface.
+ m_configurationRep.setValue("value", m_configurationValue);
+ m_configurationRep.setUri(m_configurationUri);
+ m_configurationRep.setResourceTypes(m_configurationTypes);
+ m_configurationRep.setResourceInterfaces(m_configurationInterfaces);
+ m_configurationHandle = NULL;
+
+ myTimeCollection = new TimeCollection();
+ myNetworkCollection = new NetworkCollection();
+ mySecurityCollection = new SecurityCollection();
+ }
+ ;
+
+ /// Constructor
+ ConfigurationCollection(std::string URIPrefix, std::string ResourceTypePrefix) :
+ m_configurationValue(defaultConfigurationValue), m_regionValue(defaultRegionValue), m_timeLink(
+ defaultTimeLink), m_networkLink(defaultNetworkLink), m_securityLink(
+ defaultSecurityLink)
+ {
+ m_regionUri = URIPrefix + "/0/region"; // URI of the resource
+ m_regionTypes.push_back(ResourceTypePrefix + ".region"); // type name.
+ m_regionInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+
+ m_regionRep.setUri(m_regionUri);
+ m_regionRep.setResourceTypes(m_regionTypes);
+ m_regionRep.setResourceInterfaces(m_regionInterfaces);
+ m_regionRep.setValue("value", m_regionValue);
+ m_regionHandle = NULL;
+
+ m_timeUri = URIPrefix + "/0/time"; // URI of the resource
+ m_timeTypes.push_back(ResourceTypePrefix + ".time"); // resource type name.
+ m_timeInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+
+ m_timeRep.setUri(m_timeUri);
+ m_timeRep.setResourceTypes(m_timeTypes);
+ m_timeRep.setResourceInterfaces(m_timeInterfaces);
+ m_timeRep.setValue("link", m_timeLink);
+ m_timeHandle = NULL;
+
+ m_networkUri = URIPrefix + "/0/net"; // URI of the resource
+ m_networkTypes.push_back(ResourceTypePrefix + ".net"); // resource type name.
+ m_networkInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+
+ m_networkRep.setUri(m_networkUri);
+ m_networkRep.setResourceTypes(m_networkTypes);
+ m_networkRep.setResourceInterfaces(m_networkInterfaces);
+ m_networkRep.setValue("link", m_networkLink);
+ m_networkHandle = NULL;
+
+ m_securityUri = URIPrefix + "/0/sec"; // URI of the resource
+ m_securityTypes.push_back(ResourceTypePrefix + ".sec"); // resource type name.
+ m_securityInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+
+ m_securityRep.setUri(m_securityUri);
+ m_securityRep.setResourceTypes(m_securityTypes);
+ m_securityRep.setResourceInterfaces(m_securityInterfaces);
+ m_securityRep.setValue("link", m_securityLink);
+ m_securityHandle = NULL;
+
+ m_configurationUri = URIPrefix + ""; // URI of the resource
+ m_configurationTypes.push_back(ResourceTypePrefix + ""); // resource type name.
+ m_configurationInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+ m_configurationInterfaces.push_back(BATCH_INTERFACE); // resource interface.
+ m_configurationInterfaces.push_back(LINK_INTERFACE); // resource interface.
+ m_configurationRep.setValue("value", m_configurationValue);
+ m_configurationRep.setUri(m_configurationUri);
+ m_configurationRep.setResourceTypes(m_configurationTypes);
+ m_configurationRep.setResourceInterfaces(m_configurationInterfaces);
+ m_configurationHandle = NULL;
+
+ myTimeCollection = new TimeCollection(URIPrefix, ResourceTypePrefix);
+ myNetworkCollection = new NetworkCollection(URIPrefix, ResourceTypePrefix);
+ mySecurityCollection = new SecurityCollection(URIPrefix, ResourceTypePrefix);
+ }
+ ;
+
+ ~ConfigurationCollection()
+ {
+ free(myTimeCollection);
+ free(myNetworkCollection);
+ free(mySecurityCollection);
+ }
+
+ /// This function internally calls registerResource API.
+ void createResources(ResourceEntityHandler callback);
+
+ void setConfigurationRepresentation(OCRepresentation& rep);
+ void setTimeRepresentation(OCRepresentation& rep);
+ void setNetworkRepresentation(OCRepresentation& rep);
+ void setSecurityRepresentation(OCRepresentation& rep);
+ void setRegionRepresentation(OCRepresentation& rep);
+
+ OCRepresentation getTimeRepresentation();
+ OCRepresentation getNetworkRepresentation();
+ OCRepresentation getSecurityRepresentation();
+ OCRepresentation getRegionRepresentation();
+ OCRepresentation getConfigurationRepresentation();
+
+ std::string getConfigurationUri();
+ std::string getTimeUri();
+ std::string getNetworkUri();
+ std::string getSecurityUri();
+ std::string getRegionUri();
+
+ void factoryReset();
+
+};
--- /dev/null
+//******************************************************************
+//
+// 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 shows how one could create a resource (collection) with children.
+///
+
+#include <functional>
+#include <thread>
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "ThingsManager.h"
+#include "DiagnosticsCollection.h"
+
+using namespace OC;
+
+/// This function internally calls registerResource API.
+void DiagnosticsCollection::createResources(ResourceEntityHandler callback)
+{
+ using namespace OC::OCPlatform;
+
+ if (callback == NULL)
+ {
+ std::cout << "callback should be binded\t";
+ return;
+ }
+
+ // This will internally create and register the resource.
+ OCStackResult result = registerResource(m_diagnosticsHandle, m_diagnosticsUri,
+ m_diagnosticsTypes[0], m_diagnosticsInterfaces[0], callback,
+ OC_DISCOVERABLE | OC_OBSERVABLE);
+
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Resource creation (diagnostics) was unsuccessful\n";
+ }
+
+ result = bindInterfaceToResource(m_diagnosticsHandle, m_diagnosticsInterfaces[1]);
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Binding TypeName to Resource was unsuccessful\n";
+ }
+
+ result = bindInterfaceToResource(m_diagnosticsHandle, m_diagnosticsInterfaces[2]);
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Binding TypeName to Resource was unsuccessful\n";
+ }
+
+ result = registerResource(m_factoryResetHandle, m_factoryResetUri, m_factoryResetTypes[0],
+ m_factoryResetInterfaces[0], callback, OC_DISCOVERABLE | OC_OBSERVABLE);
+
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Resource creation (factoryReset) was unsuccessful\n";
+ }
+
+ result = registerResource(m_rebootHandle, m_rebootUri, m_rebootTypes[0], m_rebootInterfaces[0],
+ callback, OC_DISCOVERABLE | OC_OBSERVABLE);
+
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Resource creation (reboot) was unsuccessful\n";
+ }
+
+ result = registerResource(m_startCollectionHandle, m_startCollectionUri,
+ m_startCollectionTypes[0], m_startCollectionInterfaces[0], callback,
+ OC_DISCOVERABLE | OC_OBSERVABLE);
+
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Resource creation (startCollection) was unsuccessful\n";
+ }
+
+ result = bindResource(m_diagnosticsHandle, m_factoryResetHandle);
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Binding installedLocation resource to room was unsuccessful\n";
+ }
+
+ result = bindResource(m_diagnosticsHandle, m_rebootHandle);
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Binding time resource to room was unsuccessful\n";
+ }
+
+ result = bindResource(m_diagnosticsHandle, m_startCollectionHandle);
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Binding network resource to room was unsuccessful\n";
+ }
+
+ thread exec(
+ std::function< void(int second) >(
+ std::bind(&DiagnosticsCollection::diagnosticsMonitor, this,
+ std::placeholders::_1)), 10); // every 10 seconds
+ exec.detach();
+
+ std::cout << "Diagnostics Collection is Created!\n";
+}
+
+void DiagnosticsCollection::setDiagnosticsRepresentation(OCRepresentation& rep)
+{
+ string value;
+
+ if (rep.getValue("value", value))
+ {
+ m_diagnosticsValue = value;
+
+ std::cout << "\t\t\t\t" << "m_diagnosticsValue: " << m_diagnosticsValue << std::endl;
+ }
+}
+
+void DiagnosticsCollection::setFactoryResetRepresentation(OCRepresentation& rep)
+{
+ string value;
+
+ if (rep.getValue("value", value))
+ {
+ m_factoryResetValue = value;
+
+ std::cout << "\t\t\t\t" << "value: " << m_factoryResetValue << std::endl;
+ }
+}
+
+void DiagnosticsCollection::setRebootRepresentation(OCRepresentation& rep)
+{
+ string value;
+
+ if (rep.getValue("value", value))
+ {
+ m_rebootValue = value;
+
+ std::cout << "\t\t\t\t" << "value: " << m_rebootValue << std::endl;
+ }
+}
+
+void DiagnosticsCollection::setStartCollectionRepresentation(OCRepresentation& rep)
+{
+ string value;
+
+ if (rep.getValue("value", value))
+ {
+ m_startCollectionValue = value;
+
+ std::cout << "\t\t\t\t" << "value: " << m_startCollectionValue << std::endl;
+ }
+}
+
+OCRepresentation DiagnosticsCollection::getFactoryResetRepresentation()
+{
+ m_factoryResetRep.setValue("value", m_factoryResetValue);
+
+ return m_factoryResetRep;
+}
+
+OCRepresentation DiagnosticsCollection::getRebootRepresentation()
+{
+ m_rebootRep.setValue("value", m_rebootValue);
+
+ return m_rebootRep;
+}
+
+OCRepresentation DiagnosticsCollection::getStartCollectionRepresentation()
+{
+ m_startCollectionRep.setValue("value", m_startCollectionValue);
+
+ return m_startCollectionRep;
+}
+
+OCRepresentation DiagnosticsCollection::getDiagnosticsRepresentation()
+{
+ m_diagnosticsRep.clearChildren();
+
+ m_diagnosticsRep.addChild(getFactoryResetRepresentation());
+ m_diagnosticsRep.addChild(getRebootRepresentation());
+ m_diagnosticsRep.addChild(getStartCollectionRepresentation());
+
+ m_diagnosticsRep.setValue("value", m_diagnosticsValue);
+
+ return m_diagnosticsRep;
+}
+
+std::string DiagnosticsCollection::getDiagnosticsUri()
+{
+ return m_diagnosticsUri;
+}
+
+std::string DiagnosticsCollection::getFactoryResetUri()
+{
+ return m_factoryResetUri;
+}
+
+std::string DiagnosticsCollection::getRebootUri()
+{
+ return m_rebootUri;
+}
+
+std::string DiagnosticsCollection::getStartCollectionUri()
+{
+ return m_startCollectionUri;
+}
+
+void DiagnosticsCollection::diagnosticsMonitor(int second)
+{
+ while (1)
+ {
+ sleep(second);
+
+ if (m_rebootValue == "true")
+ {
+ int res;
+ std::cout << "Reboot will be soon..." << std::endl;
+ m_rebootValue = defaultReboot;
+ res = system("sudo reboot"); // System reboot
+
+ std::cout << "return: " << res << std::endl;
+
+ }
+ else if (m_factoryResetValue == "true")
+ {
+ std::cout << "Factory Reset will be soon..." << std::endl;
+ m_factoryResetValue = defaultFactoryReset;
+ factoryReset();
+ }
+ }
+}
--- /dev/null
+//******************************************************************
+//
+// 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 shows how one could create a resource (collection) with children.
+///
+
+#include <functional>
+#include <thread>
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "ThingsManager.h"
+
+#pragma once
+
+using namespace OC;
+
+typedef std::function< OCEntityHandlerResult(std::shared_ptr< OCResourceRequest > request) > ResourceEntityHandler;
+
+static std::string defaultDiagnosticsValue = "false";
+static std::string defaultFactoryReset = "false";
+static std::string defaultReboot = "false";
+static std::string defaultStartCollection = "false";
+
+class DiagnosticsCollection
+{
+public:
+
+ // diagnostics members
+ std::string m_diagnosticsUri;
+ std::string m_diagnosticsValue;
+ std::vector< std::string > m_diagnosticsTypes;
+ std::vector< std::string > m_diagnosticsInterfaces;
+ OCResourceHandle m_diagnosticsHandle;
+ OCRepresentation m_diagnosticsRep;
+
+ // factory reset members
+ std::string m_factoryResetUri;
+ std::string m_factoryResetValue;
+ std::vector< std::string > m_factoryResetTypes;
+ std::vector< std::string > m_factoryResetInterfaces;
+ OCResourceHandle m_factoryResetHandle;
+ OCRepresentation m_factoryResetRep;
+
+ // reboot members
+ std::string m_rebootUri;
+ std::string m_rebootValue;
+ std::vector< std::string > m_rebootTypes;
+ std::vector< std::string > m_rebootInterfaces;
+ OCResourceHandle m_rebootHandle;
+ OCRepresentation m_rebootRep;
+
+ // startcollection members
+ std::string m_startCollectionUri;
+ std::string m_startCollectionValue;
+ std::vector< std::string > m_startCollectionTypes;
+ std::vector< std::string > m_startCollectionInterfaces;
+ OCResourceHandle m_startCollectionHandle;
+ OCRepresentation m_startCollectionRep;
+
+public:
+ /// Constructor
+ DiagnosticsCollection() :
+ m_diagnosticsValue(defaultDiagnosticsValue), m_factoryResetValue(defaultFactoryReset), m_rebootValue(
+ defaultReboot), m_startCollectionValue(defaultStartCollection)
+ {
+ m_factoryResetUri = "/oic/diag/0/factoryReset"; // URI of the resource
+ m_factoryResetTypes.push_back("oic.diag.factoryReset"); // resource type name.
+ m_factoryResetInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+
+ m_factoryResetRep.setUri(m_factoryResetUri);
+ m_factoryResetRep.setResourceTypes(m_factoryResetTypes);
+ m_factoryResetRep.setResourceInterfaces(m_factoryResetInterfaces);
+ m_factoryResetRep.setValue("value", m_factoryResetValue);
+ m_factoryResetHandle = NULL;
+
+ m_rebootUri = "/oic/diag/0/reboot"; // URI of the resource
+ m_rebootTypes.push_back("oic.diag.reboot"); // resource type name.
+ m_rebootInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+
+ m_rebootRep.setUri(m_rebootUri);
+ m_rebootRep.setResourceTypes(m_rebootTypes);
+ m_rebootRep.setResourceInterfaces(m_rebootInterfaces);
+ m_rebootRep.setValue("value", m_rebootValue);
+ m_rebootHandle = NULL;
+
+ m_startCollectionUri = "/oic/diag/0/startCollection"; // URI of the resource
+ m_startCollectionTypes.push_back("oic.diag.startCollection"); // resource type name.
+ m_startCollectionInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+
+ m_startCollectionRep.setUri(m_startCollectionUri);
+ m_startCollectionRep.setResourceTypes(m_startCollectionTypes);
+ m_startCollectionRep.setResourceInterfaces(m_startCollectionInterfaces);
+ m_startCollectionRep.setValue("value", m_startCollectionValue);
+ m_startCollectionHandle = NULL;
+
+ m_diagnosticsUri = "/oic/diag"; // URI of the resource
+ m_diagnosticsTypes.push_back("oic.diag"); // resource type name.
+ m_diagnosticsInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+ m_diagnosticsInterfaces.push_back(BATCH_INTERFACE); // resource interface.
+ m_diagnosticsInterfaces.push_back(LINK_INTERFACE); // resource interface.
+ m_diagnosticsRep.setValue("value", m_diagnosticsValue);
+ m_diagnosticsRep.setUri(m_diagnosticsUri);
+ m_diagnosticsRep.setResourceTypes(m_diagnosticsTypes);
+ m_diagnosticsRep.setResourceInterfaces(m_diagnosticsInterfaces);
+ m_diagnosticsHandle = NULL;
+ }
+ ;
+
+ /// This function internally calls registerResource API.
+ void createResources(ResourceEntityHandler callback);
+
+ void setDiagnosticsRepresentation(OCRepresentation& rep);
+ void setFactoryResetRepresentation(OCRepresentation& rep);
+ void setRebootRepresentation(OCRepresentation& rep);
+ void setStartCollectionRepresentation(OCRepresentation& rep);
+
+ OCRepresentation getDiagnosticsRepresentation();
+ OCRepresentation getFactoryResetRepresentation();
+ OCRepresentation getRebootRepresentation();
+ OCRepresentation getStartCollectionRepresentation();
+
+ std::string getDiagnosticsUri();
+ std::string getFactoryResetUri();
+ std::string getRebootUri();
+ std::string getStartCollectionUri();
+
+ void diagnosticsMonitor(int second);
+
+ std::function< void() > factoryReset;
+};
+
--- /dev/null
+//******************************************************************
+//
+// 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 shows how one could create a resource (collection) with children.
+///
+
+#include <functional>
+#include <thread>
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "ThingsManager.h"
+#include "FactorySetCollection.h"
+
+using namespace OC;
+
+/// This function internally calls registerResource API.
+void FactorySetCollection::createResources(ResourceEntityHandler callback)
+{
+ using namespace OC::OCPlatform;
+
+ if (callback == NULL)
+ {
+ std::cout << "callback should be binded\t";
+ return;
+ }
+
+ // This will internally create and register the resource.
+ OCStackResult result = registerResource(m_factorySetHandle, m_factorySetUri,
+ m_factorySetTypes[0], m_factorySetInterfaces[0], callback,
+ OC_DISCOVERABLE | OC_OBSERVABLE);
+
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Resource creation (configuration) was unsuccessful\n";
+ }
+
+ result = bindInterfaceToResource(m_factorySetHandle, m_factorySetInterfaces[1]);
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Binding TypeName to Resource was unsuccessful\n";
+ }
+
+ result = bindInterfaceToResource(m_factorySetHandle, m_factorySetInterfaces[2]);
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Binding TypeName to Resource was unsuccessful\n";
+ }
+
+ result = registerResource(m_configurationCollectionHandle, m_configurationCollectionUri,
+ m_configurationCollectionTypes[0], m_configurationCollectionInterfaces[0], callback,
+ OC_DISCOVERABLE | OC_OBSERVABLE);
+
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Resource creation (installedLocation) was unsuccessful\n";
+ }
+
+ result = bindResource(m_factorySetHandle, m_configurationCollectionHandle);
+ if (OC_STACK_OK != result)
+ {
+ std::cout << "Binding installedLocation resource to room was unsuccessful\n";
+ }
+
+ defaultConfigurationCollection = new ConfigurationCollection(defaultConfigurationURIPrefix,
+ defaultConfigurationResourceTypePrefix);
+ //defaultConfigurationCollection->bindEntityHander(callback);
+ defaultConfigurationCollection->createResources(callback);
+
+ std::cout << "FactorySet Collection is Created!\n";
+}
+
+void FactorySetCollection::setFactorySetRepresentation(OCRepresentation& rep)
+{
+ string value;
+
+ if (rep.getValue("value", value))
+ {
+ m_factorySetValue = value;
+
+ std::cout << "\t\t\t\t" << "m_factorySetValue: " << m_factorySetValue << std::endl;
+ }
+}
+
+void FactorySetCollection::setConfigurationCollectionRepresentation(OCRepresentation& rep)
+{
+ string value;
+
+ if (rep.getValue("link", value))
+ {
+ // NOT ALLOWED
+
+ std::cout << "\t\t\t\t" << "link: " << m_configurationCollectionLink << std::endl;
+ }
+}
+
+OCRepresentation FactorySetCollection::getConfigurationCollectionRepresentation()
+{
+ m_configurationCollectionRep.setValue("link", m_configurationCollectionLink);
+
+ return m_configurationCollectionRep;
+}
+
+OCRepresentation FactorySetCollection::getFactorySetRepresentation()
+{
+ m_factorySetRep.clearChildren();
+
+ m_factorySetRep.addChild(getConfigurationCollectionRepresentation());
+
+ m_factorySetRep.setValue("value", m_factorySetValue);
+
+ return m_factorySetRep;
+}
+
+std::string FactorySetCollection::getFactorySetUri()
+{
+ return m_factorySetUri;
+}
+
+std::string FactorySetCollection::getConfigurationCollectionUri()
+{
+ return m_configurationCollectionUri;
+}
--- /dev/null
+//******************************************************************
+//
+// 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 shows how one could create a resource (collection) with children.
+///
+
+#include <functional>
+#include <thread>
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "ThingsManager.h"
+#include "ConfigurationCollection.h"
+
+#pragma once
+
+using namespace OC;
+
+typedef std::function< OCEntityHandlerResult(std::shared_ptr< OCResourceRequest > request) > ResourceEntityHandler;
+
+extern std::string defaultFactorySetValue;
+static std::string defaultConfigurationCollectionLink = "/factorySet/oic/con";
+
+static std::string defaultConfigurationURIPrefix = "/factorySet/oic/con";
+static std::string defaultConfigurationResourceTypePrefix = "factorySet.oic.con";
+
+class FactorySetCollection
+{
+public:
+
+ ConfigurationCollection *defaultConfigurationCollection;
+
+public:
+
+ // diagnostics members
+ std::string m_factorySetUri;
+ std::string m_factorySetValue;
+ std::vector< std::string > m_factorySetTypes;
+ std::vector< std::string > m_factorySetInterfaces;
+ OCResourceHandle m_factorySetHandle;
+ OCRepresentation m_factorySetRep;
+
+ // Configuration members
+ std::string m_configurationCollectionUri;
+ std::string m_configurationCollectionLink;
+ std::vector< std::string > m_configurationCollectionTypes;
+ std::vector< std::string > m_configurationCollectionInterfaces;
+ OCResourceHandle m_configurationCollectionHandle;
+ OCRepresentation m_configurationCollectionRep;
+
+public:
+ /// Constructor
+ FactorySetCollection() :
+ m_factorySetValue(defaultFactorySetValue), m_configurationCollectionLink(
+ defaultConfigurationCollectionLink)
+ {
+ m_configurationCollectionUri = "/factorySet/0/con"; // URI of the resource
+ m_configurationCollectionTypes.push_back("factorySet.con"); // resource type name.
+ m_configurationCollectionInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+
+ m_configurationCollectionRep.setUri(m_configurationCollectionUri);
+ m_configurationCollectionRep.setResourceTypes(m_configurationCollectionTypes);
+ m_configurationCollectionRep.setResourceInterfaces(m_configurationCollectionInterfaces);
+ m_configurationCollectionRep.setValue("link", m_configurationCollectionLink);
+ m_configurationCollectionHandle = NULL;
+
+ m_factorySetUri = "/factorySet"; // URI of the resource
+ m_factorySetTypes.push_back("factorySet"); // resource type name.
+ m_factorySetInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+ m_factorySetInterfaces.push_back(BATCH_INTERFACE); // resource interface.
+ m_factorySetInterfaces.push_back(LINK_INTERFACE); // resource interface.
+ m_factorySetRep.setValue("value", m_factorySetValue);
+ m_factorySetRep.setUri(m_factorySetUri);
+ m_factorySetRep.setResourceTypes(m_factorySetTypes);
+ m_factorySetRep.setResourceInterfaces(m_factorySetInterfaces);
+ m_factorySetHandle = NULL;
+
+ defaultConfigurationCollection = NULL;
+ }
+ ;
+
+ ~FactorySetCollection()
+ {
+ if (defaultConfigurationCollection != NULL)
+ free(defaultConfigurationCollection);
+ }
+ ;
+
+ /// This function internally calls registerResource API.
+ void createResources(ResourceEntityHandler callback);
+
+ void setFactorySetRepresentation(OCRepresentation& rep);
+ void setConfigurationCollectionRepresentation(OCRepresentation& rep);
+
+ OCRepresentation getFactorySetRepresentation();
+ OCRepresentation getConfigurationCollectionRepresentation();
+
+ std::string getFactorySetUri();
+ std::string getConfigurationCollectionUri();
+
+};
+
--- /dev/null
+##
+# linux sample app build script
+##
+
+Import('env')
+
+# Add third party libraries
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+linux_sample_env = lib_env.Clone()
+
+######################################################################
+# Build flags
+######################################################################
+linux_sample_env.AppendUnique(CPPPATH = ['include'])
+linux_sample_env.AppendUnique(CPPPATH = ['../../../sdk/inc'])
+linux_sample_env.AppendUnique(CPPPATH = ['../../../sdk/src'])
+linux_sample_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
+linux_sample_env.AppendUnique(CPPDEFINES = ['LINUX'])
+linux_sample_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+linux_sample_env.AppendUnique(LIBS = ['libTGMSDKLibrary', 'oc', 'octbstack', 'libcoap', 'liboc_logger', 'dl', 'pthread'])
+
+######################################################################
+#build sampleapp
+######################################################################
+conserver = linux_sample_env.Program('con-server', ['ConfigurationCollection.cpp', 'DiagnosticsCollection.cpp', 'FactorySetCollection.cpp', 'con-server.cpp'])
+conclient = linux_sample_env.Program('con-client', 'con-client.cpp')
+bootstrapserver = linux_sample_env.Program('bootstrapserver', 'bootstrapserver.cpp')
+Alias("ConServerApp", conserver)
+Alias("ConCleintApp", conclient)
+Alias("BootstrapServerApp", bootstrapserver)
+env.AppendTarget('ConServerApp')
+env.AppendTarget('ConClientApp')
+env.AppendTarget('BootstrapServerApp')
--- /dev/null
+//******************************************************************
+//
+// 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 shows how one could create a resource (collection) with children.
+///
+
+#include <functional>
+
+#include <pthread.h>
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+
+using namespace OC;
+using namespace std;
+
+// Forward declaring the entityHandler (bootstrap)
+bool prepareResponse(std::shared_ptr< OCResourceRequest > request);
+OCStackResult sendResponse(std::shared_ptr< OCResourceRequest > pRequest);
+OCEntityHandlerResult entityHandlerBootstrap(std::shared_ptr< OCResourceRequest > request);
+
+#define DefaultConfigurationValue "Configuration Collection"
+#define DefaultRegionValue "Seoul, Korea"
+#define DefaultTimeValue "Time Collection"
+#define DefaultCurrentTimeValue "00:00:00"
+#define DefaultNetworkValue "Network Collection"
+#define DefaultIPAddressValue "192.168.0.2"
+#define DefaultSecurityValue "SecurityValue"
+#define DefaultModeValue "NoSec"
+#define DefaultFactorySetValue "FactorySet Value"
+
+class BootstrapResource
+{
+public:
+ // Room members
+ std::string m_bootstrapUri;
+ std::vector< std::string > m_bootstrapTypes;
+ std::vector< std::string > m_bootstrapInterfaces;
+ OCResourceHandle m_bootstrapHandle;
+ OCRepresentation m_bootstrapRep;
+
+public:
+ /// Constructor
+ BootstrapResource()
+ {
+ m_bootstrapUri = "/bootstrap"; // URI of the resource
+ m_bootstrapTypes.push_back("bootstrap"); // resource type name. In this case, it is light
+ m_bootstrapInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+ m_bootstrapRep.setUri(m_bootstrapUri);
+ m_bootstrapRep.setResourceTypes(m_bootstrapTypes);
+ m_bootstrapRep.setResourceInterfaces(m_bootstrapInterfaces);
+ m_bootstrapHandle = NULL;
+ }
+
+ /// This function internally calls registerResource API.
+ void createResources()
+ {
+ using namespace OC::OCPlatform;
+ // This will internally create and register the resource.
+ OCStackResult result = registerResource(m_bootstrapHandle, m_bootstrapUri,
+ m_bootstrapTypes[0], m_bootstrapInterfaces[0], entityHandlerBootstrap,
+ OC_DISCOVERABLE | OC_OBSERVABLE);
+
+ if (OC_STACK_OK != result)
+ {
+ cout << "Resource creation (room) was unsuccessful\n";
+ }
+ }
+
+ void setBootstrapRepresentation(OCRepresentation& rep)
+ {
+ // Not allowed
+ }
+
+ OCRepresentation getBootstrapRepresentation()
+ {
+ m_bootstrapRep.setValue< std::string >("regionValue", DefaultRegionValue);
+ m_bootstrapRep.setValue< std::string >("timeValue", DefaultTimeValue);
+ m_bootstrapRep.setValue< std::string >("currentTimeValue", DefaultCurrentTimeValue);
+ m_bootstrapRep.setValue< std::string >("networkValue", DefaultNetworkValue);
+ m_bootstrapRep.setValue< std::string >("IPAddressValue", DefaultIPAddressValue);
+ m_bootstrapRep.setValue< std::string >("securityValue", DefaultSecurityValue);
+ m_bootstrapRep.setValue< std::string >("modeValue", DefaultModeValue);
+ m_bootstrapRep.setValue< std::string >("configurationValue", DefaultConfigurationValue);
+ m_bootstrapRep.setValue< std::string >("factorySetValue", DefaultFactorySetValue);
+
+ return m_bootstrapRep;
+ }
+};
+
+// Create the instance of the resource class (in this case instance of class 'RoomResource').
+BootstrapResource myBootstrapResource;
+
+// This function prepares a response for any incoming request to Light resource.
+bool prepareResponse(std::shared_ptr< OCResourceRequest > request)
+{
+ cout << "\tIn Server CPP prepareResponse:\n";
+ bool result = false;
+ if (request)
+ {
+ // Get the request type and request flag
+ std::string requestType = request->getRequestType();
+ int requestFlag = request->getRequestHandlerFlag();
+
+ if (requestFlag == RequestHandlerFlag::InitFlag)
+ {
+ cout << "\t\trequestFlag : Init\n";
+
+ // entity handler to perform resource initialization operations
+ }
+ else if (requestFlag == RequestHandlerFlag::RequestFlag)
+ {
+ cout << "\t\trequestFlag : Request\n";
+
+ // If the request type is GET
+ if (requestType == "GET")
+ {
+ cout << "\t\t\trequestType : GET\n";
+ // GET operations are directly handled while sending the response
+ // in the sendLightResponse function
+ result = true;
+ }
+ else if (requestType == "PUT")
+ {
+ cout << "\t\t\trequestType : PUT\n";
+
+ OCRepresentation rep = request->getResourceRepresentation();
+
+ // Do related operations related to PUT request
+ myBootstrapResource.setBootstrapRepresentation(rep);
+ result = true;
+ }
+ else if (requestType == "POST")
+ {
+ // POST request operations
+ }
+ else if (requestType == "DELETE")
+ {
+ // DELETE request operations
+ }
+ }
+ else if (requestFlag == RequestHandlerFlag::ObserverFlag)
+ {
+ cout << "\t\trequestFlag : Observer\n";
+ }
+ }
+ else
+ {
+ std::cout << "Request invalid" << std::endl;
+ }
+
+ return result;
+}
+
+OCStackResult sendResponse(std::shared_ptr< OCResourceRequest > pRequest)
+{
+ auto pResponse = std::make_shared< OC::OCResourceResponse >();
+ pResponse->setRequestHandle(pRequest->getRequestHandle());
+ pResponse->setResourceHandle(pRequest->getResourceHandle());
+ pResponse->setResourceRepresentation(myBootstrapResource.getBootstrapRepresentation());
+ pResponse->setErrorCode(200);
+ pResponse->setResponseResult(OC_EH_OK);
+
+ return OCPlatform::sendResponse(pResponse);
+}
+
+OCEntityHandlerResult entityHandlerBootstrap(std::shared_ptr< OCResourceRequest > request)
+{
+ cout << "\tIn Server CPP (entityHandlerBootstrap) entity handler:\n";
+ OCEntityHandlerResult ehResult = OC_EH_ERROR;
+
+ if (prepareResponse(request))
+ {
+ if (OC_STACK_OK == sendResponse(request))
+ {
+ ehResult = OC_EH_OK;
+ }
+ else
+ {
+ std::cout << "sendResponse failed." << std::endl;
+ }
+ }
+ else
+ {
+ std::cout << "PrepareResponse failed." << std::endl;
+ }
+ return ehResult;
+}
+
+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
+ {
+
+ myBootstrapResource.createResources();
+
+ // Perform app tasks
+ while (true)
+ {
+ // some tasks
+ }
+ }
+ catch (OCException e)
+ {
+ std::cout << "Exception in main: " << e.what();
+ }
+
+ // No explicit call to stop the platform.
+ // When OCPlatform destructor is invoked, internally we do platform cleanup
+}
+
--- /dev/null
+//******************************************************************
+//
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+// OCClient.cpp : Defines the entry point for the console application.
+//
+#include <string>
+#include <cstdlib>
+#include <pthread.h>
+#include <map>
+#include <vector>
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "ThingsManager.h"
+
+using namespace OC;
+using namespace OIC;
+
+int g_Steps = 0;
+int isWaiting = 0; //0: none to wait, 1: wait for the response of "getConfigurationValue"
+
+static ThingsManager* g_thingsmanager;
+
+OCResourceHandle configurationCollectionHandle;
+std::shared_ptr< OCResource > g_configurationCollection; // for a group of multiple resources
+std::shared_ptr< OCResource > g_configurationResource; // For a single resource
+
+OCResourceHandle diagnosticsCollectionHandle;
+std::shared_ptr< OCResource > g_diagnosticsCollection; // for a group of multiple resources
+std::shared_ptr< OCResource > g_diagnosticsResource; // For a single resource
+
+OCResourceHandle setCollectionHandle;
+std::shared_ptr< OCResource > g_setCollection; // for a group of multiple resources
+std::shared_ptr< OCResource > g_setResource; // For a single resource
+
+std::map< std::string, std::shared_ptr< OCResource > > resourceTable;
+std::vector< OCResourceHandle > resourceHandleVector;
+
+typedef std::function<
+ void(const HeaderOptions& headerOptions,
+ const OCRepresentation& rep, const int eCode) > ConfigurationCallback;
+typedef std::function<
+ void(const HeaderOptions& headerOptions,
+ const OCRepresentation& rep, const int eCode) > DiagnosticsCallback;
+
+typedef std::string ConfigurationName;
+typedef std::string ConfigurationValue;
+
+void onReboot(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+{
+ std::cout << "\tResource URI: " << rep.getUri() << std::endl;
+
+ std::cout << "\t\tReboot:" << rep.getValue< std::string >("value") << std::endl;
+
+ isWaiting = 0;
+}
+
+void onFactoryReset(const HeaderOptions& headerOptions, const OCRepresentation& rep,
+ const int eCode)
+{
+ std::cout << "\tResource URI: " << rep.getUri() << std::endl;
+
+ std::cout << "\t\tFactoryReset:" << rep.getValue< std::string >("value") << std::endl;
+ isWaiting = 0;
+}
+
+void onUpdate(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+{
+ std::cout << "\tResource URI: " << rep.getUri() << std::endl;
+
+ std::cout << "\t\tvalue:" << rep.getValue< std::string >("value") << std::endl;
+
+ isWaiting = 0;
+}
+
+void onGet(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+{
+ std::cout << "\tResource URI: " << rep.getUri() << std::endl;
+
+ if (rep.hasAttribute("value"))
+ std::cout << "\t\tvalue:" << rep.getValue< std::string >("value") << std::endl;
+ else if (rep.hasAttribute("link"))
+ std::cout << "\t\tlink:" << rep.getValue< std::string >("link") << std::endl;
+
+ std::vector< OCRepresentation > children = rep.getChildren();
+
+ for (auto oit = children.begin(); oit != children.end(); ++oit)
+ {
+ std::cout << "\t\tChild Resource URI: " << oit->getUri() << std::endl;
+
+ if (oit->hasAttribute("value"))
+ std::cout << "\t\tvalue:" << oit->getValue< std::string >("value") << std::endl;
+ else if (oit->hasAttribute("link"))
+ std::cout << "\t\tlink:" << oit->getValue< std::string >("link") << std::endl;
+ }
+
+ isWaiting = 0;
+}
+
+// Callback to found collection resource
+void onFoundCollectionResource(std::vector< std::shared_ptr< OCResource > > resources)
+{
+
+ std::string resourceURI;
+ std::string hostAddress;
+ try
+ {
+ // Do some operations with resource object.
+ for (unsigned int i = 0; i < resources.size(); ++i)
+ {
+ std::shared_ptr< OCResource > resource = resources.at(i);
+
+ if (resource)
+ {
+ if (resource->uri() == "/core/a/configuration/resourceset")
+ g_configurationCollection = resource;
+ else if (resource->uri() == "/core/a/diagnostics/resourceset")
+ g_diagnosticsCollection = resource;
+ else if (resource->uri() == "/core/a/factoryset/resourceset")
+ g_setCollection = resource;
+ else
+ {
+ isWaiting = 0;
+ return;
+ }
+ }
+ else
+ {
+ // Resource is invalid
+ std::cout << "Resource is invalid" << std::endl;
+ }
+ }
+
+ }
+ catch (std::exception& e)
+ {
+ //log(e.what());
+ }
+
+ if (g_configurationCollection != NULL && g_diagnosticsCollection != NULL
+ && g_setCollection != NULL)
+ isWaiting = 0;
+}
+
+// Callback to found resources
+void onFoundCandidateCollection(std::vector< std::shared_ptr< OCResource > > resources)
+{
+
+ std::string resourceURI;
+ std::string hostAddress;
+
+ static bool flagForCon = false, flagForDiag = false, flagForSet = false;
+
+ try
+ {
+ // Do some operations with resource object.
+ for (unsigned int i = 0; i < resources.size(); ++i)
+ {
+ std::shared_ptr< OCResource > resource = resources.at(i);
+
+ if (resource)
+ {
+ // Check if the resource is new one. If so, store it.
+
+ std::map< std::string, std::shared_ptr< OCResource > >::iterator iter =
+ resourceTable.find(resource->host() + resource->uri());
+
+ if (iter == resourceTable.end()) // new one
+ {
+ resourceTable[resource->host() + resource->uri()] = resource;
+
+ OCResourceHandle foundResourceHandle;
+ OCStackResult result = OCPlatform::registerResource(foundResourceHandle,
+ resource);
+ std::cout << "\tResource ( " << resource->host() << " ) is registed!\t"
+ << std::endl;
+ if (result == OC_STACK_OK)
+ {
+ if (resource->uri() == "/oic/con")
+ {
+ flagForCon = true;
+ OCPlatform::bindResource(configurationCollectionHandle,
+ foundResourceHandle);
+ if (g_configurationResource == NULL)
+ g_configurationResource = resource;
+ }
+ else if (resource->uri() == "/oic/diag")
+ {
+ flagForDiag = true;
+ OCPlatform::bindResource(diagnosticsCollectionHandle,
+ foundResourceHandle);
+ if (g_diagnosticsResource == NULL)
+ g_diagnosticsResource = resource;
+ }
+ else if (resource->uri() == "/factorySet")
+ {
+ flagForSet = true;
+ OCPlatform::bindResource(setCollectionHandle, foundResourceHandle);
+ if (g_setResource == NULL)
+ g_setResource = resource;
+ }
+
+ resourceHandleVector.push_back(foundResourceHandle);
+ }
+ else
+ {
+ cout << "\tresource Error!" << endl;
+ }
+
+ }
+
+ }
+ else
+ {
+ // Resource is invalid
+ std::cout << "Resource is invalid" << std::endl;
+ }
+ }
+
+ }
+ catch (std::exception& e)
+ {
+ //log(e.what());
+ }
+
+ if (flagForCon && flagForDiag && flagForSet)
+ isWaiting = 0;
+}
+
+int main(int argc, char* argv[])
+{
+
+ //**************************************************************
+ // STEP 0
+ PlatformConfig cfg
+ { OC::ServiceType::InProc, OC::ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos };
+
+ OCPlatform::Configure(cfg);
+ g_thingsmanager = new ThingsManager();
+
+ //**************************************************************
+
+ while (true)
+ {
+
+ if (isWaiting > 0)
+ continue;
+
+ isWaiting = 0;
+
+ cout << endl << endl << "(0) Quit" << std::endl;
+ cout << "(1) Find all resources(URI: /oic/con, /oic/diag, /factoryset)" << std::endl;
+ cout << "(2) Find all groups" << std::endl;
+ cout << "(3) Get a new value (of \"Configuration\" Collection)" << std::endl;
+ cout << "(4) Update a value (of \"Region\" Resource)" << std::endl;
+ cout << "(5) Get a value (for \"Region\" Resource)" << std::endl;
+ cout << "(6) FactoryReset (for the group)" << std::endl;
+ cout << "(7) Reboot (for the group)" << std::endl;
+ cout << "(10) Show Configuration Units" << std::endl;
+
+ cin >> g_Steps;
+ //
+ if (g_Steps == 0)
+ break;
+ else if (g_Steps == 1)
+ {
+ std::vector< std::string > types;
+ { // For Registering a collection resource for configuration resources
+
+ string resourceURI = "/core/a/configuration/resourceset";
+ string resourceTypeName = "core.configuration.resourceset";
+ string resourceInterface = BATCH_INTERFACE;
+
+ if (configurationCollectionHandle != NULL)
+ {
+ std::cout << "already exists" << std::endl;
+ continue;
+ }
+
+ OCPlatform::registerResource(configurationCollectionHandle, resourceURI,
+ resourceTypeName, resourceInterface, NULL,
+ //&entityHandler, // entityHandler
+ OC_DISCOVERABLE);
+
+ OCPlatform::bindInterfaceToResource(configurationCollectionHandle, GROUP_INTERFACE);
+ OCPlatform::bindInterfaceToResource(configurationCollectionHandle,
+ DEFAULT_INTERFACE);
+
+ // instead of registration
+ types.push_back("oic.con");
+ std::cout << "Finding Configuration Resource... " << std::endl;
+ }
+
+ { // For Registering a collection resource for diagnostics resources
+
+ string resourceURI = "/core/a/diagnostics/resourceset";
+ string resourceTypeName = "core.diagnostics.resourceset";
+ string resourceInterface = BATCH_INTERFACE;
+
+ if (diagnosticsCollectionHandle != NULL)
+ {
+ std::cout << "already exists" << std::endl;
+ continue;
+ }
+
+ OCPlatform::registerResource(diagnosticsCollectionHandle, resourceURI,
+ resourceTypeName, resourceInterface, NULL,
+ //&entityHandler, // entityHandler
+ OC_DISCOVERABLE);
+
+ OCPlatform::bindInterfaceToResource(diagnosticsCollectionHandle, GROUP_INTERFACE);
+ OCPlatform::bindInterfaceToResource(diagnosticsCollectionHandle, DEFAULT_INTERFACE);
+
+ // instead of registration
+ types.push_back("oic.diag");
+ std::cout << "Finding Diagnostics Resource... " << std::endl;
+
+ }
+
+ { // For Registering a collection resource for set resources
+
+ string resourceURI = "/core/a/factoryset/resourceset";
+ string resourceTypeName = "core.factoryset.resourceset";
+ string resourceInterface = BATCH_INTERFACE;
+
+ if (setCollectionHandle != NULL)
+ {
+ std::cout << "already exists" << std::endl;
+ continue;
+ }
+
+ OCPlatform::registerResource(setCollectionHandle, resourceURI, resourceTypeName,
+ resourceInterface, NULL,
+ //&entityHandler, // entityHandler
+ OC_DISCOVERABLE);
+
+ OCPlatform::bindInterfaceToResource(setCollectionHandle, GROUP_INTERFACE);
+ OCPlatform::bindInterfaceToResource(setCollectionHandle, DEFAULT_INTERFACE);
+
+ // instead of registration
+ types.push_back("factorySet");
+ std::cout << "Finding Set Resource... " << std::endl;
+ }
+
+ g_thingsmanager->findCandidateResources(types, &onFoundCandidateCollection, 5);
+
+ isWaiting = 1;
+ }
+ else if (g_Steps == 2) // make a group with found things
+ {
+ std::vector< std::string > types;
+ types.push_back("core.configuration.resourceset");
+ types.push_back("core.diagnostics.resourceset");
+ types.push_back("core.factoryset.resourceset");
+
+ g_thingsmanager->findCandidateResources(types, &onFoundCollectionResource, 5);
+
+ std::cout << "Finding Collection resource... " << std::endl;
+ isWaiting = 1;
+
+ }
+ else if (g_Steps == 3)
+ {
+ // get a value
+
+ ConfigurationName name = "configuration";
+
+ std::cout << "For example, get configuration collection's value" << std::endl;
+
+ std::vector< ConfigurationName > configurations;
+
+ configurations.push_back(name);
+
+ if (g_thingsmanager->getConfigurations(g_configurationResource, configurations, &onGet)
+ != OC_STACK_ERROR)
+ isWaiting = 1;
+ }
+ else if (g_Steps == 4)
+ {
+ ConfigurationName name = "region";
+ ConfigurationValue value = "U.S.A (new region)";
+
+ std::cout << "For example, change region resource's value" << std::endl;
+ std::cout << g_configurationCollection->uri() << std::endl;
+
+ std::map< ConfigurationName, ConfigurationValue > configurations;
+
+ configurations.insert(std::make_pair(name, value));
+
+ if (g_thingsmanager->updateConfigurations(g_configurationCollection, configurations,
+ &onUpdate) != OC_STACK_ERROR)
+ isWaiting = 1;
+ }
+ else if (g_Steps == 5)
+ {
+ // get a value
+
+ ConfigurationName name = "region";
+
+ std::cout << "For example, get region resource's value" << std::endl;
+
+ std::vector< ConfigurationName > configurations;
+
+ configurations.push_back(name);
+
+ if (g_thingsmanager->getConfigurations(g_configurationCollection, configurations,
+ &onGet) != OC_STACK_ERROR)
+ isWaiting = 1;
+ }
+ else if (g_Steps == 6)
+ {
+ // factory reset
+ if (g_thingsmanager->factoryReset(g_diagnosticsCollection, &onFactoryReset)
+ != OC_STACK_ERROR)
+ isWaiting = 1;
+ }
+ else if (g_Steps == 7)
+ {
+ // reboot
+ if (g_thingsmanager->reboot(g_diagnosticsCollection, &onReboot) != OC_STACK_ERROR)
+ isWaiting = 1;
+ }
+ else if (g_Steps == 10)
+ {
+ std::cout << g_thingsmanager->getListOfSupportedConfigurationUnits() << std::endl;
+
+ }
+
+ }
+
+ return 0;
+}
+
--- /dev/null
+//******************************************************************
+//
+// 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 shows how one could create a resource (collection) with children.
+///
+
+#include <functional>
+#include <thread>
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "ThingsManager.h"
+#include "ConfigurationCollection.h"
+#include "DiagnosticsCollection.h"
+#include "FactorySetCollection.h"
+
+using namespace OC;
+using namespace OIC;
+
+const int SUCCESS_RESPONSE = 0;
+int g_Steps = 0;
+int isWaiting = 0;
+
+// Default system configuration value's variables
+// The variable's names should be same as the names of "extern" variables defined in
+// "ConfigurationCollection.h"
+std::string defaultRegionValue;
+std::string defaultTimeValue;
+std::string defaultCurrentTimeValue;
+std::string defaultNetworkValue;
+std::string defaultIPAddressValue;
+std::string defaultSecurityValue;
+std::string defaultModeValue;
+std::string defaultConfigurationValue;
+std::string defaultFactorySetValue;
+
+static ThingsManager* g_thingsmanager;
+
+// Forward declaring the entityHandler (Configuration)
+bool prepareResponseForResource(std::shared_ptr< OCResourceRequest > request);
+OCStackResult sendResponseForResource(std::shared_ptr< OCResourceRequest > pRequest);
+OCEntityHandlerResult entityHandlerForResource(std::shared_ptr< OCResourceRequest > request);
+
+ConfigurationCollection *myConfigurationCollection;
+DiagnosticsCollection *myDiagnosticsCollection;
+FactorySetCollection *myFactorySetCollection;
+
+typedef std::function< void(OCRepresentation&) > putFunc;
+typedef std::function< OCRepresentation(void) > getFunc;
+
+getFunc getGetFunction(std::string uri)
+{
+ getFunc res = NULL;
+
+ if (uri == myConfigurationCollection->getTimeUri())
+ {
+ res = std::bind(&ConfigurationCollection::getTimeRepresentation, myConfigurationCollection);
+ }
+ else if (uri == myConfigurationCollection->getConfigurationUri())
+ {
+ res = std::bind(&ConfigurationCollection::getConfigurationRepresentation,
+ myConfigurationCollection);
+ }
+ else if (uri == myConfigurationCollection->myTimeCollection->getCurrentTimeUri())
+ {
+ res = std::bind(&TimeCollection::getCurrentTimeRepresentation,
+ myConfigurationCollection->myTimeCollection);
+ }
+ else if (uri == myConfigurationCollection->getRegionUri())
+ {
+ res = std::bind(&ConfigurationCollection::getRegionRepresentation,
+ myConfigurationCollection);
+ }
+ else if (uri == myDiagnosticsCollection->getFactoryResetUri())
+ {
+ res = std::bind(&DiagnosticsCollection::getFactoryResetRepresentation,
+ myDiagnosticsCollection);
+ }
+ else if (uri == myDiagnosticsCollection->getRebootUri())
+ {
+ res = std::bind(&DiagnosticsCollection::getRebootRepresentation, myDiagnosticsCollection);
+ }
+
+ return res;
+}
+
+putFunc getPutFunction(std::string uri)
+{
+ putFunc res = NULL;
+
+ if (uri == myConfigurationCollection->getRegionUri())
+ {
+ res = std::bind(&ConfigurationCollection::setRegionRepresentation,
+ myConfigurationCollection, std::placeholders::_1);
+ }
+ else if (uri == myConfigurationCollection->myTimeCollection->getCurrentTimeUri())
+ {
+ res = std::bind(&TimeCollection::setCurrentTimeRepresentation,
+ myConfigurationCollection->myTimeCollection, std::placeholders::_1);
+ }
+ else if (uri == myDiagnosticsCollection->getFactoryResetUri())
+ {
+ res = std::bind(&DiagnosticsCollection::setFactoryResetRepresentation,
+ myDiagnosticsCollection, std::placeholders::_1);
+ }
+ else if (uri == myDiagnosticsCollection->getRebootUri())
+ {
+ res = std::bind(&DiagnosticsCollection::setRebootRepresentation, myDiagnosticsCollection,
+ std::placeholders::_1);
+ }
+
+ return res;
+}
+
+// This function prepares a response for any incoming request to Light resource.
+bool prepareResponseForResource(std::shared_ptr< OCResourceRequest > request)
+{
+ std::cout << "\tIn Server CPP prepareResponseForResource:\n";
+ bool result = false;
+ if (request)
+ {
+ // Get the request type and request flag
+ std::string requestType = request->getRequestType();
+ int requestFlag = request->getRequestHandlerFlag();
+
+ if (requestFlag == RequestHandlerFlag::InitFlag)
+ {
+ std::cout << "\t\trequestFlag : Init\n";
+
+ // entity handler to perform resource initialization operations
+ }
+ else if (requestFlag == RequestHandlerFlag::RequestFlag)
+ {
+ std::cout << "\t\trequestFlag : Request\n";
+
+ // If the request type is GET
+ if (requestType == "GET")
+ {
+ std::cout << "\t\t\trequestType : GET\n";
+ // GET operations are directly handled while sending the response
+ // in the sendLightResponse function
+ result = true;
+ }
+ else if (requestType == "PUT")
+ {
+ std::cout << "\t\t\trequestType : PUT\n";
+ putFunc putFunction;
+ OCRepresentation rep = request->getResourceRepresentation();
+
+ putFunction = getPutFunction(request->getResourceUri());
+
+ // Do related operations related to PUT request
+ putFunction(rep);
+ result = true;
+ }
+ else if (requestType == "POST")
+ {
+ // POST request operations
+ }
+ else if (requestType == "DELETE")
+ {
+ // DELETE request operations
+ }
+ }
+ else if (requestFlag == RequestHandlerFlag::ObserverFlag)
+ {
+ std::cout << "\t\trequestFlag : Observer\n";
+ }
+ }
+ else
+ {
+ std::cout << "Request invalid" << std::endl;
+ }
+
+ return result;
+}
+
+OCStackResult sendResponseForResource(std::shared_ptr< OCResourceRequest > pRequest)
+{
+ auto pResponse = std::make_shared< OC::OCResourceResponse >();
+
+ // Check for query params (if any)
+ QueryParamsMap queryParamsMap = pRequest->getQueryParameters();
+
+ pResponse->setRequestHandle(pRequest->getRequestHandle());
+ pResponse->setResourceHandle(pRequest->getResourceHandle());
+
+ getFunc getFunction;
+ getFunction = getGetFunction(pRequest->getResourceUri());
+
+ OCRepresentation rep;
+ rep = getFunction();
+
+ auto findRes = queryParamsMap.find("if");
+
+ if (findRes != queryParamsMap.end())
+ {
+ pResponse->setResourceRepresentation(rep, findRes->second);
+ }
+ else
+ {
+ pResponse->setResourceRepresentation(rep, DEFAULT_INTERFACE);
+ }
+
+ pResponse->setErrorCode(200);
+ pResponse->setResponseResult(OC_EH_OK);
+
+ return OCPlatform::sendResponse(pResponse);
+}
+
+OCEntityHandlerResult entityHandlerForResource(std::shared_ptr< OCResourceRequest > request)
+{
+ std::cout << "\tIn Server CPP (entityHandlerForResource) entity handler:\n";
+ OCEntityHandlerResult ehResult = OC_EH_ERROR;
+
+ if (prepareResponseForResource(request))
+ {
+ if (OC_STACK_OK == sendResponseForResource(request))
+ {
+ ehResult = OC_EH_OK;
+ }
+ else
+ {
+ std::cout << "sendResponse failed." << std::endl;
+ }
+ }
+ else
+ {
+ std::cout << "PrepareResponse failed." << std::endl;
+ }
+ return ehResult;
+}
+
+// callback handler on GET request
+void onBootstrap(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+{
+ if (eCode == SUCCESS_RESPONSE)
+ {
+ std::cout << "\n\nGET request was successful" << std::endl;
+ std::cout << "\tResource URI: " << rep.getUri() << std::endl;
+
+ defaultRegionValue = rep.getValue< std::string >("regionValue");
+ defaultTimeValue = rep.getValue< std::string >("timeValue");
+ defaultCurrentTimeValue = rep.getValue< std::string >("currentTimeValue");
+ defaultNetworkValue = rep.getValue< std::string >("networkValue");
+ defaultIPAddressValue = rep.getValue< std::string >("IPAddressValue");
+ defaultSecurityValue = rep.getValue< std::string >("securityValue");
+ defaultModeValue = rep.getValue< std::string >("modeValue");
+ defaultConfigurationValue = rep.getValue< std::string >("configurationValue");
+ defaultFactorySetValue = rep.getValue< std::string >("factorySetValue");
+
+ std::cout << "\tregionValue : " << defaultRegionValue << std::endl;
+ std::cout << "\ttimeValue : " << defaultTimeValue << std::endl;
+ std::cout << "\tcurrentTimeValue : " << defaultCurrentTimeValue << std::endl;
+ std::cout << "\tnetworkValue : " << defaultNetworkValue << std::endl;
+ std::cout << "\tIPAddressValue : " << defaultIPAddressValue << std::endl;
+ std::cout << "\tsecurityValue : " << defaultSecurityValue << std::endl;
+ std::cout << "\tmodeValue : " << defaultModeValue << std::endl;
+ std::cout << "\tconfigurationValue : " << defaultConfigurationValue << std::endl;
+ std::cout << "\tfactorySetValue : " << defaultFactorySetValue << std::endl;
+
+ }
+ else
+ {
+ std::cout << "onGET Response error: " << eCode << std::endl;
+ std::exit(-1);
+ }
+ isWaiting = 0;
+}
+
+int main()
+{
+ //**************************************************************
+ // STEP 0
+ // Create PlatformConfig object
+ PlatformConfig cfg
+ { OC::ServiceType::InProc, OC::ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos };
+
+ OCPlatform::Configure(cfg);
+ g_thingsmanager = new ThingsManager();
+ //**************************************************************
+
+ if (getuid() != 0)
+ {
+ std::cout << "NOTE: You may gain the root privilege (e.g, reboot)\n";
+ std::cout << "NOTE: Now, you don't have it.\n";
+ }
+
+ try
+ {
+ // Perform app tasks
+ while (true)
+ {
+
+ if (isWaiting > 0)
+ continue;
+
+ isWaiting = 0;
+
+ std::cout << endl << endl << "(0) Quit" << std::endl;
+ std::cout << "(1) Bootstrap" << std::endl;
+ std::cout << "(2) Create Configuration Resources" << std::endl;
+
+ cin >> g_Steps;
+ //
+ if (g_Steps == 0)
+ break;
+ else if (g_Steps == 1)
+ {
+ g_thingsmanager->doBootstrap(&onBootstrap);
+ isWaiting = 1;
+ }
+ else if (g_Steps == 2)
+ {
+ myConfigurationCollection = new ConfigurationCollection();
+ myConfigurationCollection->createResources(&entityHandlerForResource);
+
+ myDiagnosticsCollection = new DiagnosticsCollection();
+ myDiagnosticsCollection->createResources(&entityHandlerForResource);
+
+ myFactorySetCollection = new FactorySetCollection();
+ myFactorySetCollection->createResources(&entityHandlerForResource);
+ myDiagnosticsCollection->factoryReset = std::function < void()
+ > (std::bind(&ConfigurationCollection::factoryReset,
+ myConfigurationCollection));
+ isWaiting = 1;
+ }
+ }
+ }
+ catch (OCException e)
+ {
+ std::cout << "Exception in main: " << e.what();
+ }
+
+ // No explicit call to stop the platform.
+ // When OCPlatform destructor is invoked, internally we do platform cleanup
+}
+
--- /dev/null
+TGMROOT=../../../
+IOT_BASE=${TGMROOT}../../resource
+RST_NAME=.
+TARGET1=con-server
+TARGET2=con-client
+TARGET3=bootstrapserver
+
+OBJS = ConfigurationCollection.o DiagnosticsCollection.o FactorySetCollection.o con-server.o
+SRCS = $(OBJS:.o=.c)
+
+# C++ type Compile Flag define.
+CXX=g++
+CXX_FLAGS=-std=c++0x -Wall -pthread -DLINUX -ldl
+
+CXX_INC := -I../../ -I../../inc/ -I../../../sdk/inc/ -I../../../sdk/src/
+CXX_INC += -I${IOT_BASE}/include/
+CXX_INC += -I${IOT_BASE}/oc_logger/include
+CXX_INC += -I${IOT_BASE}/csdk/stack/include
+CXX_INC += -I${IOT_BASE}/csdk/ocsocket/include
+CXX_INC += -I${IOT_BASE}/csdk/ocrandom/include
+CXX_INC += -I${IOT_BASE}/csdk/logger/include
+CXX_INC += -I${IOT_BASE}/dependencies/cereal/include
+
+CXX_LIB=-L""
+
+CXX_SRCPATH=${wildcard ../../src/*.cpp}
+CXX_SRCLIST=${notdir ${CXX_SRCPATH}}
+CXX_USESRCS=${filter-out ${EXCLUDE_LIST}, ${CXX_SRCLIST}}
+CXX_OBJLIST=${CXX_USESRCS:.cpp=.o}
+
+
+TGM = ../../
+SDK = ${TGMROOT}sdk
+TGM_INC = -I${TGMROOT}sdk/inc
+SDK_LIB = ${TGMROOT}sdk/build/linux/libTGMSDKLibrary.a
+
+LIB_OC_LOGGER := $(IOT_BASE)/oc_logger/lib/oc_logger.a
+
+LD_LIB := $(IOT_BASE)/release/obj/liboc.a
+LD_LIB += $(IOT_BASE)/csdk/linux/release/liboctbstack.a
+LD_LIB += $(LIB_OC_LOGGER)
+
+
+# Force metatargets to build:
+.PHONY: all clean
+
+all: ${TARGET1} ${TARGET2} ${TARGET3}
+
+.cpp.o:
+ $(CXX) $(CXX_FLAGS) -c -o $@ $< $(CXX_INC) $(TGM_INC)
+
+$(TARGET1): $(OBJS)
+ $(CXX) $(CXX_FLAGS) -o $@ ${OBJS} $(CXX_INC) ${LD_LIB} $(TGM_INC) $(SDK_LIB)
+
+${TARGET2}: con-client.cpp
+ $(CXX) $(CXX_FLAGS) -o ${TARGET2} $< $(CXX_INC) ${LD_LIB} $(TGM_INC) $(SDK_LIB)
+
+${TARGET3}: bootstrapserver.cpp
+ $(CXX) $(CXX_FLAGS) -o ${TARGET3} $< $(CXX_INC) ${LD_LIB} $(TGM_INC) $(SDK_LIB)
+
+
+dep:
+ gccmakedep $(SRCS)
+
+clean:
+ rm -f -v *.o con-client
+ rm -f -v *.o con-server
+ rm -f -v *.o bootstrapserver
+
+#dep:
+# gccmakedep $(SRCS)
--- /dev/null
+##
+# linux sample app build script
+##
+
+Import('env')
+
+# Add third party libraries
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+linux_sample_env = lib_env.Clone()
+
+######################################################################
+# Build flags
+######################################################################
+linux_sample_env.AppendUnique(CPPPATH = ['include'])
+linux_sample_env.AppendUnique(CPPPATH = ['../../../sdk/inc'])
+linux_sample_env.AppendUnique(CPPPATH = ['../../../sdk/src'])
+linux_sample_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
+linux_sample_env.AppendUnique(CPPDEFINES = ['LINUX'])
+linux_sample_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+linux_sample_env.AppendUnique(LIBS = ['libTGMSDKLibrary', 'oc', 'octbstack', 'libcoap', 'liboc_logger', 'dl', 'pthread'])
+
+
+######################################################################
+#build sampleapp
+######################################################################
+groupserver = linux_sample_env.Program('groupserver', 'groupserver.cpp')
+lightserver = linux_sample_env.Program('lightserver', 'lightserver.cpp')
+bookmark = linux_sample_env.Program('bookmark', 'bookmark.cpp')
+Alias("GroupServerApp", groupserver)
+Alias("LightServerApp", lightserver)
+Alias("BookmarkApp", bookmark)
+env.AppendTarget('GroupServerApp')
+env.AppendTarget('LightServerApp')
+env.AppendTarget('BookmarkApp')
--- /dev/null
+//******************************************************************
+//
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include <functional>
+#include <pthread.h>
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+
+using namespace OC;
+using namespace std;
+
+namespace PH = std::placeholders;
+
+unsigned int startedThread;
+unsigned int gObservation;
+pthread_t threadId;
+
+void* ObserveHandler(void *param);
+
+class BookmarkResource
+{
+
+private:
+ OCEntityHandlerResult entityHandler(std::shared_ptr< OCResourceRequest > request)
+ {
+ 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::InitFlag)
+ {
+ cout << "\t\trequestFlag : Init\n";
+
+ // entity handler to perform resource initialization operations
+ }
+ else if (requestFlag & RequestHandlerFlag::RequestFlag)
+ {
+ auto pResponse = std::make_shared< OC::OCResourceResponse >();
+ pResponse->setRequestHandle(request->getRequestHandle());
+ pResponse->setResourceHandle(request->getResourceHandle());
+
+ // If the request type is GET
+ if (requestType == "GET")
+ {
+ }
+ else if (requestType == "PUT")
+ {
+ cout << "\t\t\trequestType : PUT\n";
+ }
+ else if (requestType == "POST")
+ {
+ // POST request operations
+ }
+ else if (requestType == "DELETE")
+ {
+ // DELETE request operations
+ }
+
+ pResponse->setErrorCode(200);
+ pResponse->setResponseResult(OC_EH_OK);
+ pResponse->setResourceRepresentation(getRepresentation());
+ if (OC_STACK_OK == OCPlatform::sendResponse(pResponse))
+ {
+ ehResult = OC_EH_OK;
+ }
+ }
+
+ if (requestFlag & RequestHandlerFlag::ObserverFlag)
+ {
+ cout << "\t\trequestFlag : Observer\n";
+
+ if (!startedThread)
+ {
+ pthread_create(&threadId, NULL, ObserveHandler, (void *) NULL);
+ startedThread = 1;
+ gObservation = 1;
+ }
+
+ ehResult = OC_EH_OK;
+ }
+ }
+ else
+ {
+ std::cout << "Request invalid" << std::endl;
+ }
+
+ return ehResult;
+ }
+
+public:
+ /// Constructor
+ BookmarkResource()
+ {
+ m_pressure = 0;
+
+ m_BookmarkUri = "/core/bookmark"; // URI of the resource
+ m_BookmarkType = "core.bookmark"; // resource type name. In this case, it is light
+
+ m_BookmarkInterface = DEFAULT_INTERFACE; // resource interface.
+ m_BookmarkHandle = 0;
+ }
+
+ /// This function internally calls registerResource API.
+ void createResources()
+ {
+ EntityHandler cb = std::bind(&BookmarkResource::entityHandler, this, PH::_1);
+
+ // This will internally create and register the resource.
+ OCStackResult result = OC::OCPlatform::registerResource(m_BookmarkHandle, m_BookmarkUri,
+ m_BookmarkType, m_BookmarkInterface, cb, OC_DISCOVERABLE | OC_OBSERVABLE);
+
+ if (OC_STACK_OK != result)
+ {
+ cout << "Resource creation (bookmark) was unsuccessful\n";
+ }
+ else
+ {
+ cout << "Resource URI : " << m_BookmarkUri << endl;
+ cout << "\tResource Type Name : " << m_BookmarkType << endl;
+ cout << "\tResource Interface : " << DEFAULT_INTERFACE << endl;
+ cout << "\tResource creation is successful with resource handle : " << m_BookmarkHandle
+ << endl;
+ }
+ }
+
+ void setRepresentation(OCRepresentation& rep)
+ {
+ // AttributeMap attributeMap = rep.getAttributeMap();
+ // if(rep.getValue("level", m_pressure) == true)
+ {
+ std::cout << m_pressure << endl;
+ }
+ }
+
+ OCRepresentation getRepresentation()
+ {
+ OCRepresentation rep;
+
+ rep.setValue("level", (int) m_pressure);
+
+ return rep;
+ }
+
+public:
+ // Members of Bookmark
+ std::string m_BookmarkUri;
+ std::string m_BookmarkType;
+ std::string m_BookmarkInterface;
+ unsigned int m_pressure;
+ OCResourceHandle m_BookmarkHandle;
+};
+
+// Create the instance of the resource class (in this case instance of class 'BookmarkResource').
+BookmarkResource myBookmarkResource;
+
+void* ObserveHandler(void *param)
+{
+ while (startedThread)
+ {
+ sleep(1);
+
+ cout << "input a integer(0:opened, 5:close) : ";
+ cin >> myBookmarkResource.m_pressure;
+
+ if (myBookmarkResource.m_pressure == 0 || // When your book opened.
+ myBookmarkResource.m_pressure == 5) // When your book closed.
+ {
+ cout << "notifyObservers call!" << endl;
+
+ OCStackResult result = OCPlatform::notifyAllObservers(
+ myBookmarkResource.m_BookmarkHandle);
+
+ if (OC_STACK_NO_OBSERVERS == result)
+ {
+ cout << "No More observers, stopping notifications" << endl;
+ gObservation = 0;
+ startedThread = 0;
+ }
+ }
+ }
+
+ return NULL;
+}
+
+int main()
+{
+ // Create PlatformConfig object
+
+ OC::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 };
+
+ // Create a OCPlatform instance.
+ // Note: Platform creation is synchronous call.
+ try
+ {
+
+ // Invoke createResource function of class bookmark.
+ myBookmarkResource.createResources();
+
+ // Perform app tasks
+ while (true)
+ {
+ // some tasks
+ }
+ }
+ catch (OCException e)
+ {
+ std::cout << "Exception in main: " << e.what();
+ }
+}
--- /dev/null
+//******************************************************************
+//
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include <OCPlatform.h>
+#include <OCApi.h>
+
+#include <functional>
+#include <pthread.h>
+#include <iostream>
+
+#include <ThingsManager.h>
+
+using namespace std;
+using namespace OC;
+using namespace OIC;
+namespace PH = std::placeholders;
+
+bool isReady = false;
+
+OCResourceHandle resourceHandle;
+std::vector< OCResourceHandle > resourceHandleVector;
+
+shared_ptr< OCResource > g_resource;
+vector< string > lights;
+
+ThingsManager *thingsMgr = new ThingsManager();
+
+void onGet(const HeaderOptions& opt, const OCRepresentation &rep, const int eCode);
+
+void onPut(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode);
+
+void onPost(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode);
+
+void onObserve(const HeaderOptions headerOptions, const OCRepresentation& rep, const int& eCode,
+ const int& sequenceNumber);
+
+void allBulbOn();
+void allBulbOff();
+
+void foundResources(std::vector< std::shared_ptr< OC::OCResource > > listOfResource)
+{
+
+ for (auto rsrc = listOfResource.begin(); rsrc != listOfResource.end(); ++rsrc)
+ {
+ std::string resourceURI = (*rsrc)->uri();
+ std::string hostAddress = (*rsrc)->host();
+
+ if (resourceURI == "/a/light")
+ {
+
+ cout << "\tResource URI : " << resourceURI << endl;
+ cout << "\tResource Host : " << hostAddress << endl;
+
+ OCResourceHandle foundResourceHandle;
+ OCStackResult result = OCPlatform::registerResource(foundResourceHandle, (*rsrc));
+ cout << "\tresource registed!" << endl;
+ if (result == OC_STACK_OK)
+ {
+ OCPlatform::bindResource(resourceHandle, foundResourceHandle);
+ resourceHandleVector.push_back(foundResourceHandle);
+ }
+ else
+ {
+ cout << "\tresource Error!" << endl;
+ }
+
+ lights.push_back((hostAddress + resourceURI));
+ }
+ }
+
+ isReady = true;
+}
+
+void foundResource(std::shared_ptr< OCResource > resource)
+{
+ std::string resourceURI;
+ std::string hostAddress;
+
+ try
+ {
+ cout << "FOUND RESOURCE" << endl;
+
+ if (resource)
+ {
+ resourceURI = resource->uri();
+ hostAddress = resource->host();
+ if (resourceURI == "/core/a/collection")
+ {
+ g_resource = resource;
+
+ // g_resource->get("", DEFAULT_INTERFACE, QueryParamsMap(), onGet);
+
+ printf("\tHOST :: %s\n", resource->host().c_str());
+ }
+ else if (resourceURI == "/core/bookmark")
+ {
+ resource->observe(ObserveType::Observe, QueryParamsMap(), &onObserve);
+ }
+
+ // p_platform.bindResource(resourceHandle, foundResourceHandle);
+
+ }
+ }
+ catch (std::exception& e)
+ {
+ std::cout << "" << std::endl;
+ }
+}
+
+void onGet(const HeaderOptions& opt, const OCRepresentation &rep, const int eCode)
+{
+ // std::vector<OCRepresentation> children = rep.getChildren();
+
+ // cout << "\n\n\nCHILD RESOURCE OF GROUP" << endl;
+ // for( auto iter = children.begin(); iter != children.end(); ++iter )
+ // {
+ // lights.push_back((*iter).getUri());
+ // cout << "\tURI :: " << (*iter).getUri() << endl;
+ // }
+}
+
+void onPut(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+{
+ printf("\nonPut\n");
+}
+
+void onPost(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+{
+ printf("\nonPost\n");
+
+ if (rep.hasAttribute("ActionSet"))
+ {
+ std::string plainText;
+
+ if (rep.getValue("ActionSet", plainText))
+ {
+ ActionSet *actionset = thingsMgr->getActionSetfromString(plainText);
+ if (actionset != NULL)
+ {
+ cout << endl << "\tACTIONSET NAME :: " << actionset->actionsetName << endl;
+ for (auto actIter = actionset->listOfAction.begin();
+ actIter != actionset->listOfAction.end(); ++actIter)
+ {
+ cout << "\t\tTARGET :: " << (*actIter)->target << endl;
+
+ for (auto capaIter = (*actIter)->listOfCapability.begin();
+ capaIter != (*actIter)->listOfCapability.end(); ++capaIter)
+ {
+ cout << "\t\t\t" << (*capaIter)->capability << " :: " << (*capaIter)->status
+ << endl;
+ }
+ }
+ }
+ delete actionset;
+ }
+
+ // printf( "\tPlain Text :: %s\n", plainText.c_str() );
+ }
+ else if (rep.hasAttribute("DoAction"))
+ {
+ std::string plainText;
+ if (rep.getValue("DoAction", plainText))
+ {
+ cout << "\t" << plainText << endl;
+ }
+ }
+ else
+ {
+
+ }
+}
+
+void allBulbOff()
+{
+ OCRepresentation rep;
+
+ rep.setValue("DoAction", std::string("AllBulbOff"));
+
+ if (g_resource)
+ {
+ g_resource->post("a.collection", GROUP_INTERFACE, rep, QueryParamsMap(), &onPost);
+ }
+}
+
+void allBulbOn()
+{
+ OCRepresentation rep;
+
+ rep.setValue("DoAction", std::string("AllBulbOn"));
+
+ if (g_resource)
+ {
+ g_resource->post("a.collection", GROUP_INTERFACE, rep, QueryParamsMap(), &onPost);
+ }
+}
+
+void onObserve(const HeaderOptions headerOptions, const OCRepresentation& rep, const int& eCode,
+ const int& sequenceNumber)
+{
+ if (eCode == OC_STACK_OK)
+ {
+ int level;
+
+ std::cout << "OBSERVE RESULT:" << std::endl;
+ std::cout << "\tSequenceNumber: " << sequenceNumber << endl;
+
+ if (rep.getValue("level", level))
+ {
+ if (level == 0)
+ {
+ allBulbOn();
+ }
+ else
+ {
+ allBulbOff();
+ }
+ }
+ std::cout << "\tlevel: " << level << std::endl;
+ }
+ else
+ {
+ std::cout << "onObserve Response error: " << eCode << std::endl;
+ std::exit(-1);
+ }
+}
+
+void createActionSet_AllBulbOff()
+{
+ string actionsetDesc;
+ ActionSet *allBulbOff = new ActionSet();
+ allBulbOff->actionsetName = "AllBulbOff";
+
+ for (auto iter = lights.begin(); iter != lights.end(); ++iter)
+ {
+ Action *action = new Action();
+ action->target = (*iter);
+
+ Capability *capa = new Capability();
+ capa->capability = "power";
+ capa->status = "off";
+
+ action->listOfCapability.push_back(capa);
+ allBulbOff->listOfAction.push_back(action);
+ }
+ // actionsetDesc = thingsMgr->getStringFromActionSet(allBulbOff);
+
+ // cout << "ActionSet :: " << actionsetDesc << endl;
+
+ // OCRepresentation rep;
+ // rep.setValue("ActionSet", actionsetDesc);
+
+ if (g_resource)
+ {
+ thingsMgr->addActionSet(g_resource, allBulbOff, onPut);
+ // g_resource->put("a.collection", GROUP_INTERFACE, rep,
+ // QueryParamsMap(), &onPut);
+ }
+
+ delete allBulbOff;
+}
+
+void createActionSet_AllBulbOn()
+{
+ string actionsetDesc;
+ ActionSet *allBulbOff = new ActionSet();
+ allBulbOff->actionsetName = "AllBulbOn";
+
+ for (auto iter = lights.begin(); iter != lights.end(); ++iter)
+ {
+ Action *action = new Action();
+ action->target = (*iter);
+
+ Capability *capa = new Capability();
+ capa->capability = "power";
+ capa->status = "on";
+
+ action->listOfCapability.push_back(capa);
+ allBulbOff->listOfAction.push_back(action);
+ }
+ // actionsetDesc = thingsMgr->getStringFromActionSet(allBulbOff);
+
+ // cout << "ActionSet :: " << actionsetDesc << endl;
+
+ // OCRepresentation rep;
+ // rep.setValue("ActionSet", actionsetDesc);
+
+ if (g_resource)
+ {
+ thingsMgr->addActionSet(g_resource, allBulbOff, onPut);
+ // g_resource->put("a.collection", GROUP_INTERFACE, rep,
+ // QueryParamsMap(), &onPut);
+ }
+
+ delete allBulbOff;
+}
+
+int main()
+{
+ PlatformConfig config
+ { OC::ServiceType::InProc, ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos };
+
+ try
+ {
+ string resourceURI = "/core/a/collection";
+ string resourceTypeName = "a.collection";
+ string resourceInterface = BATCH_INTERFACE;
+ OCPlatform::Configure(config);
+
+ // Find lights for group creation.
+ vector< string > types;
+ types.push_back("core.light");
+ thingsMgr->findCandidateResources(types, &foundResources, 5);
+
+ OCPlatform::registerResource(resourceHandle, resourceURI, resourceTypeName,
+ resourceInterface, NULL,
+ //&entityHandler, // entityHandler
+ OC_DISCOVERABLE);
+
+ cout << "registerResource is called." << endl;
+
+ OCPlatform::bindInterfaceToResource(resourceHandle, GROUP_INTERFACE);
+ OCPlatform::bindInterfaceToResource(resourceHandle, DEFAULT_INTERFACE);
+
+ bool isRun = true;
+
+ while (isRun)
+ {
+ while (isReady)
+ {
+ int n;
+
+ cout << endl;
+ cout << "1 :: CREATE ACTIONSET 2 :: EXECUTE ACTIONSET(ALLBULBON)"
+ << "3 :: EXECUTE ACTIONSET(ALLBULBOFF)" << endl;
+ cout << "4 :: GET ACTIONSET 5 :: DELETE ACTIONSET 6 :: QUIT" << endl;
+ cout << "9 :: FIND GROUP 0 :: FIND BOOKMARK TO OBSERVE" << endl;
+
+ fflush(stdin);
+ cin >> n;
+
+ if (n == 9)
+ {
+ OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=a.collection",
+ &foundResource);
+ }
+ else if (n == 0)
+ {
+ OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.bookmark",
+ &foundResource);
+ }
+ else if (n == 1)
+ {
+
+ // Craete Action Set
+ // "AllBulbOff"
+ //"movieTime*uri=coap://10.251.44.228:49858/a/light|power=10";
+ createActionSet_AllBulbOff();
+ createActionSet_AllBulbOn();
+
+ }
+ else if (n == 2)
+ {
+
+ allBulbOn();
+ // thingsMgr->executeActionSet(g_resource, "AllBulbOn", onPost);
+
+ }
+ else if (n == 3)
+ {
+
+ allBulbOff();
+ // thingsMgr->executeActionSet(g_resource, "AllBulbOff", onPost);
+
+ }
+ else if (n == 4)
+ {
+ // OCRepresentation rep;
+
+ // rep.setValue("GetActionSet", std::string("AllBulbOff"));
+
+ // if(g_resource)
+ // {
+ // g_resource->post("a.collection", GROUP_INTERFACE, rep,
+ // QueryParamsMap(), &onPost);
+ // }
+
+ thingsMgr->getActionSet(g_resource, "AllBulbOff", onPost);
+ }
+ else if (n == 5)
+ {
+ // OCRepresentation rep;
+
+ // rep.setValue("DelActionSet", std::string("AllBulbOff"));
+
+ // if(g_resource)
+ // {
+ // g_resource->put("a.collection", GROUP_INTERFACE, rep,
+ // QueryParamsMap(), &onPut);
+ // }
+ thingsMgr->deleteActionSet(g_resource, "AllBulbOff", onPut);
+ }
+ else if (n == 6)
+ {
+ isRun = false;
+ break;
+ }
+ }
+ }
+ }
+ catch (OCException& e)
+ {
+
+ }
+
+ return 0;
+}
--- /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::InitFlag)
+ {
+ cout << "\t\trequestFlag : Init\n";
+
+ // entity handler to perform resource initialization operations
+ }
+ 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(int argc, char* argv[])
+{
+ // 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
+
+TGMROOT=../../../
+IOT_BASE=${TGMROOT}../../resource
+RST_NAME=.
+
+
+
+# C++ type Compile Flag define.
+CXX=g++
+CXX_FLAGS=-std=c++0x -Wall -pthread -DLINUX -ldl
+
+DEPEND_DIR:= ../../../../../resource/dependencies/
+CEREAL_DIR:= $(DEPEND_DIR)/cereal
+
+CXX_INC := -I../../ -I../../inc/
+CXX_INC += -I${IOT_BASE}/include/
+CXX_INC += -I${IOT_BASE}/oc_logger/include
+CXX_INC += -I${IOT_BASE}/csdk/stack/include
+CXX_INC += -I${IOT_BASE}/csdk/ocsocket/include
+CXX_INC += -I${IOT_BASE}/csdk/ocrandom/include
+CXX_INC += -I${IOT_BASE}/csdk/logger/include
+CXX_INC += -I$(CEREAL_DIR)/include
+CXX_INC += -I../../../sdk/inc
+CXX_INC += -I../../../sdk/src
+
+
+CXX_LIB=-L""
+
+CXX_SRCPATH=${wildcard ../../src/*.cpp}
+CXX_SRCLIST=${notdir ${CXX_SRCPATH}}
+CXX_USESRCS=${filter-out ${EXCLUDE_LIST}, ${CXX_SRCLIST}}
+CXX_OBJLIST=${CXX_USESRCS:.cpp=.o}
+
+
+TGM = ../../
+SDK = ${TGMROOT}sdk
+TGM_INC = -I${TGMROOT}sdk/inc
+SDK_LIB = ${TGMROOT}sdk/build/linux/libTGMSDKLibrary.a
+
+LIB_OC_LOGGER := $(IOT_BASE)/oc_logger/lib/oc_logger.a
+
+LD_LIB := $(IOT_BASE)/release/obj/liboc.a
+LD_LIB += $(IOT_BASE)/csdk/linux/release/liboctbstack.a
+LD_LIB += $(LIB_OC_LOGGER)
+
+
+# Force metatargets to build:
+.PHONY: all clean
+
+all: bookmark lightserver groupserver
+
+#groupclient
+bookmark: ./bookmark.cpp
+ $(CXX) $(CXX_FLAGS) -o bookmark ./bookmark.cpp $(CXX_INC) ${LD_LIB} $(TGM_INC) $(SDK_LIB)
+
+lightserver: ./lightserver.cpp
+ $(CXX) $(CXX_FLAGS) -o lightserver ./lightserver.cpp $(CXX_INC) ${LD_LIB} $(TGM_INC) $(SDK_LIB)
+
+groupserver: ./groupserver.cpp
+ $(CXX) $(CXX_FLAGS) -o groupserver ./groupserver.cpp $(CXX_INC) ${LD_LIB} $(TGM_INC) $(SDK_LIB)
+
+# groupclient: ./groupclient.cpp
+# $(CXX) $(CXX_FLAGS) -o groupclient ./groupclient.cpp $(CXX_INC) ${LD_LIB} $(TGM_INC) $(SDK_LIB)
+
+clean:
+ rm -f -v *.o ${TARGET}
+ rm -f groupserver
+ rm -f groupclient
+ rm -f lightserver
+ rm -f bookmark
--- /dev/null
+##
+# linux sample app build script
+##
+
+Import('env')
+
+# Add third party libraries
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+linux_sample_env = lib_env.Clone()
+
+######################################################################
+# Build flags
+######################################################################
+linux_sample_env.AppendUnique(CPPPATH = ['include'])
+linux_sample_env.AppendUnique(CPPPATH = ['../../../sdk/inc'])
+linux_sample_env.AppendUnique(CPPPATH = ['../../../sdk/src'])
+linux_sample_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
+linux_sample_env.AppendUnique(CPPDEFINES = ['LINUX'])
+linux_sample_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+linux_sample_env.AppendUnique(LIBS = ['libTGMSDKLibrary', 'oc', 'octbstack', 'libcoap', 'liboc_logger', 'dl', 'pthread'])
+
+
+######################################################################
+#build sampleapp
+######################################################################
+group = linux_sample_env.Program('group', 'group.cpp')
+musicplayer = linux_sample_env.Program('musicplayer', 'musicplayer.cpp')
+phone = linux_sample_env.Program('phone', 'phone.cpp')
+speaker = linux_sample_env.Program('speaker', 'speaker.cpp')
+Alias("GroupApp", group)
+Alias("ConCleintApp", musicplayer)
+Alias("PhoneApp", phone)
+Alias("SpeakerApp", speaker)
+env.AppendTarget('GroupApp')
+env.AppendTarget('MusicplayerApp')
+env.AppendTarget('PhoneApp')
+env.AppendTarget('SpeakerApp')
--- /dev/null
+//******************************************************************
+//
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include <string>
+#include <cstdlib>
+#include <pthread.h>
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "ThingsManager.h"
+
+using namespace OC;
+using namespace OIC;
+
+static ThingsManager* gThingManager = NULL;
+
+static std::vector< OCResourceHandle > gResourceHandleList;
+
+static std::string collectionResourceType = "core.group";
+
+void onFindResource(std::shared_ptr< OCResource > resource)
+{
+ cout << "onFindResource" << endl;
+
+ if (resource)
+ {
+ OCResourceHandle resourceHandle;
+ OCStackResult result = OCPlatform::registerResource(resourceHandle, resource);
+ if (OC_STACK_OK == result)
+ {
+ cout << "onFindResource : Resource creation was successful\n";
+ }
+ else
+ {
+ cout << "onFindResource : Resource creation was unsuccessful\n";
+ return;
+ }
+
+ result = gThingManager->joinGroup(collectionResourceType, resourceHandle);
+ if (OC_STACK_OK == result)
+ {
+ cout << "onFindResource : Joining group was successful\n";
+ }
+ else
+ {
+ cout << "onFindResource : Joining group was unsuccessful\n";
+
+ OCPlatform::unregisterResource(resourceHandle);
+ return;
+ }
+
+ gResourceHandleList.push_back(resourceHandle);
+ }
+ else
+ {
+ cout << "onFindResource : There is no found resource." << endl;
+ }
+}
+
+int main(int argc, char* argv[])
+{
+
+ // Create PlatformConfig object
+ PlatformConfig cfg
+ { OC::ServiceType::InProc, OC::ModeType::Both/*OC::ModeType::Server*/, "0.0.0.0", 0,
+ OC::QualityOfService::LowQos };
+
+ OCPlatform::Configure(cfg);
+ gThingManager = new ThingsManager();
+
+ int selectedMenu;
+ OCStackResult result;
+
+ try
+ {
+ while (true)
+ {
+ // some operations
+ cout << "(1) CREATE GROUP " << endl;
+ cout << "(11) FIND MUSIC PLAYER & JOIN GROUP | (12) FIND SPEAKER & JOIN GROUP" << endl;
+ cout << "(21) LEAVE GROUP - MUSIC PLAYER | (22) LEAVE GROUP - SPEAKER" << endl;
+ cout << "(31) DELETE GROUP " << endl;
+
+ std::cin >> selectedMenu;
+
+ if (selectedMenu == 1)
+ {
+ result = gThingManager->createGroup(collectionResourceType);
+ if (OC_STACK_OK == result)
+ {
+ cout << "Group creation was successful\n";
+ }
+ else
+ {
+ cout << "Group creation was unsuccessful\n";
+ }
+ }
+ else if (selectedMenu == 11)
+ {
+ result = OCPlatform::findResource("",
+ "coap://224.0.1.187/oc/core?rt=core.musicplayer", onFindResource);
+ if (OC_STACK_OK == result)
+ {
+ cout << "Finding music player was successful\n";
+ }
+ else
+ {
+ cout << "Finding music player was unsuccessful\n";
+ }
+ }
+ else if (selectedMenu == 12)
+ {
+ result = OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.speaker",
+ onFindResource);
+ if (OC_STACK_OK == result)
+ {
+ cout << "Finding speaker was successful\n";
+ }
+ else
+ {
+ cout << "Finding speaker was unsuccessful\n";
+ }
+ }
+ else if (selectedMenu == 21)
+ {
+ std::vector< OCResourceHandle >::iterator It;
+ OCResourceHandle resourceHandle;
+ for (It = gResourceHandleList.begin(); It != gResourceHandleList.end(); ++It)
+ {
+ resourceHandle = (*It);
+ std::string mpType = "core.musicplayer";
+ std::string type = OCGetResourceTypeName(resourceHandle, 0);
+ if (0 == mpType.compare(type))
+ {
+ result = gThingManager->leaveGroup(collectionResourceType, resourceHandle);
+ if (OC_STACK_OK == result)
+ {
+ cout << "Leaving group of music player was successful\n";
+ }
+ else
+ {
+ cout << "Leaving group of music player was unsuccessful\n";
+ }
+ break;
+ }
+ }
+
+ gResourceHandleList.erase(It);
+ result = OCPlatform::unregisterResource(resourceHandle);
+ if (OC_STACK_OK == result)
+ {
+ cout << "Unregistering music player was successful\n";
+ }
+ else
+ {
+ cout << "Unregistering music player was unsuccessful\n";
+ }
+ }
+ else if (selectedMenu == 22)
+ {
+ std::vector< OCResourceHandle >::iterator It;
+ OCResourceHandle resourceHandle;
+ for (It = gResourceHandleList.begin(); It != gResourceHandleList.end(); ++It)
+ {
+ resourceHandle = (*It);
+ std::string mpType = "core.speaker";
+ std::string type = OCGetResourceTypeName(resourceHandle, 0);
+ if (0 == mpType.compare(type))
+ {
+ result = gThingManager->leaveGroup(collectionResourceType, resourceHandle);
+ if (OC_STACK_OK == result)
+ {
+ cout << "Leaving group of speaker was successful\n";
+ }
+ else
+ {
+ cout << "Leaving group of speaker was unsuccessful\n";
+ }
+ break;
+ }
+ }
+
+ gResourceHandleList.erase(It);
+ result = OCPlatform::unregisterResource(resourceHandle);
+ if (OC_STACK_OK == result)
+ {
+ cout << "Unregistering speaker was successful\n";
+ }
+ else
+ {
+ cout << "Unregistering speaker was unsuccessful\n";
+ }
+ }
+ else if (selectedMenu == 31)
+ {
+ gThingManager->deleteGroup(collectionResourceType);
+ }
+ }
+ }
+ catch (OCException& e)
+ {
+ //log(e.what());
+ }
+
+ return 0;
+}
+
--- /dev/null
+
+TGMROOT=../../../
+IOT_BASE=${TGMROOT}../../resource
+RST_NAME=.
+TARGET1=group
+TARGET2=phone
+TARGET3=musicplayer
+TARGET4=speaker
+BUILD:=release
+
+# C++ type Compile Flag define.
+CXX=g++
+CXX_FLAGS=-std=c++0x -Wall -pthread -DLINUX -ldl
+
+CXX_INC := -I../../ -I../../inc/ -I../../../sdk/inc/ -I../../../sdk/src/
+CXX_INC += -I${IOT_BASE}/include/
+CXX_INC += -I${IOT_BASE}/oc_logger/include
+CXX_INC += -I${IOT_BASE}/csdk/stack/include
+CXX_INC += -I${IOT_BASE}/csdk/ocsocket/include
+CXX_INC += -I${IOT_BASE}/csdk/ocrandom/include
+CXX_INC += -I${IOT_BASE}/csdk/logger/include
+CXX_INC += -I${IOT_BASE}/dependencies/cereal/include
+
+CXX_LIB=-L""
+
+CXX_SRCPATH=${wildcard ../../src/*.cpp}
+CXX_SRCLIST=${notdir ${CXX_SRCPATH}}
+CXX_USESRCS=${filter-out ${EXCLUDE_LIST}, ${CXX_SRCLIST}}
+CXX_OBJLIST=${CXX_USESRCS:.cpp=.o}
+
+
+TGM = ../../
+SDK = ${TGMROOT}sdk
+TGM_INC = -I${TGMROOT}sdk/inc
+SDK_LIB = ${TGMROOT}sdk/build/linux/libTGMSDKLibrary.a
+
+LIB_OC_LOGGER := $(IOT_BASE)/oc_logger/lib/oc_logger.a
+
+LD_LIB := $(IOT_BASE)/$(BUILD)/obj/liboc.a
+LD_LIB += $(IOT_BASE)/csdk/linux/$(BUILD)/liboctbstack.a
+LD_LIB += $(LIB_OC_LOGGER)
+
+
+# Force metatargets to build:
+.PHONY: all clean
+
+all: ${TARGET1} ${TARGET2} ${TARGET3} ${TARGET4}
+
+${TARGET1}: ./group.cpp
+ $(CXX) $(CXX_FLAGS) -o ${TARGET1} ./group.cpp $(CXX_INC) ${LD_LIB} $(TGM_INC) $(SDK_LIB)
+
+${TARGET2}: ./phone.cpp
+ $(CXX) $(CXX_FLAGS) -o ${TARGET2} ./phone.cpp $(CXX_INC) ${LD_LIB} $(TGM_INC) $(SDK_LIB)
+
+${TARGET3}: ./musicplayer.cpp
+ $(CXX) $(CXX_FLAGS) -o ${TARGET3} ./musicplayer.cpp $(CXX_INC) ${LD_LIB} $(TGM_INC) $(SDK_LIB)
+
+${TARGET4}: ./speaker.cpp
+ $(CXX) $(CXX_FLAGS) -o ${TARGET4} ./speaker.cpp $(CXX_INC) ${LD_LIB} $(TGM_INC) $(SDK_LIB)
+
+clean:
+ rm -f -v *.o ${TARGET1}
+ rm -f -v *.o ${TARGET2}
+ rm -f -v *.o ${TARGET3}
+ rm -f -v *.o ${TARGET4}
--- /dev/null
+//******************************************************************
+//
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include <string>
+#include <cstdlib>
+#include <pthread.h>
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "ThingsManager.h"
+
+using namespace OC;
+
+OCEntityHandlerResult mpEntityHandler(const std::shared_ptr< OCResourceRequest > request)
+{
+ cout << "mpEntityHandler:\n";
+
+ if (request)
+ {
+ // Get the request type and request flag
+ std::string requestType = request->getRequestType();
+ int requestFlag = request->getRequestHandlerFlag();
+ std::string action;
+
+ if (requestFlag == RequestHandlerFlag::InitFlag)
+ {
+ cout << "\trequestFlag : Init\n";
+
+ // entity handler to perform resource initialization operations
+ }
+ else if (requestFlag == RequestHandlerFlag::RequestFlag)
+ {
+ cout << "\trequestFlag : Request\n";
+
+ OCRepresentation rp = request->getResourceRepresentation();
+
+ // If the request type is GET
+ if (requestType == "GET")
+ {
+ cout << "\t\trequestType : GET\n";
+ }
+ else if (requestType == "PUT")
+ {
+ cout << "\t\trequestType : PUT\n";
+
+ action = rp.getValue< std::string >("play");
+ cout << "\t\t\tplay : " << action << endl;
+ }
+ else if (requestType == "POST")
+ {
+ cout << "\t\trequestType : POST\n";
+ }
+ else if (requestType == "DELETE")
+ {
+ cout << "\t\trequestType : DELETE\n";
+ }
+ }
+ else if (requestFlag == RequestHandlerFlag::ObserverFlag)
+ {
+ cout << "\trequestFlag : Observer\n";
+ }
+ }
+ else
+ {
+ cout << "Request invalid" << endl;
+ }
+
+ return OC_EH_OK;
+}
+
+int main(int argc, char* argv[])
+{
+ // Create PlatformConfig object
+ PlatformConfig cfg
+ { OC::ServiceType::InProc, OC::ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos };
+
+ OCPlatform::Configure(cfg);
+
+ int selectedMenu;
+ OCStackResult result;
+ OCResourceHandle mpResourceHandle = NULL;
+
+ try
+ {
+ while (true)
+ {
+ // some operations
+ cout << "(1) CREATE MUSIC PLAYER | (2) DELETE MUSIC PLAYER" << endl;
+
+ std::cin >> selectedMenu;
+
+ if (selectedMenu == 1)
+ {
+ if (mpResourceHandle)
+ {
+ cout << "Music player resource is registered already." << endl;
+ continue;
+ }
+
+ std::string resourceURi = "/core/musicplayer";
+ std::string resourceTypeName = "core.musicplayer";
+ std::string resourceInterface = DEFAULT_INTERFACE;
+
+ result = OCPlatform::registerResource(mpResourceHandle, resourceURi,
+ resourceTypeName, resourceInterface, mpEntityHandler,
+ OC_DISCOVERABLE | OC_OBSERVABLE);
+ if (OC_STACK_OK == result)
+ {
+ cout << "To register music player resource was successful\n";
+ }
+ else
+ {
+ cout << "To register music player resource was unsuccessful\n";
+ }
+ }
+ else if (selectedMenu == 2)
+ {
+ if (NULL == mpResourceHandle)
+ {
+ cout
+ << "Error! No resource to unregister. Register resource first!"
+ << endl;
+ continue;
+ }
+
+ result = OCPlatform::unregisterResource(mpResourceHandle);
+ if (OC_STACK_OK == result)
+ {
+ cout << "To unregister music player resource was successful\n";
+ }
+ else
+ {
+ cout << "To unregister music player resource was unsuccessful\n";
+ }
+
+ mpResourceHandle = NULL;
+ }
+ }
+ }
+ catch (OCException& e)
+ {
+ //log(e.what());
+ }
+
+ return 0;
+}
+
--- /dev/null
+//******************************************************************
+//
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include <string>
+#include <cstdlib>
+#include <pthread.h>
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "ThingsManager.h"
+
+using namespace OC;
+using namespace OIC;
+
+static ThingsManager* gThingManager = NULL;
+
+static OCResourceHandle gPhoneResourceHandle = NULL;
+
+static std::shared_ptr< OCResource > gFindGroup = NULL;
+
+static std::string collectionResourceType = "core.group";
+
+static ActionSet* gPlayStart;
+
+static ActionSet* gPlayStop;
+
+void onFindGroup(std::shared_ptr< OCResource > resource)
+{
+ if (resource)
+ {
+ if (NULL == gPhoneResourceHandle)
+ {
+ cout
+ << "onFindGroup : Error! No resource to join group. Register resource first!"
+ << endl;
+ return;
+ }
+
+ if (gFindGroup)
+ {
+ cout << "onFindGroup : Found group is already saved." << endl;
+ }
+ else
+ {
+ cout << "onFindGroup : Found group is saved now." << endl;
+ gFindGroup = resource;
+ }
+
+ gThingManager->joinGroup(gFindGroup, gPhoneResourceHandle);
+ }
+ else
+ {
+ cout << "onFindGroup : Resource is invalid. So a new Group Resource has to be created."
+ << endl;
+ }
+}
+
+void onAction(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+{
+ if (eCode == OC_STACK_OK)
+ {
+ cout << "onAction" << endl;
+ }
+ else
+ {
+ cout << "onAction : error - " << eCode << endl;
+ }
+}
+
+void onGetChild(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+{
+ if (eCode == OC_STACK_OK)
+ {
+ gPlayStart = new ActionSet();
+ gPlayStop = new ActionSet();
+
+ gPlayStart->actionsetName = "playstart";
+ gPlayStop->actionsetName = "playstop";
+
+ std::vector< OCRepresentation > childList = rep.getChildren();
+ OCRepresentation child;
+ std::string resourceURI;
+
+ QueryParamsMap query;
+ OCRepresentation rep;
+ std::string playStart;
+ std::string playStop;
+
+ std::vector< std::string > types;
+ std::string resType;
+
+ OCStackResult result;
+
+ for (unsigned int i = 0; i < childList.size(); ++i)
+ {
+// cout << "\n\tchild resource - " << i + 1 << endl;
+
+ child = childList.at(i);
+ resourceURI = child.getUri();
+
+// cout << "\t\tURI of the resource: " << resourceURI << endl;
+
+// cout << "\t\tList of resource types: " << endl;
+
+ types = child.getResourceTypes();
+
+ for (unsigned int j = 0; j < types.size(); ++j)
+ {
+ resType = types.at(j);
+// cout << "\t\t\t" << resType << endl;
+
+ if (std::string::npos != resType.find("musicplayer"))
+ {
+ Capability *pStartCapa = new Capability;
+ pStartCapa->capability = "play";
+ pStartCapa->status = "on";
+
+ Action* pPlayStart = new Action();
+ pPlayStart->target = resourceURI;
+ pPlayStart->listOfCapability.push_back(pStartCapa);
+
+ gPlayStart->listOfAction.push_back(pPlayStart);
+
+ Capability *pStopCapa = new Capability;
+ pStopCapa->capability = "play";
+ pStopCapa->status = "off";
+
+ Action* pPlayStop = new Action();
+ pPlayStop->target = resourceURI;
+ pPlayStop->listOfCapability.push_back(pStopCapa);
+
+ gPlayStop->listOfAction.push_back(pPlayStop);
+ }
+ else if (std::string::npos != resType.find("speaker"))
+ {
+ Capability *pStartCapa = new Capability;
+ pStartCapa->capability = "volume";
+ pStartCapa->status = "50";
+
+ Action* pPlayStart = new Action();
+ pPlayStart->target = resourceURI;
+ pPlayStart->listOfCapability.push_back(pStartCapa);
+
+ gPlayStart->listOfAction.push_back(pPlayStart);
+
+ Capability *pStopCapa = new Capability;
+ pStopCapa->capability = "volume";
+ pStopCapa->status = "0";
+
+ Action* pPlayStop = new Action();
+ pPlayStop->target = resourceURI;
+ pPlayStop->listOfCapability.push_back(pStopCapa);
+
+ gPlayStop->listOfAction.push_back(pPlayStop);
+ }
+ }
+ }
+
+// std::string temp = gThingManager->getStringFromActionSet (gPlayStart);
+// cout << "play start - " << temp << endl;
+
+// temp = gThingManager->getStringFromActionSet (gPlayStop);
+// cout << "play stop - " << temp << endl;
+
+ if (0 == gPlayStart->listOfAction.empty())
+ {
+ result = gThingManager->addActionSet(gFindGroup, gPlayStart, onAction);
+ if (OC_STACK_OK == result)
+ {
+ cout << "addActionSet(gPlayStart) was successful\n";
+ }
+ else
+ {
+ cout << "addActionSet(gPlayStart) was unsuccessful. result = " << result << endl;
+ }
+ }
+
+ if (0 == gPlayStop->listOfAction.empty())
+ {
+ result = gThingManager->addActionSet(gFindGroup, gPlayStop, onAction);
+ if (OC_STACK_OK == result)
+ {
+ cout << "addActionSet(gPlayStop) was successful\n";
+ }
+ else
+ {
+ cout << "addActionSet(gPlayStop) was unsuccessful. result = " << result << endl;
+ }
+ }
+ }
+ else
+ {
+ cout << "onGetChild : error - " << eCode << endl;
+ }
+}
+
+int main(int argc, char* argv[])
+{
+ // Create PlatformConfig object
+ PlatformConfig cfg
+ { OC::ServiceType::InProc, OC::ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos };
+
+ OCPlatform::Configure(cfg);
+ gThingManager = new ThingsManager();
+
+ int selectedMenu;
+ OCStackResult result;
+
+ try
+ {
+ while (true)
+ {
+ // some operations
+ cout << "(1) CREATE PHONE" << endl;
+ cout
+ << "(11) FIND & JOIN GROUP | (12) ADD GROUP ACTION | (13) PLAY START"
+ << " | (14) PLAY STOP"<< endl;
+ cout << "(15) DELETE GROUP ACTION | (16) LEAVE GROUP" << endl;
+ cout << "(21) DELETE PHONE" << endl;
+
+ std::cin >> selectedMenu;
+
+ if (selectedMenu == 1)
+ {
+ if (gPhoneResourceHandle)
+ {
+ cout << "Phone resource is registered already." << endl;
+ continue;
+ }
+
+ std::string resourceURi = "/core/phone";
+ std::string resourceTypeName = "core.phone";
+ std::string resourceInterface = DEFAULT_INTERFACE;
+
+ result = OCPlatform::registerResource(gPhoneResourceHandle, resourceURi,
+ resourceTypeName, resourceInterface, NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
+ if (OC_STACK_OK == result)
+ {
+ cout << "To register phone resource was successful\n";
+ }
+ else
+ {
+ cout << "To register phone resource was unsuccessful. result = " << result
+ << endl;
+ }
+ }
+ else if (selectedMenu == 11)
+ {
+ std::vector< std::string > types;
+ types.clear();
+ types.push_back(collectionResourceType);
+
+ result = gThingManager->findGroup(types, &onFindGroup);
+ if (OC_STACK_OK == result)
+ {
+ cout << "Finding group was successful\n";
+ }
+ else
+ {
+ cout << "Finding group was unsuccessful. result = " << result << endl;
+ }
+ }
+ else if (selectedMenu == 12)
+ {
+ if (!gFindGroup)
+ {
+ cout << "gFindGroup is NULL. Please process step 1 and step 11 first." << endl;
+ continue;
+ }
+
+ QueryParamsMap queryParamsMap;
+ result = gFindGroup->get("", DEFAULT_INTERFACE, queryParamsMap, onGetChild);
+ if (OC_STACK_OK == result)
+ {
+ cout << "gFindGroup->get was successful\n";
+ }
+ else
+ {
+ cout << "gFindGroup->get was unsuccessful. result = " << result << endl;
+ }
+ }
+ else if (selectedMenu == 13)
+ {
+ if (!gFindGroup)
+ {
+ cout << "gFindGroup is NULL. Please process step 1 and step 11 first." << endl;
+ continue;
+ }
+
+ if (!gPlayStart)
+ {
+ cout << "gPlayStart is NULL. Please process step 12 first." << endl;
+ continue;
+ }
+
+ result = gThingManager->executeActionSet(gFindGroup, "playstart", onAction);
+ if (OC_STACK_OK == result)
+ {
+ cout << "DoAction(playstart) was successful\n";
+ }
+ else
+ {
+ cout << "DoAction(playstart) was unsuccessful. result = " << result << endl;
+ }
+ }
+ else if (selectedMenu == 14)
+ {
+ if (!gFindGroup)
+ {
+ cout << "gFindGroup is NULL. Please process step 1 and step 11 first." << endl;
+ continue;
+ }
+
+ if (!gPlayStop)
+ {
+ cout << "gPlayStop is NULL. Please process step 12 first." << endl;
+ continue;
+ }
+
+ result = gThingManager->executeActionSet(gFindGroup, "playstop", onAction);
+ if (OC_STACK_OK == result)
+ {
+ cout << "DoAction(playstop) was successful\n";
+ }
+ else
+ {
+ cout << "DoAction(playstop) was unsuccessful. result = " << result << endl;
+ }
+ }
+ else if (selectedMenu == 15)
+ {
+ if (!gFindGroup)
+ {
+ cout << "gFindGroup is NULL. Please process step 1 and step 11 first." << endl;
+ continue;
+ }
+
+ if (!gPlayStart)
+ {
+ cout << "gPlayStart is NULL. Please process step 12 first." << endl;
+ continue;
+ }
+
+ if (!gPlayStop)
+ {
+ cout << "gPlayStop is NULL. Please process step 12 first." << endl;
+ continue;
+ }
+
+ result = gThingManager->deleteActionSet(gFindGroup, "playstart", onAction);
+ if (OC_STACK_OK == result)
+ {
+ cout << "Delete Action(playstart) was successful\n";
+ }
+ else
+ {
+ cout << "Delete Action(playstart) was unsuccessful. result = " << result
+ << endl;
+ }
+
+ result = gThingManager->deleteActionSet(gFindGroup, "playstop", onAction);
+ if (OC_STACK_OK == result)
+ {
+ cout << "Delete Action(playstop) was successful\n";
+ }
+ else
+ {
+ cout << "Delete Action(playstop) was unsuccessful. result = " << result << endl;
+ }
+
+ Action* a;
+ Capability* c;
+
+ for (auto actionIter = gPlayStart->listOfAction.begin();
+ actionIter != gPlayStart->listOfAction.end(); ++actionIter)
+ {
+ a = (*actionIter);
+
+ for (auto capaIter = a->listOfCapability.begin();
+ capaIter != a->listOfCapability.end(); ++capaIter)
+ {
+ c = (*capaIter);
+ delete c;
+ }
+
+ delete a;
+ }
+
+ delete gPlayStart;
+ gPlayStart = NULL;
+
+ for (auto actionIter = gPlayStop->listOfAction.begin();
+ actionIter != gPlayStop->listOfAction.end(); ++actionIter)
+ {
+ a = (*actionIter);
+
+ for (auto capaIter = a->listOfCapability.begin();
+ capaIter != a->listOfCapability.end(); ++capaIter)
+ {
+ c = (*capaIter);
+ delete c;
+ }
+
+ delete a;
+ }
+
+ delete gPlayStop;
+ gPlayStop = NULL;
+ }
+ else if (selectedMenu == 16)
+ {
+ if (NULL == gPhoneResourceHandle)
+ {
+ cout
+ << "Error! No resource to leave group. Register resource first!"
+ << endl;
+ continue;
+ }
+
+ result = gThingManager->leaveGroup(collectionResourceType, gPhoneResourceHandle);
+ if (OC_STACK_OK == result)
+ {
+ cout << "Leaving group was successful\n";
+ }
+ else
+ {
+ cout << "Leaving group was unsuccessful. result = " << result << endl;
+ }
+ }
+ else if (selectedMenu == 21)
+ {
+ if (NULL == gPhoneResourceHandle)
+ {
+ cout
+ << "Error! No resource to unregister. Register resource first!"
+ << endl;
+ continue;
+ }
+
+ result = OCPlatform::unregisterResource(gPhoneResourceHandle);
+ if (OC_STACK_OK == result)
+ {
+ cout << "To unregister phone resource was successful\n";
+ }
+ else
+ {
+ cout << "To unregister phone resource was unsuccessful. result = " << result
+ << endl;
+ }
+ gPhoneResourceHandle = NULL;
+ }
+ }
+
+ }
+ catch (OCException& e)
+ {
+ //log(e.what());
+ }
+
+ return 0;
+}
+
--- /dev/null
+//******************************************************************
+//
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include <string>
+#include <cstdlib>
+#include <pthread.h>
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "ThingsManager.h"
+
+using namespace OC;
+
+OCEntityHandlerResult speakerEntityHandler(const std::shared_ptr< OCResourceRequest > request)
+{
+ cout << "speakerEntityHandler:\n";
+
+ if (request)
+ {
+ // Get the request type and request flag
+ std::string requestType = request->getRequestType();
+ int requestFlag = request->getRequestHandlerFlag();
+ std::string action;
+
+ if (requestFlag == RequestHandlerFlag::InitFlag)
+ {
+ cout << "\trequestFlag : Init\n";
+
+ // entity handler to perform resource initialization operations
+ }
+ else if (requestFlag == RequestHandlerFlag::RequestFlag)
+ {
+ cout << "\trequestFlag : Request\n";
+
+ OCRepresentation rp = request->getResourceRepresentation();
+
+ // If the request type is GET
+ if (requestType == "GET")
+ {
+ cout << "\t\trequestType : GET\n";
+ }
+ else if (requestType == "PUT")
+ {
+ cout << "\t\trequestType : PUT\n";
+
+ action = rp.getValue< std::string >("volume");
+ cout << "\t\t\tvolume : " << action << endl;
+ }
+ else if (requestType == "POST")
+ {
+ cout << "\t\trequestType : POST\n";
+ }
+ else if (requestType == "DELETE")
+ {
+ cout << "\t\trequestType : DELETE\n";
+ }
+ }
+ else if (requestFlag == RequestHandlerFlag::ObserverFlag)
+ {
+ cout << "\trequestFlag : Observer\n";
+ }
+ }
+ else
+ {
+ cout << "Request invalid" << endl;
+ }
+
+ return OC_EH_OK;
+}
+
+int main(int argc, char* argv[])
+{
+
+ // Create PlatformConfig object
+ PlatformConfig cfg
+ { OC::ServiceType::InProc, OC::ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos };
+
+ OCPlatform::Configure(cfg);
+
+ int selectedMenu;
+ OCStackResult result;
+ OCResourceHandle speakerResourceHandle = NULL;
+
+ try
+ {
+ while (true)
+ {
+ // some operations
+ cout << "(1) CREATE SPEAKER | (2) DELETE SPEAKER" << endl;
+
+ std::cin >> selectedMenu;
+
+ if (selectedMenu == 1)
+ {
+ if (speakerResourceHandle)
+ {
+ cout << "Speaker resource is registered already." << endl;
+ continue;
+ }
+
+ std::string resourceURi = "/core/speaker";
+ std::string resourceTypeName = "core.speaker";
+
+ std::string resourceInterface = DEFAULT_INTERFACE;
+
+ result = OCPlatform::registerResource(speakerResourceHandle, resourceURi,
+ resourceTypeName, resourceInterface, speakerEntityHandler,
+ OC_DISCOVERABLE | OC_OBSERVABLE);
+ if (OC_STACK_OK == result)
+ {
+ cout << "To register speaker resource was successful\n";
+ }
+ else
+ {
+ cout << "To register speaker resource was unsuccessful\n";
+ }
+ }
+ else if (selectedMenu == 2)
+ {
+ if (NULL == speakerResourceHandle)
+ {
+ cout
+ << "Error! No resource to unregister. Register resource first!"
+ << endl;
+ continue;
+ }
+
+ result = OCPlatform::unregisterResource(speakerResourceHandle);
+ if (OC_STACK_OK == result)
+ {
+ cout << "To unregister speaker resource was successful\n";
+ }
+ else
+ {
+ cout << "To unregister speaker resource was unsuccessful\n";
+ }
+
+ speakerResourceHandle = NULL;
+ }
+ }
+ }
+ catch (OCException& e)
+ {
+ //log(e.what());
+ }
+
+ return 0;
+}
+
--- /dev/null
+MAKE=make
+
+DIRLIST=configuration groupaction groupsyncaction
+
+# Force metatargets to build:
+.PHONY: all clean
+
+all: build
+
+build:
+ @for subdir in ${DIRLIST} ; do \
+ ${MAKE} -C $${subdir} ; \
+ echo " " ; \
+ done
+ @echo " "
+
+clean:
+ @for subdir in ${DIRLIST} ; do \
+ ${MAKE} clean -C $${subdir} ; \
+ echo " " ; \
+ done
+++ /dev/null
-##
-# linux sample app build script
-##
-
-Import('env')
-
-# Add third party libraries
-lib_env = env.Clone()
-SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
-
-linux_sample_env = lib_env.Clone()
-######################################################################
-# Build flags
-######################################################################
-linux_sample_env.AppendUnique(CPPPATH = ['../../../sdk/inc'])
-linux_sample_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
-linux_sample_env.AppendUnique(LIBS = ['oc', 'octbstack', 'coap', 'oc_logger', 'TGMSDKLibrary'])
-
-if env.get('TARGET_OS') not in ['windows', 'winrt']:
- linux_sample_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
-
-######################################################################
-# Source files and Targets
-######################################################################
-tgmclient = linux_sample_env.Program('tgmclient', 'tgmsdkclient.cpp')
-
-Alias("tgmclient_sample", tgmclient)
-env.AppendTarget('tgmclient_sample')
\ No newline at end of file
+++ /dev/null
-
-TGMROOT=../../../
-IOT_BASE=${TGMROOT}../../resource
-RST_NAME=.
-TARGET=tgmclient
-
-
-# C++ type Compile Flag define.
-CXX=g++
-CXX_FLAGS=-std=c++0x -Wall -pthread -DLINUX -ldl
-
-CXX_INC := -I../../ -I../../inc/
-CXX_INC += -I${IOT_BASE}/include/
-CXX_INC += -I${IOT_BASE}/oc_logger/include
-CXX_INC += -I${IOT_BASE}/csdk/stack/include
-CXX_INC += -I${IOT_BASE}/csdk/ocsocket/include
-CXX_INC += -I${IOT_BASE}/csdk/ocrandom/include
-CXX_INC += -I${IOT_BASE}/csdk/logger/include
-
-CXX_LIB=-L""
-
-CXX_SRCPATH=${wildcard ../../src/*.cpp}
-CXX_SRCLIST=${notdir ${CXX_SRCPATH}}
-CXX_USESRCS=${filter-out ${EXCLUDE_LIST}, ${CXX_SRCLIST}}
-CXX_OBJLIST=${CXX_USESRCS:.cpp=.o}
-
-
-TGM = ../../
-SDK = ${TGMROOT}sdk
-TGM_INC = -I${TGMROOT}sdk/inc
-SDK_LIB = ${TGMROOT}sdk/build/linux/libTGMSDKLibrary.a
-
-LIB_OC_LOGGER := $(IOT_BASE)/oc_logger/lib/oc_logger.a
-
-LD_LIB := $(IOT_BASE)/release/obj/liboc.a
-LD_LIB += $(IOT_BASE)/csdk/linux/release/liboctbstack.a
-LD_LIB += $(LIB_OC_LOGGER)
-
-
-# Force metatargets to build:
-.PHONY: all clean
-
-all: ${TARGET}
-
-${TARGET}: ./tgmsdkclient.cpp
- $(CXX) $(CXX_FLAGS) -o ${TARGET} ./tgmsdkclient.cpp $(CXX_INC) ${LD_LIB} $(TGM_INC) $(SDK_LIB)
-
-clean:
- rm -f -v *.o ${TARGET}
-
+++ /dev/null
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#include <string>
-#include <cstdlib>
-#include <pthread.h>
-#include "OCPlatform.h"
-#include "OCApi.h"
-#include "TGMClient.h"
-
-using namespace OC;
-
-void onGet(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
-{
- if (eCode == OC_STACK_OK)
- {
- std::cout << "GET request was successful" << std::endl;
- std::cout << "Resource URI: " << rep.getUri() << std::endl;
-
- AttributeMap dataMap = rep.getAttributeMap();
- for (auto it = dataMap.begin(); it != dataMap.end(); ++it)
- {
- std::cout << "\t KEY:" << it->first << " // VALUE:" << it->second << std::endl;
- }
-
- }
- else
- {
- std::cout << "onGET Response error: " << eCode << std::endl;
- std::exit(-1);
- }
-}
-
-void onFoundCandidate(std::vector< std::shared_ptr< OCResource > > resources)
-{
- std::cout << "\n\n FOUND CANDIDATE \n\n";
- for (unsigned int i = 0; i < resources.size(); ++i)
- {
- QueryParamsMap test;
- resources.at(i)->get(test, &onGet);
- }
-}
-
-int main(int argc, char* argv[])
-{
-
- // Create PlatformConfig object
- PlatformConfig cfg
- { OC::ServiceType::InProc, OC::ModeType::Client, "0.0.0.0", 0, OC::QualityOfService::LowQos };
-
- OCPlatform::Configure(cfg);
- TGMClient *tgmclient = new TGMClient();
-
- int selectedMenu;
-
- try
- {
- std::vector < std::string > types;
-
- while (true)
- {
- // some operations
- std::cout << "ADD | (1)TV | (2)LIGHT | (3)CURTAIN | (4)RESET |" << std::endl;
- std::cout << "FIND | (5) ONCE | (6) 10sec |" << std::endl;
-
- std::cin >> selectedMenu;
-
- if (selectedMenu == 1)
- {
- types.push_back("core.tv");
- }
- else if (selectedMenu == 2)
- {
- types.push_back("core.light");
- }
- else if (selectedMenu == 3)
- {
- types.push_back("core.curtain");
- }
- else if (selectedMenu == 4)
- {
- types.clear();
- }
- else if (selectedMenu == 5)
- {
- tgmclient->findCandidateResources(types, &onFoundCandidate);
- }
- else if (selectedMenu == 6)
- {
- tgmclient->findCandidateResources(types, &onFoundCandidate, 10);
- }
-
- }
-
- }
- catch (OCException& e)
- {
- //log(e.what());
- }
-
- return 0;
-}
-