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"
35 typedef std::function<
36 OCEntityHandlerResult(std::shared_ptr< OCResourceRequest > request) > ResourceEntityHandler;
38 static std::string defaultConURI = "/oic/con";
39 static std::string defaultConResourceType = "oic.wk.con";
41 extern std::string defaultDeviceName;
42 extern std::string defaultLocation;
43 extern std::string defaultLocationName;
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_deviceName;
53 std::string m_location;
54 std::string m_locationName;
55 std::string m_currency;
57 std::vector< std::string > m_configurationTypes;
58 std::vector< std::string > m_configurationInterfaces;
59 OCResourceHandle m_configurationHandle;
60 OCRepresentation m_configurationRep;
64 ConfigurationResource() :
65 m_deviceName(defaultDeviceName), m_location(defaultLocation),
66 m_locationName(defaultLocationName), m_currency(defaultCurrency),
67 m_region(defaultRegion)
69 m_configurationUri = defaultConURI; // URI of the resource
70 m_configurationTypes.push_back(defaultConResourceType); // resource type name.
71 m_configurationInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
72 m_configurationRep.setValue("st", m_deviceName);
73 m_configurationRep.setValue("loc", m_location);
74 m_configurationRep.setValue("locn", m_locationName);
75 m_configurationRep.setValue("c", m_currency);
76 m_configurationRep.setValue("r", m_region);
77 m_configurationRep.setUri(m_configurationUri);
78 m_configurationRep.setResourceTypes(m_configurationTypes);
79 m_configurationRep.setResourceInterfaces(m_configurationInterfaces);
80 m_configurationHandle = NULL;
84 ~ConfigurationResource()
89 /// This function internally calls registerResource API.
90 void createResources(ResourceEntityHandler callback);
91 void setConfigurationRepresentation(OCRepresentation& rep);
92 OCRepresentation getConfigurationRepresentation();