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< OCEntityHandlerResult(std::shared_ptr< OCResourceRequest > request) > ResourceEntityHandler;
38 static std::string defaultDiagnosticsValue = "false";
39 static std::string defaultFactoryReset = "false";
40 static std::string defaultReboot = "false";
41 static std::string defaultStartCollection = "false";
43 class DiagnosticsCollection
47 // diagnostics members
48 std::string m_diagnosticsUri;
49 std::string m_diagnosticsValue;
50 std::vector< std::string > m_diagnosticsTypes;
51 std::vector< std::string > m_diagnosticsInterfaces;
52 OCResourceHandle m_diagnosticsHandle;
53 OCRepresentation m_diagnosticsRep;
55 // factory reset members
56 std::string m_factoryResetUri;
57 std::string m_factoryResetValue;
58 std::vector< std::string > m_factoryResetTypes;
59 std::vector< std::string > m_factoryResetInterfaces;
60 OCResourceHandle m_factoryResetHandle;
61 OCRepresentation m_factoryResetRep;
64 std::string m_rebootUri;
65 std::string m_rebootValue;
66 std::vector< std::string > m_rebootTypes;
67 std::vector< std::string > m_rebootInterfaces;
68 OCResourceHandle m_rebootHandle;
69 OCRepresentation m_rebootRep;
71 // startcollection members
72 std::string m_startCollectionUri;
73 std::string m_startCollectionValue;
74 std::vector< std::string > m_startCollectionTypes;
75 std::vector< std::string > m_startCollectionInterfaces;
76 OCResourceHandle m_startCollectionHandle;
77 OCRepresentation m_startCollectionRep;
81 DiagnosticsCollection() :
82 m_diagnosticsValue(defaultDiagnosticsValue), m_factoryResetValue(defaultFactoryReset), m_rebootValue(
83 defaultReboot), m_startCollectionValue(defaultStartCollection)
85 m_factoryResetUri = "/oic/diag/0/factoryReset"; // URI of the resource
86 m_factoryResetTypes.push_back("oic.diag.factoryReset"); // resource type name.
87 m_factoryResetInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
89 m_factoryResetRep.setUri(m_factoryResetUri);
90 m_factoryResetRep.setResourceTypes(m_factoryResetTypes);
91 m_factoryResetRep.setResourceInterfaces(m_factoryResetInterfaces);
92 m_factoryResetRep.setValue("value", m_factoryResetValue);
93 m_factoryResetHandle = NULL;
95 m_rebootUri = "/oic/diag/0/reboot"; // URI of the resource
96 m_rebootTypes.push_back("oic.diag.reboot"); // resource type name.
97 m_rebootInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
99 m_rebootRep.setUri(m_rebootUri);
100 m_rebootRep.setResourceTypes(m_rebootTypes);
101 m_rebootRep.setResourceInterfaces(m_rebootInterfaces);
102 m_rebootRep.setValue("value", m_rebootValue);
103 m_rebootHandle = NULL;
105 m_startCollectionUri = "/oic/diag/0/startCollection"; // URI of the resource
106 m_startCollectionTypes.push_back("oic.diag.startCollection"); // resource type name.
107 m_startCollectionInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
109 m_startCollectionRep.setUri(m_startCollectionUri);
110 m_startCollectionRep.setResourceTypes(m_startCollectionTypes);
111 m_startCollectionRep.setResourceInterfaces(m_startCollectionInterfaces);
112 m_startCollectionRep.setValue("value", m_startCollectionValue);
113 m_startCollectionHandle = NULL;
115 m_diagnosticsUri = "/oic/diag"; // URI of the resource
116 m_diagnosticsTypes.push_back("oic.diag"); // resource type name.
117 m_diagnosticsInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
118 m_diagnosticsInterfaces.push_back(BATCH_INTERFACE); // resource interface.
119 m_diagnosticsInterfaces.push_back(LINK_INTERFACE); // resource interface.
120 m_diagnosticsRep.setValue("value", m_diagnosticsValue);
121 m_diagnosticsRep.setUri(m_diagnosticsUri);
122 m_diagnosticsRep.setResourceTypes(m_diagnosticsTypes);
123 m_diagnosticsRep.setResourceInterfaces(m_diagnosticsInterfaces);
124 m_diagnosticsHandle = NULL;
128 /// This function internally calls registerResource API.
129 void createResources(ResourceEntityHandler callback);
131 void setDiagnosticsRepresentation(OCRepresentation& rep);
132 void setFactoryResetRepresentation(OCRepresentation& rep);
133 void setRebootRepresentation(OCRepresentation& rep);
134 void setStartCollectionRepresentation(OCRepresentation& rep);
136 OCRepresentation getDiagnosticsRepresentation();
137 OCRepresentation getFactoryResetRepresentation();
138 OCRepresentation getRebootRepresentation();
139 OCRepresentation getStartCollectionRepresentation();
141 std::string getDiagnosticsUri();
142 std::string getFactoryResetUri();
143 std::string getRebootUri();
144 std::string getStartCollectionUri();
146 void diagnosticsMonitor(int second);
148 std::function< void() > factoryReset;