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"
36 typedef std::function<
37 OCEntityHandlerResult(std::shared_ptr< OCResourceRequest > request) > ResourceEntityHandler;
39 static std::string defaultFactoryReset = "false";
40 static std::string defaultReboot = "false";
41 static std::string defaultStartStatCollection = "false";
43 class DiagnosticsResource
47 // diagnostics members
48 std::string m_diagnosticsUri;
49 std::string m_factoryReset;
51 std::string m_startStatCollection;
52 std::vector< std::string > m_diagnosticsTypes;
53 std::vector< std::string > m_diagnosticsInterfaces;
54 OCResourceHandle m_diagnosticsHandle;
55 OCRepresentation m_diagnosticsRep;
59 DiagnosticsResource() :
60 m_factoryReset(defaultFactoryReset), m_reboot(defaultReboot),
61 m_startStatCollection(defaultStartStatCollection)
63 m_diagnosticsUri = "/oic/diag"; // URI of the resource
64 m_diagnosticsTypes.push_back("oic.diag"); // resource type name.
65 m_diagnosticsInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
66 m_diagnosticsRep.setValue("fr", m_factoryReset);
67 m_diagnosticsRep.setValue("rb", m_reboot);
68 m_diagnosticsRep.setValue("ssc", m_startStatCollection);
69 m_diagnosticsRep.setUri(m_diagnosticsUri);
70 m_diagnosticsRep.setResourceTypes(m_diagnosticsTypes);
71 m_diagnosticsRep.setResourceInterfaces(m_diagnosticsInterfaces);
72 m_diagnosticsHandle = NULL;
76 /// This function internally calls registerResource API.
77 void createResources(ResourceEntityHandler callback);
79 void setDiagnosticsRepresentation(OCRepresentation& rep);
81 OCRepresentation getDiagnosticsRepresentation();
85 void diagnosticsMonitor(int second);
87 std::function< void() > factoryReset;