Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / service / simulator / inc / simulator_remote_resource.h
1 /******************************************************************
2  *
3  * Copyright 2015 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 simulator_remote_resource.h
23  *
24  * @brief This file provides a class for handling discovered resources.
25  *
26  */
27
28 #ifndef SIMULATOR_REMOTE_RESOURCE_H_
29 #define SIMULATOR_REMOTE_RESOURCE_H_
30
31 #include "simulator_client_types.h"
32 #include "simulator_resource_model.h"
33 #include "simulator_request_model.h"
34 #include "simulator_uncopyable.h"
35 #include "simulator_exceptions.h"
36
37 /**
38  * @class   SimulatorRemoteResource
39  * @brief   This class provides a API for handling discovered resources.
40  */
41 class SimulatorRemoteResource : private UnCopyable
42 {
43     public:
44
45         /**
46          * Callback method for receiving response for GET, PUT and POST requests.
47          *
48          * @param uid - Identifier of remote resource.
49          * @param result - Result of the request mapped to one of the enum value
50          * in @SimulatorResult.
51          * @param resModel - Resource representation model.
52          */
53         typedef std::function<void (const std::string &uid, SimulatorResult result,
54                                     const SimulatorResourceModel &resModel)>
55         ResponseCallback;
56
57         typedef ResponseCallback GetResponseCallback;
58         typedef ResponseCallback PutResponseCallback;
59         typedef ResponseCallback PostResponseCallback;
60         typedef ResponseCallback DeleteResponseCallback;
61
62         /**
63          * Callback method for receiving representation change notifications from remote resource.
64          *
65          * @param uid - Identifier of remote resource.
66          * @param result - Result of the request mapped to one of the enum value
67          * in @SimulatorResult.
68          * @param resModel - Resource representation model.
69          * @param id - Notificaiton sequence id.
70          */
71         typedef std::function<void (const std::string &uid, SimulatorResult result,
72                                     const SimulatorResourceModel &resModel, int id)>
73         ObserveNotificationCallback;
74
75         /**
76          * Callback method for receiving auto request generation and verifiction progress state.
77          *
78          * @param uid - Identifier of remote resource.
79          * @param id - Auto request generation id.
80          * @param sate - Auto request generation and validation state.
81          */
82         typedef std::function<void(const std::string &uid, int id, OperationState state)>
83         AutoRequestGenerationCallback;
84
85         /**
86          * API for getting URI of resource.
87          *
88          * @return URI of resource.
89          */
90         virtual std::string getURI() const = 0;
91
92         /**
93          * API for getting host address of resource.
94          *
95          * @return Host address of resource.
96          */
97         virtual std::string getHost() const = 0;
98
99         /**
100          * API for getting unique id of resource.
101          *
102          * @return ID of resource.
103          */
104         virtual std::string getID() const = 0;
105
106
107         /**
108          * API for getting connectivity type of resource.
109          *
110          * @return enum SimulatorConnectivityType value
111          */
112         virtual SimulatorConnectivityType getConnectivityType() const = 0;
113
114         /**
115          * API for getting resource types bound with the resource.
116          *
117          * @return vector of strings representing resource types.
118          */
119         virtual std::vector < std::string > getResourceTypes() const = 0;
120
121         /**
122          * API for getting interface types bound with the resource.
123          *
124          * @return vector of strings representing interface types.
125          */
126         virtual std::vector < std::string > getInterface() const = 0;
127
128         /**
129          * API to check whether resource can be observed or not.
130          *
131          * @return true if resource is observable, otherwise false.
132          */
133         virtual bool isObservable() const = 0;
134
135         /**
136          * API to send observe request to remote resource.
137          *
138          * @param type - Observe request type.
139          * @param callback - callback for receiving notifications from remote resource
140          * asynchronously.
141          */
142         virtual void observe(ObserveType type, ObserveNotificationCallback callback) = 0;
143
144         /**
145          * API to send cancel observe request to remote resource.
146          *
147          */
148         virtual void cancelObserve() = 0;
149
150         /**
151          * API to send GET request to remote resource.
152          *
153          * @param callback - callback for receiving response from remote resource
154          * asynchronously.
155          */
156         virtual void get(const GetResponseCallback &callback) = 0;
157
158         /**
159          * API to send GET request to remote resource.
160          *
161          * @param queryParams - Query parameters string.
162          * @param callback - callback for receiving response from remote resource
163          * asynchronously.
164          */
165         virtual void get(const std::map<std::string, std::string> &queryParams,
166                          const GetResponseCallback &) = 0;
167
168         /**
169          * API to send GET request to remote resource.
170          *
171          * @param interfaceType - Interace type on which request to be sent.
172          * @param queryParams - Query parameters string.
173          * @param callback - callback for receiving response from remote resource
174          * asynchronously.
175          */
176         virtual void get(const std::string &interfaceType,
177                          const std::map<std::string, std::string> &queryParams,
178                          const GetResponseCallback &) = 0;
179
180         /**
181          * API to send PUT request to remote resource.
182          *
183          * @param representation - Resource representation to be sent with request.
184          * @param callback - callback for receiving response from remote resource
185          * asynchronously.
186          */
187         virtual void put(const SimulatorResourceModel &representation,
188                          const PutResponseCallback &callback) = 0;
189
190
191         /**
192          * API to send PUT request to remote resource.
193          *
194          * @param queryParams - Query parameters string.
195          * @param representation - Resource representation to be sent with request.
196          * @param callback - callback for receiving response from remote resource
197          * asynchronously.
198          */
199         virtual void put(const std::map<std::string, std::string> &queryParams,
200                          const SimulatorResourceModel &representation,
201                          const PutResponseCallback &callback) = 0;
202
203         /**
204          * API to send PUT request to remote resource.
205          *
206          * @param interfaceType - Interace type on which request to be sent.
207          * @param queryParams - Query parameters string.
208          * @param representation - Resource representation to be sent with request.
209          * @param callback - callback for receiving response from remote resource
210          * asynchronously.
211          */
212         virtual void put(const std::string &interfaceType,
213                          const std::map<std::string, std::string> &queryParams,
214                          const SimulatorResourceModel &representation,
215                          const PutResponseCallback &callback) = 0;
216
217         /**
218          * API to send POST request to remote resource.
219          *
220          * @param representation - Resource representation to be sent with request.
221          * @param callback - callback for receiving response from remote resource
222          * asynchronously.
223          */
224         virtual void post(const SimulatorResourceModel &representation,
225                           const PostResponseCallback &callback) = 0;
226
227         /**
228          * API to send POST request to remote resource.
229          *
230          * @param queryParams - Query parameters string.
231          * @param representation - Resource representation to be sent with request.
232          * @param callback - callback for receiving response from remote resource
233          * asynchronously.
234          */
235         virtual void post(const std::map<std::string, std::string> &queryParams,
236                           const SimulatorResourceModel &representation,
237                           const PostResponseCallback &callback) = 0;
238
239         /**
240          * API to send POST request to remote resource.
241          *
242          * @param interfaceType - Interace type on which request to be sent.
243          * @param queryParams - Query parameters string.
244          * @param representation - Resource representation to be sent with request.
245          * @param callback - callback for receiving response from remote resource
246          * asynchronously.
247          */
248         virtual void post(const std::string &interfaceType,
249                           const std::map<std::string, std::string> &queryParams,
250                           const SimulatorResourceModel &representation,
251                           const PostResponseCallback &callback) = 0;
252
253         /**
254          * API to configure resource from RAML file.
255          *
256          * @param path - Path to RAML file.
257          *
258          * @return Map of request models representing the format of requests.
259          */
260         virtual std::map<RequestType, SimulatorRequestModel> configure(
261             const std::string &path) = 0;
262
263         /**
264          * API to start generating requests and send to remote resource.
265          *
266          * @param type - Request type.
267          * @param callback - callback for receiving progress state of auto request
268          * generation process.
269          *
270          * @return Identifier of auto request generating session. This id should be used
271          * for stopping the same.
272          */
273         virtual int startAutoRequesting(RequestType type,
274                                         AutoRequestGenerationCallback callback) = 0;
275
276         /**
277          * API to stop generating requests and send to remote resource.
278          *
279          * @param id - Identifier of auto request generating session.
280          */
281         virtual void stopAutoRequesting(int id) = 0;
282 };
283
284 typedef std::shared_ptr<SimulatorRemoteResource> SimulatorRemoteResourceSP;
285
286 #endif
287