1 /******************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
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 * @file simulator_remote_resource.h
24 * @brief This file provides a class for handling discovered resources.
28 #ifndef SIMULATOR_REMOTE_RESOURCE_H_
29 #define SIMULATOR_REMOTE_RESOURCE_H_
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"
38 * @class SimulatorRemoteResource
39 * @brief This class provides a API for handling discovered resources.
41 class SimulatorRemoteResource : private UnCopyable
46 * Callback method for receiving response for GET, PUT and POST requests.
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.
53 typedef std::function<void (const std::string &uid, SimulatorResult result,
54 const SimulatorResourceModel &resModel)>
57 typedef ResponseCallback GetResponseCallback;
58 typedef ResponseCallback PutResponseCallback;
59 typedef ResponseCallback PostResponseCallback;
60 typedef ResponseCallback DeleteResponseCallback;
63 * Callback method for receiving representation change notifications from remote resource.
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.
71 typedef std::function<void (const std::string &uid, SimulatorResult result,
72 const SimulatorResourceModel &resModel, int id)>
73 ObserveNotificationCallback;
76 * Callback method for receiving auto request generation and verifiction progress state.
78 * @param uid - Identifier of remote resource.
79 * @param id - Auto request generation id.
80 * @param sate - Auto request generation and validation state.
82 typedef std::function<void(const std::string &uid, int id, OperationState state)>
83 AutoRequestGenerationCallback;
86 * API for getting URI of resource.
88 * @return URI of resource.
90 virtual std::string getURI() const = 0;
93 * API for getting host address of resource.
95 * @return Host address of resource.
97 virtual std::string getHost() const = 0;
100 * API for getting unique id of resource.
102 * @return ID of resource.
104 virtual std::string getID() const = 0;
108 * API for getting connectivity type of resource.
110 * @return enum SimulatorConnectivityType value
112 virtual SimulatorConnectivityType getConnectivityType() const = 0;
115 * API for getting resource types bound with the resource.
117 * @return vector of strings representing resource types.
119 virtual std::vector < std::string > getResourceTypes() const = 0;
122 * API for getting interface types bound with the resource.
124 * @return vector of strings representing interface types.
126 virtual std::vector < std::string > getInterface() const = 0;
129 * API to check whether resource can be observed or not.
131 * @return true if resource is observable, otherwise false.
133 virtual bool isObservable() const = 0;
136 * API to send observe request to remote resource.
138 * @param type - Observe request type.
139 * @param callback - callback for receiving notifications from remote resource
142 virtual void observe(ObserveType type, ObserveNotificationCallback callback) = 0;
145 * API to send cancel observe request to remote resource.
148 virtual void cancelObserve() = 0;
151 * API to send GET request to remote resource.
153 * @param callback - callback for receiving response from remote resource
156 virtual void get(const GetResponseCallback &callback) = 0;
159 * API to send GET request to remote resource.
161 * @param queryParams - Query parameters string.
162 * @param callback - callback for receiving response from remote resource
165 virtual void get(const std::map<std::string, std::string> &queryParams,
166 const GetResponseCallback &) = 0;
169 * API to send GET request to remote resource.
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
176 virtual void get(const std::string &interfaceType,
177 const std::map<std::string, std::string> &queryParams,
178 const GetResponseCallback &) = 0;
181 * API to send PUT request to remote resource.
183 * @param representation - Resource representation to be sent with request.
184 * @param callback - callback for receiving response from remote resource
187 virtual void put(const SimulatorResourceModel &representation,
188 const PutResponseCallback &callback) = 0;
192 * API to send PUT request to remote resource.
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
199 virtual void put(const std::map<std::string, std::string> &queryParams,
200 const SimulatorResourceModel &representation,
201 const PutResponseCallback &callback) = 0;
204 * API to send PUT request to remote resource.
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
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;
218 * API to send POST request to remote resource.
220 * @param representation - Resource representation to be sent with request.
221 * @param callback - callback for receiving response from remote resource
224 virtual void post(const SimulatorResourceModel &representation,
225 const PostResponseCallback &callback) = 0;
228 * API to send POST request to remote resource.
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
235 virtual void post(const std::map<std::string, std::string> &queryParams,
236 const SimulatorResourceModel &representation,
237 const PostResponseCallback &callback) = 0;
240 * API to send POST request to remote resource.
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
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;
254 * API to configure resource from RAML file.
256 * @param path - Path to RAML file.
258 * @return Map of request models representing the format of requests.
260 virtual std::map<RequestType, SimulatorRequestModel> configure(
261 const std::string &path) = 0;
264 * API to start generating requests and send to remote resource.
266 * @param type - Request type.
267 * @param callback - callback for receiving progress state of auto request
268 * generation process.
270 * @return Identifier of auto request generating session. This id should be used
271 * for stopping the same.
273 virtual int startAutoRequesting(RequestType type,
274 AutoRequestGenerationCallback callback) = 0;
277 * API to stop generating requests and send to remote resource.
279 * @param id - Identifier of auto request generating session.
281 virtual void stopAutoRequesting(int id) = 0;
284 typedef std::shared_ptr<SimulatorRemoteResource> SimulatorRemoteResourceSP;