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"
36 typedef std::function<
37 OCEntityHandlerResult(std::shared_ptr< OCResourceRequest > request) > ResourceEntityHandler;
39 static std::string defaultURIPrefix = "/oic/con";
40 static std::string defaultResourceTypePrefix = "oic.con";
42 extern std::string defaultLocation;
43 extern std::string defaultSystemTime;
44 extern std::string defaultCurrency;
45 extern std::string defaultRegion;
47 class ConfigurationResource
50 // Configuration members
51 std::string m_configurationUri;
52 std::string m_location;
53 std::string m_systemTime;
54 std::string m_currency;
56 std::vector< std::string > m_configurationTypes;
57 std::vector< std::string > m_configurationInterfaces;
58 OCResourceHandle m_configurationHandle;
59 OCRepresentation m_configurationRep;
63 ConfigurationResource() :
64 m_location(defaultLocation), m_systemTime(defaultSystemTime), m_currency(
65 defaultCurrency), m_region(defaultRegion)
67 m_configurationUri = "/oic/con"; // URI of the resource
68 m_configurationTypes.push_back("oic.con"); // resource type name.
69 m_configurationInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
70 //m_configurationInterfaces.push_back(BATCH_INTERFACE); // resource interface.
71 //m_configurationInterfaces.push_back(LINK_INTERFACE); // resource interface.
72 m_configurationRep.setValue("loc", m_location);
73 m_configurationRep.setValue("st", m_systemTime);
74 m_configurationRep.setValue("c", m_currency);
75 m_configurationRep.setValue("r", m_region);
76 m_configurationRep.setUri(m_configurationUri);
77 m_configurationRep.setResourceTypes(m_configurationTypes);
78 m_configurationRep.setResourceInterfaces(m_configurationInterfaces);
79 m_configurationHandle = NULL;
83 ~ConfigurationResource()
88 /// This function internally calls registerResource API.
89 void createResources(ResourceEntityHandler callback);
90 void setConfigurationRepresentation(OCRepresentation& rep);
91 OCRepresentation getConfigurationRepresentation();