1 //******************************************************************
3 // Copyright 2014 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 /// This sample shows how one could create a resource (collection) with children.
28 #include "OCPlatform.h"
30 #include "ThingsManager.h"
31 #include "ConfigurationCollection.h"
35 /// This function internally calls registerResource API.
36 void ConfigurationResource::createResources(ResourceEntityHandler callback)
38 using namespace OC::OCPlatform;
42 std::cout << "callback should be binded\t";
46 // This will internally create and register the resource.
47 OCStackResult result = registerResource(m_configurationHandle, m_configurationUri,
48 m_configurationTypes[0], m_configurationInterfaces[0], callback,
49 OC_DISCOVERABLE | OC_OBSERVABLE);
51 if (OC_STACK_OK != result)
53 std::cout << "Resource creation (configuration) was unsuccessful\n";
56 std::cout << "Configuration Resource is Created!(URI: " << m_configurationUri << ") \n";
59 void ConfigurationResource::setConfigurationRepresentation(OCRepresentation& rep)
63 if (rep.getValue("loc", value))
66 std::cout << "\t\t\t\t" << "m_location: " << m_location << std::endl;
69 if (rep.getValue("st", value))
71 std::cout << "\t\t\t\t" << "SystemTime is not allowed to be written." << std::endl;
74 if (rep.getValue("c", value))
77 std::cout << "\t\t\t\t" << "m_currency: " << m_currency << std::endl;
80 if (rep.getValue("r", value))
83 std::cout << "\t\t\t\t" << "m_region: " << m_region << std::endl;
87 OCRepresentation ConfigurationResource::getConfigurationRepresentation()
89 m_configurationRep.setValue("loc", m_location);
90 m_configurationRep.setValue("st", m_systemTime);
91 m_configurationRep.setValue("c", m_currency);
92 m_configurationRep.setValue("r", m_region);
94 return m_configurationRep;
97 std::string ConfigurationResource::getUri()
99 return m_configurationUri;
102 void ConfigurationResource::factoryReset()
104 m_location = defaultLocation;
105 m_systemTime = defaultSystemTime;
106 m_currency = defaultCurrency;
107 m_region = defaultRegion;