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 "configurationresource.h"
26 #include "OCPlatform.h"
28 #include "ThingsManager.h"
33 ConfigurationResource::ConfigurationResource() :
34 m_location(defaultLocation), m_systemTime(defaultSystemTime), m_currency(
35 defaultCurrency), m_region(defaultRegion)
37 m_configurationUri = "/oic/con"; // URI of the resource
38 m_configurationTypes.push_back("oic.con"); // resource type name
39 m_configurationInterfaces.push_back(DEFAULT_INTERFACE); // resource interface
40 m_configurationRep.setValue("loc", m_location);
41 m_configurationRep.setValue("st", m_systemTime);
42 m_configurationRep.setValue("c", m_currency);
43 m_configurationRep.setValue("r", m_region);
44 m_configurationRep.setUri(m_configurationUri);
45 m_configurationRep.setResourceTypes(m_configurationTypes);
46 m_configurationRep.setResourceInterfaces(m_configurationInterfaces);
47 m_configurationHandle = NULL;
50 // Creates a ConfigurationResource
51 void ConfigurationResource::createResource(ResourceEntityHandler callback)
53 using namespace OC::OCPlatform;
57 dlog_print(DLOG_INFO, "ConfigurationResource", "#### Callback should be binded");
61 // This will internally create and register the resource
62 OCStackResult result = registerResource(m_configurationHandle, m_configurationUri,
63 m_configurationTypes[0], m_configurationInterfaces[0],
64 callback, OC_DISCOVERABLE | OC_OBSERVABLE);
66 if (OC_STACK_OK != result)
68 dlog_print(DLOG_INFO, "ConfigurationResource", "#### Resource creation"
69 "(configuration) was unsuccessful");
73 dlog_print(DLOG_INFO, "ConfigurationResource", "#### Configuration Resource is Created");
76 void ConfigurationResource::setConfigurationRepresentation(OCRepresentation &rep)
80 if (rep.getValue("loc", value))
83 dlog_print(DLOG_INFO, "ConfigurationResource", "#### m_location: %s",
87 if (rep.getValue("st", value))
89 dlog_print(DLOG_INFO, "ConfigurationResource", "#### SystemTime is not"
90 "allowed to be written");
93 if (rep.getValue("c", value))
96 dlog_print(DLOG_INFO, "ConfigurationResource", "#### m_currency: %s",
100 if (rep.getValue("r", value))
103 dlog_print(DLOG_INFO, "ConfigurationResource", "#### m_region: %s",
108 OCRepresentation ConfigurationResource::getConfigurationRepresentation()
110 m_configurationRep.setValue("loc", m_location);
111 m_configurationRep.setValue("st", m_systemTime);
112 m_configurationRep.setValue("c", m_currency);
113 m_configurationRep.setValue("r", m_region);
115 return m_configurationRep;
118 std::string ConfigurationResource::getUri()
120 return m_configurationUri;
123 // Assigns default values to all the attributes of the configuration resource
124 void ConfigurationResource::factoryReset()
126 m_location = defaultLocation;
127 m_systemTime = defaultSystemTime;
128 m_currency = defaultCurrency;
129 m_region = defaultRegion;
132 // Deletes the configuration resource which has been created using createResource()
133 void ConfigurationResource::deleteResource()
135 // Unregister the resource
136 if (NULL != m_configurationHandle)
138 OCPlatform::unregisterResource(m_configurationHandle);