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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
24 * This file contains the declaration of classes and its members related to
28 #ifndef __OC_THINGSDIAGNOSTICS__
29 #define __OC_THINGSDIAGNOSTICS__
35 #include "OCPlatform.h"
37 #include "GroupManager.h"
42 /// Declearation of Diagnostics Callback funtion type
43 typedef std::function<
44 void(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
45 > DiagnosticsCallback;
49 * The following class is used as a item stacking in request queue. The class stores a request
50 * and referential information (e.g., a diagnostics name, a target resource object, a callback
51 * function passed from the applications, and a update value). When the function for updating/
52 * getting diagnostics value is called from applications, this class instance is created and
53 * stored in the request queue. The queue is maintained in a std::map structure so if desiring
54 * to find a specific request, you can find it by querying a diagnostics name.
56 class DiagnosticsRequestEntry
59 DiagnosticsRequestEntry(std::string ID, DiagnosticsCallback callback,
60 std::shared_ptr< OCResource > resource, std::string updateVal);
62 // Diagnostics Name (used in key value in std::map structure)
63 // e.g., reboot and factoryset
66 // Reference callback pointer
67 DiagnosticsCallback m_callback;
69 // Reference resource object
70 std::shared_ptr< OCResource > m_resource;
72 // Update value only used for diagnostics update (always "true")
73 std::string m_updateVal;
78 * The following class is used to store providing diagnostics name and its relevant information
79 * The relevant information includes a brief description, uri, and attribute key.
80 * Note that a developer only specifies a diagnostics name, not URI nor attribute key, to
81 * update a value to a remote. Thus, using diagnostics name, we convert it to more specific
82 * information (i.e. uri and attribute key) to send a request. This class is reponsible to
83 * storing these information.
85 class DiagnosticsUnitInfo
89 std::string m_attribute;
92 DiagnosticsUnitInfo(std::string name, std::string attribute, std::string uri);
94 // If a developer wants to know a list of configuration names, gives it in JSON format.
95 std::string getJSON();
99 typedef std::string DiagnosticsName;
100 typedef std::string DiagnosticsValue;
102 class ThingsDiagnostics
106 * Constructor for ThingsDiagnostics. Constructs a new ThingsDiagnostics
108 ThingsDiagnostics(void);
113 ~ThingsDiagnostics(void);
115 static ThingsDiagnostics *thingsDiagnosticsInstance;
116 static ThingsDiagnostics* getInstance();
117 void deleteInstance();
119 void setGroupManager(GroupManager *groupmanager);
122 * API to make things reboot
123 * Callback call when a response arrives.
125 * @param resource - resource pointer representing the target group
126 * @param callback - callback.
128 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
130 * NOTE: OCStackResult is defined in ocstack.h.
132 OCStackResult reboot(std::shared_ptr< OCResource > resource, DiagnosticsCallback callback);
135 * API for factory reset on device
136 * Callback call when a response arrives.
138 * @param resource - resource pointer representing the target group
139 * @param callback - callback.
141 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
143 * NOTE: OCStackResult is defined in ocstack.h.
146 OCStackResult factoryReset(std::shared_ptr< OCResource > resource,
147 DiagnosticsCallback callback);
150 * API to show a list of supported diagnostics units
151 * Callback call when a response arrives.
153 * @return the list in JSON format
155 std::string getListOfSupportedDiagnosticsUnits();
159 GroupManager *g_groupmanager;
161 std::vector< DiagnosticsUnitInfo > DiagnosticsUnitTable;
163 void onExecuteForGroupAction(const HeaderOptions& headerOptions,
164 const OCRepresentation& rep, const int eCode, std::string conf);
165 void onDeleteGroupAction(const HeaderOptions& headerOptions,
166 const OCRepresentation& rep, const int eCode, std::string conf);
167 void onGetChildInfoForUpdate(const HeaderOptions& headerOptions,
168 const OCRepresentation& rep, const int eCode, std::string conf);
169 void onCreateActionSet(const HeaderOptions& headerOptions, const OCRepresentation& rep,
170 const int eCode, std::string conf);
171 void onGet(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode,
173 void onPut(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode,
176 std::shared_ptr< OCResource > getResource(std::string conf);
177 DiagnosticsCallback getCallback(std::string conf);
178 std::string getUpdateVal(std::string conf);
179 std::string getAttributeByDiagnosticsName(DiagnosticsName name);
180 std::string getUriByDiagnosticsName(DiagnosticsName name);
182 std::string getHostFromURI(std::string oldUri);
184 bool isSimpleResource(std::shared_ptr< OCResource > resource);
188 #endif /* __OC_THINGSCONFIGURATION__*/