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_THINGSMAINTENANCE__
29 #define __OC_THINGSMAINTENANCE__
35 #include "OCPlatform.h"
37 #include "GroupManager.h"
42 /// Declearation of Maintenance Callback funtion type
43 typedef std::function<
44 void(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
45 > MaintenanceCallback;
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 maintenance name, a target resource object, a callback
51 * function passed from the applications, and a update value). When the function for updating/
52 * getting maintenance 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 maintenance name.
56 class MaintenanceRequestEntry
59 MaintenanceRequestEntry(std::string ID, MaintenanceCallback callback,
60 std::shared_ptr< OCResource > resource, std::string updateVal);
62 // Maintenance Name (used in key value in std::map structure)
63 // e.g., reboot and factoryset
66 // Reference callback pointer
67 MaintenanceCallback m_callback;
69 // Reference resource object
70 std::shared_ptr< OCResource > m_resource;
72 // Update value only used for maintenance update (always "true")
73 std::string m_updateVal;
78 * The following class is used to store providing maintenance 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 maintenance name, not URI nor attribute key, to
81 * update a value to a remote. Thus, using maintenance 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 MaintenanceUnitInfo
89 std::string m_attribute;
92 MaintenanceUnitInfo(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 MaintenanceName;
100 typedef std::string MaintenanceValue;
102 class ThingsMaintenance
106 * Constructor for ThingsMaintenance. Constructs a new ThingsMaintenance
108 ThingsMaintenance(void);
113 ~ThingsMaintenance(void);
115 static ThingsMaintenance *thingsMaintenanceInstance;
116 static ThingsMaintenance* getInstance();
119 void deleteInstance();
120 void setGroupManager(GroupManager *groupmanager);
123 * API to make things reboot
124 * Callback call when a response arrives.
126 * @param resource - resource pointer representing the target group
127 * @param callback - callback.
129 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
131 * NOTE: OCStackResult is defined in ocstack.h.
133 OCStackResult reboot(std::shared_ptr< OCResource > resource, MaintenanceCallback callback);
136 * API for factory reset on device
137 * Callback call when a response arrives.
139 * @param resource - resource pointer representing the target group
140 * @param callback - callback.
142 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
144 * NOTE: OCStackResult is defined in ocstack.h.
147 OCStackResult factoryReset(std::shared_ptr< OCResource > resource,
148 MaintenanceCallback callback);
151 * API to show a list of supported maintenance units
152 * Callback call when a response arrives.
154 * @return the list in JSON format
156 std::string getListOfSupportedMaintenanceUnits();
160 GroupManager *g_groupmanager;
162 std::vector< MaintenanceUnitInfo > MaintenanceUnitTable;
164 void onExecuteForGroupAction(const HeaderOptions& headerOptions,
165 const OCRepresentation& rep, const int eCode, std::string conf);
166 void onDeleteGroupAction(const HeaderOptions& headerOptions,
167 const OCRepresentation& rep, const int eCode, std::string conf);
168 void onGetChildInfoForUpdate(const HeaderOptions& headerOptions,
169 const OCRepresentation& rep, const int eCode, std::string conf);
170 void onCreateActionSet(const HeaderOptions& headerOptions, const OCRepresentation& rep,
171 const int eCode, std::string conf);
172 void onGet(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode,
174 void onPut(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode,
177 std::shared_ptr< OCResource > getResource(std::string conf);
178 MaintenanceCallback getCallback(std::string conf);
179 std::string getUpdateVal(std::string conf);
180 std::string getAttributeByMaintenanceName(MaintenanceName name);
181 std::string getUriByMaintenanceName(MaintenanceName name);
183 std::string getHostFromURI(std::string oldUri);
185 bool isSimpleResource(std::shared_ptr< OCResource > resource);
189 #endif /* __OC_THINGSCONFIGURATION__*/