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"
26 #include "OCPlatform.h"
28 #include "ThingsManager.h"
32 FactorySetResource::FactorySetResource()
34 m_configurationUri = "/factorySet"; // URI of the resource
35 m_configurationTypes.clear();
36 m_configurationTypes.push_back("factorySet"); // resource type name.
37 m_configurationRep.setUri(m_configurationUri);
38 m_configurationRep.setResourceTypes(m_configurationTypes);
41 FactorySetResource::~FactorySetResource() {}
43 // This function internally calls registerResource API.
44 void FactorySetResource::createResource(ResourceEntityHandler callback)
46 using namespace OC::OCPlatform;
50 dlog_print(DLOG_INFO, "FactorySetResource", "#### Callback should be binded");
54 // This will internally create and register the resource
55 OCStackResult result = registerResource(m_configurationHandle, m_configurationUri,
56 m_configurationTypes[0], m_configurationInterfaces[0],
57 callback, OC_DISCOVERABLE | OC_OBSERVABLE);
59 if (OC_STACK_OK != result)
61 dlog_print(DLOG_INFO, "FactorySetResource", "#### Resource creation"
62 "(configuration) was unsuccessful");
66 dlog_print(DLOG_INFO, "FactorySetResource", "#### Configuration Resource is Created");
69 void FactorySetResource::setFactorySetRepresentation(OCRepresentation &rep)
73 if (rep.getValue("loc", value))
76 dlog_print(DLOG_INFO, "FactorySetResource", "#### m_location: %s",
80 if (rep.getValue("st", value))
82 dlog_print(DLOG_INFO, "FactorySetResource", "#### SystemTime is not"
83 "allowed to be written");
86 if (rep.getValue("c", value))
89 dlog_print(DLOG_INFO, "FactorySetResource", "#### m_currency: %s",
93 if (rep.getValue("r", value))
96 dlog_print(DLOG_INFO, "FactorySetResource", "#### m_region: %s",
101 OCRepresentation FactorySetResource::getFactorySetRepresentation()
103 m_configurationRep.setValue("loc", m_location);
104 m_configurationRep.setValue("st", m_systemTime);
105 m_configurationRep.setValue("c", m_currency);
106 m_configurationRep.setValue("r", m_region);
108 return m_configurationRep;
111 std::string FactorySetResource::getUri()
113 return m_configurationUri;
116 // Deletes the factoryset resource which has been created using createResource()
117 void FactorySetResource::deleteResource()
119 // Unregister the Configuration resource
120 if (NULL != m_configurationHandle)
122 OCPlatform::unregisterResource(m_configurationHandle);