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 "FactorySetCollection.h"
35 /// This function internally calls registerResource API.
36 void FactorySetCollection::createResources(ResourceEntityHandler callback)
38 using namespace OC::OCPlatform;
42 std::cout << "callback should be binded\t";
46 // This will internally create and register the resource.
47 OCStackResult result = registerResource(m_factorySetHandle, m_factorySetUri,
48 m_factorySetTypes[0], m_factorySetInterfaces[0], callback,
49 OC_DISCOVERABLE | OC_OBSERVABLE);
51 if (OC_STACK_OK != result)
53 std::cout << "Resource creation (configuration) was unsuccessful\n";
56 result = bindInterfaceToResource(m_factorySetHandle, m_factorySetInterfaces[1]);
57 if (OC_STACK_OK != result)
59 std::cout << "Binding TypeName to Resource was unsuccessful\n";
62 result = bindInterfaceToResource(m_factorySetHandle, m_factorySetInterfaces[2]);
63 if (OC_STACK_OK != result)
65 std::cout << "Binding TypeName to Resource was unsuccessful\n";
68 result = registerResource(m_configurationCollectionHandle, m_configurationCollectionUri,
69 m_configurationCollectionTypes[0], m_configurationCollectionInterfaces[0], callback,
70 OC_DISCOVERABLE | OC_OBSERVABLE);
72 if (OC_STACK_OK != result)
74 std::cout << "Resource creation (installedLocation) was unsuccessful\n";
77 result = bindResource(m_factorySetHandle, m_configurationCollectionHandle);
78 if (OC_STACK_OK != result)
80 std::cout << "Binding installedLocation resource to room was unsuccessful\n";
83 defaultConfigurationCollection = new ConfigurationCollection(defaultConfigurationURIPrefix,
84 defaultConfigurationResourceTypePrefix);
85 //defaultConfigurationCollection->bindEntityHander(callback);
86 defaultConfigurationCollection->createResources(callback);
88 std::cout << "FactorySet Collection is Created!\n";
91 void FactorySetCollection::setFactorySetRepresentation(OCRepresentation& rep)
95 if (rep.getValue("value", value))
97 m_factorySetValue = value;
99 std::cout << "\t\t\t\t" << "m_factorySetValue: " << m_factorySetValue << std::endl;
103 void FactorySetCollection::setConfigurationCollectionRepresentation(OCRepresentation& rep)
107 if (rep.getValue("link", value))
111 std::cout << "\t\t\t\t" << "link: " << m_configurationCollectionLink << std::endl;
115 OCRepresentation FactorySetCollection::getConfigurationCollectionRepresentation()
117 m_configurationCollectionRep.setValue("link", m_configurationCollectionLink);
119 return m_configurationCollectionRep;
122 OCRepresentation FactorySetCollection::getFactorySetRepresentation()
124 m_factorySetRep.clearChildren();
126 m_factorySetRep.addChild(getConfigurationCollectionRepresentation());
128 m_factorySetRep.setValue("value", m_factorySetValue);
130 return m_factorySetRep;
133 std::string FactorySetCollection::getFactorySetUri()
135 return m_factorySetUri;
138 std::string FactorySetCollection::getConfigurationCollectionUri()
140 return m_configurationCollectionUri;