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"
31 #include "ConfigurationCollection.h"
37 typedef std::function< OCEntityHandlerResult(std::shared_ptr< OCResourceRequest > request) > ResourceEntityHandler;
39 extern std::string defaultFactorySetValue;
40 static std::string defaultConfigurationCollectionLink = "/factorySet/oic/con";
42 static std::string defaultConfigurationURIPrefix = "/factorySet/oic/con";
43 static std::string defaultConfigurationResourceTypePrefix = "factorySet.oic.con";
45 class FactorySetCollection
49 ConfigurationCollection *defaultConfigurationCollection;
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;
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;
71 FactorySetCollection() :
72 m_factorySetValue(defaultFactorySetValue), m_configurationCollectionLink(
73 defaultConfigurationCollectionLink)
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.
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;
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;
96 defaultConfigurationCollection = NULL;
100 ~FactorySetCollection()
102 if (defaultConfigurationCollection != NULL)
103 free(defaultConfigurationCollection);
107 /// This function internally calls registerResource API.
108 void createResources(ResourceEntityHandler callback);
110 void setFactorySetRepresentation(OCRepresentation& rep);
111 void setConfigurationCollectionRepresentation(OCRepresentation& rep);
113 OCRepresentation getFactorySetRepresentation();
114 OCRepresentation getConfigurationCollectionRepresentation();
116 std::string getFactorySetUri();
117 std::string getConfigurationCollectionUri();