bc20a71a78902be76dbfdbfc44fe60f5c71c457b
[platform/upstream/iotivity.git] / service / things-manager / sampleapp / linux / configuration / FactorySetCollection.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 #include "ConfigurationCollection.h"
32
33 #pragma once
34
35 using namespace OC;
36
37 typedef std::function< OCEntityHandlerResult(std::shared_ptr< OCResourceRequest > request) > ResourceEntityHandler;
38
39 extern std::string defaultFactorySetValue;
40 static std::string defaultConfigurationCollectionLink = "/factorySet/oic/con";
41
42 static std::string defaultConfigurationURIPrefix = "/factorySet/oic/con";
43 static std::string defaultConfigurationResourceTypePrefix = "factorySet.oic.con";
44
45 class FactorySetCollection
46 {
47 public:
48
49     ConfigurationCollection *defaultConfigurationCollection;
50
51 public:
52
53     // diagnostics members
54     std::string m_factorySetUri;
55     std::string m_factorySetValue;
56     std::vector< std::string > m_factorySetTypes;
57     std::vector< std::string > m_factorySetInterfaces;
58     OCResourceHandle m_factorySetHandle;
59     OCRepresentation m_factorySetRep;
60
61     // Configuration members
62     std::string m_configurationCollectionUri;
63     std::string m_configurationCollectionLink;
64     std::vector< std::string > m_configurationCollectionTypes;
65     std::vector< std::string > m_configurationCollectionInterfaces;
66     OCResourceHandle m_configurationCollectionHandle;
67     OCRepresentation m_configurationCollectionRep;
68
69 public:
70     /// Constructor
71     FactorySetCollection() :
72             m_factorySetValue(defaultFactorySetValue), m_configurationCollectionLink(
73                     defaultConfigurationCollectionLink)
74     {
75         m_configurationCollectionUri = "/factorySet/0/con"; // URI of the resource
76         m_configurationCollectionTypes.push_back("factorySet.con"); // resource type name.
77         m_configurationCollectionInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
78
79         m_configurationCollectionRep.setUri(m_configurationCollectionUri);
80         m_configurationCollectionRep.setResourceTypes(m_configurationCollectionTypes);
81         m_configurationCollectionRep.setResourceInterfaces(m_configurationCollectionInterfaces);
82         m_configurationCollectionRep.setValue("link", m_configurationCollectionLink);
83         m_configurationCollectionHandle = NULL;
84
85         m_factorySetUri = "/factorySet"; // URI of the resource
86         m_factorySetTypes.push_back("factorySet"); // resource type name.
87         m_factorySetInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
88         m_factorySetInterfaces.push_back(BATCH_INTERFACE); // resource interface.
89         m_factorySetInterfaces.push_back(LINK_INTERFACE); // resource interface.
90         m_factorySetRep.setValue("value", m_factorySetValue);
91         m_factorySetRep.setUri(m_factorySetUri);
92         m_factorySetRep.setResourceTypes(m_factorySetTypes);
93         m_factorySetRep.setResourceInterfaces(m_factorySetInterfaces);
94         m_factorySetHandle = NULL;
95
96         defaultConfigurationCollection = NULL;
97     }
98     ;
99
100     ~FactorySetCollection()
101     {
102         if (defaultConfigurationCollection != NULL)
103             free(defaultConfigurationCollection);
104     }
105     ;
106
107     /// This function internally calls registerResource API.
108     void createResources(ResourceEntityHandler callback);
109
110     void setFactorySetRepresentation(OCRepresentation& rep);
111     void setConfigurationCollectionRepresentation(OCRepresentation& rep);
112
113     OCRepresentation getFactorySetRepresentation();
114     OCRepresentation getConfigurationCollectionRepresentation();
115
116     std::string getFactorySetUri();
117     std::string getConfigurationCollectionUri();
118
119 };
120