Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / service / things-manager / sampleapp / linux / configuration / ConfigurationCollection.h
1 //******************************************************************
2 //
3 // Copyright 2014 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 ///
22 /// This sample shows how one could create a resource (collection) with children.
23 ///
24
25 #include <functional>
26 #include <thread>
27
28 #include "OCPlatform.h"
29 #include "OCApi.h"
30
31 #pragma once
32
33 using namespace OC;
34
35 typedef std::function<
36     OCEntityHandlerResult(std::shared_ptr< OCResourceRequest > request) > ResourceEntityHandler;
37
38 static std::string defaultConURI = "/oic/con";
39 static std::string defaultConResourceType = "oic.wk.con";
40
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;
46
47 class ConfigurationResource
48 {
49 public:
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;
56     std::string m_region;
57     std::vector< std::string > m_configurationTypes;
58     std::vector< std::string > m_configurationInterfaces;
59     OCResourceHandle m_configurationHandle;
60     OCRepresentation m_configurationRep;
61
62 public:
63     /// Constructor
64     ConfigurationResource() :
65             m_deviceName(defaultDeviceName), m_location(defaultLocation),
66                 m_locationName(defaultLocationName), m_currency(defaultCurrency),
67                 m_region(defaultRegion)
68     {
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;
81     }
82     ;
83
84     ~ConfigurationResource()
85     {
86
87     }
88
89     /// This function internally calls registerResource API.
90     void createResources(ResourceEntityHandler callback);
91     void setConfigurationRepresentation(OCRepresentation& rep);
92     OCRepresentation getConfigurationRepresentation();
93     std::string getUri();
94
95     void factoryReset();
96
97 };