Imported Upstream version 0.9.1
[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 #include "ThingsManager.h"
31
32 #pragma once
33
34 using namespace OC;
35
36 typedef std::function<
37     OCEntityHandlerResult(std::shared_ptr< OCResourceRequest > request) > ResourceEntityHandler;
38
39 static std::string defaultURIPrefix = "/oic/con";
40 static std::string defaultResourceTypePrefix = "oic.con";
41
42 extern std::string defaultLocation;
43 extern std::string defaultSystemTime;
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_location;
53     std::string m_systemTime;
54     std::string m_currency;
55     std::string m_region;
56     std::vector< std::string > m_configurationTypes;
57     std::vector< std::string > m_configurationInterfaces;
58     OCResourceHandle m_configurationHandle;
59     OCRepresentation m_configurationRep;
60
61 public:
62     /// Constructor
63     ConfigurationResource() :
64             m_location(defaultLocation), m_systemTime(defaultSystemTime), m_currency(
65                     defaultCurrency), m_region(defaultRegion)
66     {
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;
80     }
81     ;
82
83     ~ConfigurationResource()
84     {
85
86     }
87
88     /// This function internally calls registerResource API.
89     void createResources(ResourceEntityHandler callback);
90     void setConfigurationRepresentation(OCRepresentation& rep);
91     OCRepresentation getConfigurationRepresentation();
92     std::string getUri();
93
94     void factoryReset();
95
96 };