1 /******************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
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 ******************************************************************/
21 #include "factorysetresource.h"
27 #include "OCPlatform.h"
29 #include "configurationresource.h"
33 FactorySetResource::FactorySetResource()
35 m_configurationUri = "/factoryset"; // URI of the resource
36 m_configurationTypes.clear();
37 m_configurationTypes.push_back("factoryset"); // resource type name.
38 m_configurationRep.setUri(m_configurationUri);
39 m_configurationRep.setResourceTypes(m_configurationTypes);
42 FactorySetResource::~FactorySetResource() {}
44 // This function internally calls registerResource API.
45 void FactorySetResource::createResource(ResourceEntityHandler callback)
47 using namespace OC::OCPlatform;
51 dlog_print(DLOG_INFO, "FactorySetResource", "#### Callback should be binded");
55 // This will internally create and register the resource
56 OCStackResult result = registerResource(m_configurationHandle, m_configurationUri,
57 m_configurationTypes[0], m_configurationInterfaces[0],
58 callback, OC_DISCOVERABLE | OC_OBSERVABLE);
60 if (OC_STACK_OK != result)
62 dlog_print(DLOG_INFO, "FactorySetResource", "#### Resource creation"
63 "(configuration) was unsuccessful");
67 dlog_print(DLOG_INFO, "FactorySetResource", "#### Configuration Resource is Created");
70 void FactorySetResource::setFactorySetRepresentation(OCRepresentation &rep)
74 if (rep.getValue(DEFAULT_DEVICENAME, value))
77 dlog_print(DLOG_INFO, "FactorySetResource", "#### m_deviceName: %s",
78 m_deviceName.c_str());
81 if (rep.getValue(DEFAULT_LOCATION, value))
84 dlog_print(DLOG_INFO, "FactorySetResource", "#### m_location: %s",
88 if (rep.getValue(DEFAULT_LOCATIONNAME, value))
90 m_locationName = value;
91 dlog_print(DLOG_INFO, "FactorySetResource", "#### m_locationName: %s",
92 m_locationName.c_str());
95 if (rep.getValue(DEFAULT_CURRENCY, value))
98 dlog_print(DLOG_INFO, "FactorySetResource", "#### m_currency: %s",
102 if (rep.getValue(DEFAULT_REGION, value))
105 dlog_print(DLOG_INFO, "FactorySetResource", "#### m_region: %s",
110 OCRepresentation FactorySetResource::getFactorySetRepresentation()
112 m_configurationRep.setValue(DEFAULT_DEVICENAME, m_deviceName);
113 m_configurationRep.setValue(DEFAULT_LOCATION, m_location);
114 m_configurationRep.setValue(DEFAULT_LOCATIONNAME, m_locationName);
115 m_configurationRep.setValue(DEFAULT_CURRENCY, m_currency);
116 m_configurationRep.setValue(DEFAULT_REGION, m_region);
118 return m_configurationRep;
121 std::string FactorySetResource::getUri()
123 return m_configurationUri;
126 // Deletes the factoryset resource which has been created using createResource()
127 void FactorySetResource::deleteResource()
129 // Unregister the Configuration resource
130 if (NULL != m_configurationHandle)
132 OCPlatform::unregisterResource(m_configurationHandle);