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 "DiagnosticsCollection.h"
35 /// This function internally calls registerResource API.
36 void DiagnosticsResource::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_diagnosticsHandle, m_diagnosticsUri,
48 m_diagnosticsTypes[0], m_diagnosticsInterfaces[0], callback,
49 OC_DISCOVERABLE | OC_OBSERVABLE);
51 if (OC_STACK_OK != result)
53 std::cout << "Resource creation (diagnostics) was unsuccessful\n";
57 std::function< void(int second) >(
58 std::bind(&DiagnosticsResource::diagnosticsMonitor, this,
59 std::placeholders::_1)), 10); // every 10 seconds
62 std::cout << "Diagnostics Resource is Created!\n";
65 void DiagnosticsResource::setDiagnosticsRepresentation(OCRepresentation& rep)
69 if (rep.getValue("fr", value))
71 m_factoryReset = value;
72 std::cout << "\t\t\t\t" << "m_factoryReset: " << m_factoryReset << std::endl;
75 if (rep.getValue("rb", value))
78 std::cout << "\t\t\t\t" << "m_reboot: " << m_reboot << std::endl;
81 if (rep.getValue("ssc", value))
83 m_startStatCollection = value;
84 std::cout << "\t\t\t\t" << "m_startStatCollection: " << m_startStatCollection << std::endl;
88 OCRepresentation DiagnosticsResource::getDiagnosticsRepresentation()
90 m_diagnosticsRep.setValue("fr", m_factoryReset);
91 m_diagnosticsRep.setValue("rb", m_reboot);
92 m_diagnosticsRep.setValue("ssc", m_startStatCollection);
94 return m_diagnosticsRep;
97 std::string DiagnosticsResource::getUri()
99 return m_diagnosticsUri;
102 void DiagnosticsResource::diagnosticsMonitor(int second)
108 if (m_reboot == "true")
111 std::cout << "Reboot will be soon..." << std::endl;
112 m_reboot = defaultReboot;
113 res = system("sudo reboot"); // System reboot
115 std::cout << "return: " << res << std::endl;
118 else if (m_factoryReset == "true")
120 std::cout << "Factory Reset will be soon..." << std::endl;
121 m_factoryReset = defaultFactoryReset;