Remove a Things Manager class and expose its component classes for SDK
[platform/upstream/iotivity.git] / service / things-manager / sdk / inc / ThingsMaintenance.h
1 //******************************************************************
2 //
3 // Copyright 2014 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 /**
22  * @file
23  *
24  * This file contains the declaration of classes and its members related to
25  * ThingsMaintenance.
26  */
27
28 #ifndef __OC_THINGSMAINTENANCE__
29 #define __OC_THINGSMAINTENANCE__
30
31 #include <string>
32 #include <vector>
33 #include <map>
34 #include <cstdlib>
35 #include "OCPlatform.h"
36 #include "OCApi.h"
37 #include "GroupManager.h"
38
39 using namespace OC;
40 namespace OIC
41 {
42     /// Declearation of Maintenance Callback funtion type
43     typedef std::function<
44             void(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
45             > MaintenanceCallback;
46
47     /**
48      *  @brief
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.
55      */
56     class MaintenanceRequestEntry
57     {
58     public:
59         MaintenanceRequestEntry(std::string ID, MaintenanceCallback callback,
60                 std::shared_ptr< OCResource > resource, std::string updateVal);
61
62         // Maintenance Name (used in key value in std::map structure)
63         // e.g., reboot and factoryset
64         std::string m_ID;
65
66         // Reference callback pointer
67         MaintenanceCallback m_callback;
68
69         // Reference resource object
70         std::shared_ptr< OCResource > m_resource;
71
72         // Update value only used for maintenance update (always "true")
73         std::string m_updateVal;
74     };
75
76     /**
77      *  @brief
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.
84      */
85     class MaintenanceUnitInfo
86     {
87     public:
88         std::string m_name;
89         std::string m_attribute;
90         std::string m_uri;
91
92         MaintenanceUnitInfo(std::string name, std::string attribute, std::string uri);
93
94         // If a developer wants to know a list of configuration names, gives it in JSON format.
95         std::string getJSON();
96     };
97
98 #define NUMDIAGUNIT 3
99     typedef std::string MaintenanceName;
100     typedef std::string MaintenanceValue;
101
102     class ThingsMaintenance
103     {
104     public:
105         /**
106          * Constructor for ThingsMaintenance. Constructs a new ThingsMaintenance
107          */
108         ThingsMaintenance(void);
109
110         /**
111          * Virtual destructor
112          */
113         ~ThingsMaintenance(void);
114
115         static ThingsMaintenance *thingsMaintenanceInstance;
116         static ThingsMaintenance* getInstance();
117
118         // TODO: deprecated
119         void deleteInstance();
120         void setGroupManager(GroupManager *groupmanager);
121
122         /**
123          * API to make things reboot
124          * Callback call when a response arrives.
125          *
126          * @param resource - resource pointer representing the target group
127          * @param callback - callback.
128          *
129          * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
130          *
131          * NOTE: OCStackResult is defined in ocstack.h.
132          */
133         OCStackResult reboot(std::shared_ptr< OCResource > resource, MaintenanceCallback callback);
134
135         /**
136          * API for factory reset on device
137          * Callback call when a response arrives.
138          *
139          * @param resource - resource pointer representing the target group
140          * @param callback - callback.
141          *
142          * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
143          *
144          * NOTE: OCStackResult is defined in ocstack.h.
145          */
146
147         OCStackResult factoryReset(std::shared_ptr< OCResource > resource,
148                 MaintenanceCallback callback);
149
150         /**
151          * API to show a list of supported maintenance units
152          * Callback call when a response arrives.
153          *
154          * @return the list in JSON format
155          */
156         std::string getListOfSupportedMaintenanceUnits();
157
158     private:
159
160         GroupManager *g_groupmanager;
161
162         std::vector< MaintenanceUnitInfo > MaintenanceUnitTable;
163
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,
173                 std::string conf);
174         void onPut(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode,
175                 std::string conf);
176
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);
182
183         std::string getHostFromURI(std::string oldUri);
184
185         bool isSimpleResource(std::shared_ptr< OCResource > resource);
186
187     };
188 }
189 #endif  /* __OC_THINGSCONFIGURATION__*/