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.
29 #include "OCPlatform.h"
31 #include "MaintenanceCollection.h"
36 /// This function internally calls registerResource API.
37 void MaintenanceResource::createResources(ResourceEntityHandler callback)
39 using namespace OC::OCPlatform;
43 std::cout << "callback should be binded\t";
47 // This will internally create and register the resource.
48 OCStackResult result = registerResource(m_maintenanceHandle, m_maintenanceUri,
49 m_maintenanceTypes[0], m_maintenanceInterfaces[0], callback,
50 OC_DISCOVERABLE | OC_OBSERVABLE);
52 if (OC_STACK_OK != result)
54 std::cout << "Resource creation (maintenance) was unsuccessful\n";
58 std::function< void(int second) >(
59 std::bind(&MaintenanceResource::maintenanceMonitor, this,
60 std::placeholders::_1)), 10); // every 10 seconds
63 std::cout << "maintenance Resource is Created!\n";
66 void MaintenanceResource::setMaintenanceRepresentation(OCRepresentation& rep)
70 if (rep.getValue("fr", value))
72 m_factoryReset = value;
73 std::cout << "\t\t\t\t" << "m_factoryReset: " << m_factoryReset << std::endl;
76 if (rep.getValue("rb", value))
79 std::cout << "\t\t\t\t" << "m_reboot: " << m_reboot << std::endl;
82 if (rep.getValue("ssc", value))
84 m_startStatCollection = value;
85 std::cout << "\t\t\t\t" << "m_startStatCollection: " << m_startStatCollection << std::endl;
89 OCRepresentation MaintenanceResource::getMaintenanceRepresentation()
91 m_maintenanceRep.setValue("fr", m_factoryReset);
92 m_maintenanceRep.setValue("rb", m_reboot);
93 m_maintenanceRep.setValue("ssc", m_startStatCollection);
95 return m_maintenanceRep;
98 std::string MaintenanceResource::getUri()
100 return m_maintenanceUri;
103 void MaintenanceResource::maintenanceMonitor(int second)
109 if (m_reboot == "true")
112 std::cout << "Reboot will be soon..." << std::endl;
113 m_reboot = defaultReboot;
114 res = system("sudo reboot"); // System reboot
116 std::cout << "return: " << res << std::endl;
119 else if (m_factoryReset == "true")
121 std::cout << "Factory Reset will be soon..." << std::endl;
122 m_factoryReset = defaultFactoryReset;