Updated Doxygen @param for OCResourceResponse::setResourceRepresentation
[platform/upstream/iotivity.git] / resource / include / OCPlatform.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH 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 /// @file OCPlatform.h
22
23 /// @brief  This file contains the declaration of classes and its members related to
24 ///         OCPlatform.
25
26 #ifndef __OCPLATFORM_H
27 #define __OCPLATFORM_H
28 #include <OCApi.h>
29 #include <OCPlatform_impl.h>
30 namespace OC
31 {
32     /**
33     * @brief: This namespace contains the main entrance/functionality of the product.
34     * It may be used with OC::OCPlatform::functionName.  To set a custom configuration,
35     * the implementer must make a call to OCPlatform::Configure before the first usage
36     * of a function in this namespace.
37     */
38     namespace OCPlatform
39     {
40         /**
41         * API for overwriting the default configuration of the OCPlatform object.
42         * Note: Any calls made to this AFTER the first call to OCPlatform::Instance
43         * will have no affect
44         */
45         void Configure(const PlatformConfig& config);
46
47         // typedef for handle to cancel presence info with
48         typedef OCDoHandle OCPresenceHandle;
49
50         /**
51         * API for notifying base that resource's attributes have changed.
52         *
53         * @param OCResourceHandle resource handle of the resource
54         * @param QualityOfService the quality of communication
55         *
56         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
57         * NOTE: This API is for server side only.
58         * NOTE: OCResourceHandle is defined in ocstack.h.
59         * NOTE: OCStackResult is defined in ocstack.h.
60         */
61         OCStackResult notifyAllObservers(OCResourceHandle resourceHandle);
62         OCStackResult notifyAllObservers(OCResourceHandle resourceHandle, QualityOfService QoS);
63
64         /**
65         * API for notifying only specific clients that resource's attributes have changed.
66         *
67         * @param OCResourceHandle resource handle of the resource
68         * @param observationIds std vector of observationIds. These set of ids are ones which
69         * which will be notified upon resource change.
70         * @param responsePtr OCResourceResponse pointer used by app to fill the response for this
71         * resource change.
72         * @param QualityOfService the quality of communication
73         *
74         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
75         *
76         * NOTE: This API is for server side only.
77         * NOTE: OCResourceHandle is defined in ocstack.h.
78         * NOTE: OCStackResult is defined in ocstack.h.
79         */
80         OCStackResult notifyListOfObservers(
81                     OCResourceHandle resourceHandle,
82                     ObservationIds& observationIds,
83                     const std::shared_ptr<OCResourceResponse> responsePtr);
84         OCStackResult notifyListOfObservers(
85                     OCResourceHandle resourceHandle,
86                     ObservationIds& observationIds,
87                     const std::shared_ptr<OCResourceResponse> responsePtr,
88                     QualityOfService QoS);
89
90         /**
91         * API for Service and Resource Discovery.
92         * NOTE: This API applies to client side only.
93         *
94         * @param host - Host IP Address of a service to direct resource discovery query. If null or
95         *        empty, performs multicast resource discovery query
96         * @param resourceURI - name of the resource. If null or empty, performs search for all
97         *       resource names
98         * @param connectivityType - @ref OCConnectivityType type of connectivity indicating the
99         *                           interface. Example: OC_WIFI, OC_ETHERNET, OC_ALL
100         * @param handler - Handles callbacks, success states and failure states.
101         *
102         *        Four modes of discovery defined as follows:
103         *        (NULL/Empty, NULL/Empty) - Performs ALL service discovery AND ALL resource
104         *           discovery.
105         *        (NULL/Empty, Not Empty) - Performs query for a filtered/scoped/particular
106         *                                   resource(s) from ALL services.
107         *        (Not Empty, NULL/Empty) - Performs ALL resource discovery on a particular service.
108         *        (Not Empty, Not Empty) - Performs query for a filtered/scoped/particular
109         *                                   resource(s)
110         *                                  from a particular service.
111         * @param QualityOfService the quality of communication
112         *
113         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
114         * NOTE: First parameter 'host' currently represents an IP address. This will change in
115         * future and will refer to endpoint interface so that we can refer to other transports such
116         * as BTH etc.
117         * NOTE: OCStackResult is defined in ocstack.h.
118         */
119         OCStackResult findResource(const std::string& host, const std::string& resourceURI,
120                     OCConnectivityType connectivityType, FindCallback resourceHandler);
121         OCStackResult findResource(const std::string& host, const std::string& resourceURI,
122                     OCConnectivityType connectivityType, FindCallback resourceHandler,
123                     QualityOfService QoS);
124
125         /**
126         * API for Device Discovery
127         *
128         *
129         * @param host - Host IP Address. If null or empty, Multicast is performed.
130         * @param deviceURI - Uri containing address to the virtual device in C Stack
131                                 ("/oc/core/d")
132         * @param connectivityType - @ref OCConnectivityType type of connectivity indicating the
133         *                           interface. Example: OC_WIFI, OC_ETHERNET, OC_ALL
134         * @param deviceInfoHandler - device discovery callback
135         * @param QoS the quality of communication
136         *
137         */
138         OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
139                     OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler);
140         OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
141                     OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler,
142                     QualityOfService QoS);
143
144         /**
145         * This API registers a resource with the server
146         * NOTE: This API applies to server side only.
147         *
148         * @param resourceHandle - Upon successful registration, resourceHandle will be filled
149         * @param resourceURI - The URI of the resource. Example: "a/light". See NOTE below
150         * @param resourceTypeName - The resource type. Example: "light"
151         * @param resourceInterface - The resource interface (whether it is collection etc).
152         * @param entityHandler - entity handler callback.
153         * @param resourceProperty - indicates the property of the resource. Defined in ocstack.h.
154         * setting resourceProperty as OC_DISCOVERABLE will allow Discovery of this resource
155         * setting resourceProperty as OC_OBSERVABLE will allow observation
156         * settings resourceProperty as OC_DISCOVERABLE | OC_OBSERVABLE will allow both discovery and
157         * observation
158         *
159         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
160         * NOTE: "a/light" is a relative URI.
161         * Above relative URI will be prepended (by core) with a host IP + namespace "oc"
162         * Therefore, fully qualified URI format would be //HostIP-Address/namespace/relativeURI"
163         * Example, a relative URI: 'a/light' will result in a fully qualified URI:
164         *   //192.168.1.1/oc/a/light"
165         * First parameter can take a relative URI and core will take care of preparing the fully
166         * qualified URI OR
167         * first paramter can take fully qualified URI and core will take that as is for further
168         * operations
169         * NOTE: OCStackResult is defined in ocstack.h.
170         */
171         OCStackResult registerResource(OCResourceHandle& resourceHandle,
172                         std::string& resourceURI,
173                         const std::string& resourceTypeName,
174                         const std::string& resourceInterface,
175                         EntityHandler entityHandler,
176                         uint8_t resourceProperty);
177
178         /**
179         * This API registers a resource with the server
180         * NOTE: This API applies to server & client side.
181
182         * @param resourceHandle - Upon successful registration, resourceHandle will be filled
183         * @param OCResource - The instance of OCResource that all data filled.
184         *
185         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
186         */
187         OCStackResult registerResource(OCResourceHandle& resourceHandle,
188                         const std::shared_ptr< OCResource > resource);
189
190         /**
191         * Register Device Info
192         *
193         * @param deviceInfo - structure containing all the device specific information
194         *
195         * @return
196         *      OC_STACK_OK   - no errors
197         *      OC_STACK_ERROR - stack process error
198         */
199         OCStackResult registerDeviceInfo(const OCDeviceInfo deviceInfo);
200
201         /**
202         * Set default device entity handler
203         *
204         * @param entityHandler - entity handler to handle requests for
205         *                        any undefined resources or default actions.
206         *                        if NULL is passed it removes the device default entity handler.
207         *
208         * @return
209         *     OC_STACK_OK    - no errors
210         *     OC_STACK_ERROR - stack process error
211         */
212         OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler);
213
214         /**
215         * This API unregisters a resource with the server
216         * NOTE: This API applies to server side only.
217         *
218         * @param resourceHandle - This is the resource handle which we which to unregister from the
219         * server
220         *
221         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
222         * NOTE: OCStackResult is defined in ocstack.h.
223         */
224         OCStackResult unregisterResource(const OCResourceHandle& resourceHandle);
225
226         /**
227         * Add a resource to a collection resource.
228         *
229         * @param collectionHandle - handle to the collection resource
230         * @param addedResourceHandle - handle to resource to be added to the collection resource
231         *
232         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.<br>
233         * NOTE: OCStackResult is defined in ocstack.h. <br>
234         * NOTE: bindResource must be used only after the both collection resource and
235         * resource to add under a collections are created and respective handles obtained<br>
236         * <b>Example:</b> <br>
237         * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
238         *   entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
239         * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
240         *   entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
241         * Step 3: bindResource(homeResourceHandle, kitchenResourceHandle);<br>
242         * At the end of Step 3, resource "a/home" will contain a reference to "a/kitchen".<br>
243         */
244         OCStackResult bindResource(const OCResourceHandle collectionHandle,
245                 const OCResourceHandle resourceHandle);
246
247         /**
248         * Add multiple resources to a collection resource.
249         *
250         * @param collectionHandle - handle to the collection resource
251         * @param addedResourceHandleList reference to list of resource handles to be added to the
252         *   collection resource
253         *
254         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
255         * NOTE: OCStackResult is defined in ocstack.h. <br>
256         * NOTE: bindResources must be used only after the both collection resource and
257         * list of resources to add under a collection are created and respective handles
258         * obtained <br>
259         * <b> Example: </b> <br>
260         * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
261         *   homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
262         * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
263         *   kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
264         * Step 3: registerResource(roomResourceHandle, "a/room", "room", Link_Interface,
265         *   roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
266         * Step 4: std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle);
267         *   rList.push_back(roomResourceHandle);<br>
268         * Step 5: bindResource(homeResourceHandle, rList);<br>
269         * At the end of Step 5, resource "a/home" will contain a references to "a/kitchen" and
270         *   "a/room" <br>
271         */
272         OCStackResult bindResources(const OCResourceHandle collectionHandle,
273                 const std::vector<OCResourceHandle>& addedResourceHandleList);
274
275         /**
276         * Unbind a resource from a collection resource.
277         *
278         * @param collectionHandle - handle to the collection resource
279         * @param resourceHandle resource handle to be unbound from the collection resource
280         *
281         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
282         * NOTE: OCStackResult is defined in ocstack.h.<br>
283         * NOTE: unbindResource must be used only after the both collection resource and
284         * resource to unbind from a collection are created and respective handles obtained<br>
285         * <b> Example </b> <br>
286         * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
287         *   entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
288         * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
289         *   entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
290         * Step 3: bindResource(homeResourceHandle, kitchenResourceHandle);<br>
291         * Step 4: unbindResource(homeResourceHandle, kitchenResourceHandle);<br>
292         * At the end of Step 4, resource "a/home" will no longer reference "a/kitchen". <br>
293         */
294         OCStackResult unbindResource(const OCResourceHandle collectionHandle,
295                     const OCResourceHandle resourceHandle);
296
297         /**
298         * Unbind resources from a collection resource.
299         *
300         * @param collectionHandle - handle to the collection resource
301         * @param resourceHandleList List of resource handles to be unbound from the collection
302         *   resource
303         *
304         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
305         *
306         * NOTE: OCStackResult is defined in ocstack.h.<br>
307         * NOTE: unbindResources must be used only after the both collection resource and
308         * list of resources resource to unbind from a collection are created and respective handles
309         *   obtained. <br>
310         * <b>Example</b> <br>
311         * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
312         *   homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
313         * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
314         *   kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
315         * Step 3: registerResource(roomResourceHandle, "a/room", "room", Link_Interface,
316         *   roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
317         * Step 4: std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle);
318         *   rList.push_back(roomResourceHandle);<br>
319         * Step 5: bindResource(homeResourceHandle, rList);<br>
320         * Step 6: unbindResources(homeResourceHandle, rList);<br>
321         * At the end of Step 6, resource "a/home" will no longer reference to "a/kitchen" and
322         *   "a/room"<br>
323         */
324         OCStackResult unbindResources(const OCResourceHandle collectionHandle,
325                         const std::vector<OCResourceHandle>& resourceHandleList);
326
327         /**
328         * Binds a type to a particular resource
329         * @param resourceHandle - handle to the resource
330         * @param resourceTypeName - new typename to bind to the resource
331
332         * @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
333         */
334         OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
335                         const std::string& resourceTypeName);
336
337         /**
338         * Binds an interface to a particular resource
339         * @param resourceHandle - handle to the resource
340         * @param resourceTypeName - new interface  to bind to the resource
341
342         * @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
343         */
344         OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
345                         const std::string& resourceInterfaceName);
346
347
348         /**
349         * Start Presence announcements.
350         *
351         * @param ttl - time to live
352         * @return OCStackResult - Returns OCSTACK_OK if success <br>
353         *
354         * Server can call this function when it comes online for the
355         * first time, or when it comes back online from offline mode,
356         * or when it re enters network.
357         *
358         */
359         OCStackResult startPresence(const unsigned int ttl);
360
361         /**
362         * Stop Presence announcements.
363         *
364         * @return OCStackResult - Returns OCSTACK_OK if success <br>
365         *
366         * Server can call this function when it is terminating,
367         * going offline, or when going away from network.
368         *
369         */
370         OCStackResult stopPresence();
371
372         /**
373         * subscribes to a server's presence change events.  By making this subscription,
374         * every time a server adds/removes/alters a resource, starts or is intentionally
375         * stopped (potentially more to be added later).
376         *
377         * @param presenceHandle - a handle object that can be used to identify this subscription
378         *               request.  It can be used to unsubscribe from these events in the future.
379         *               It will be set upon successful return of this method.
380         * @param host - The IP address/addressable name of the server to subscribe to.
381         * @param connectivityType - @ref OCConnectivityType type of connectivity indicating the
382         *                           interface. Example: OC_WIFI, OC_ETHERNET, OC_ALL
383         * @param resourceType - a resource type specified as a filter for subscription callbacks.
384         * @param presenceHandler - callback function that will receive notifications/subscription
385         *               events
386         *
387         * @return OCStackResult - return value of the API.  Returns OCSTACK_OK if success <br>
388         */
389         OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
390                         OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
391         OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
392                         const std::string& resourceType, OCConnectivityType connectivityType,
393                         SubscribeCallback presenceHandler);
394
395         /**
396         * unsubscribes from a previously subscribed server's presence events. Note that
397         * you may for a short time still receive events from the server since it may take time
398         * for the unsubscribe to take effect.
399         *
400         * @param presenceHandle - the handle object provided by the subscribePresence call that
401         *               identifies this subscription.
402         *
403         * @return OCStackResult - return value of the API.  Returns OCSTACK_OK if success <br>
404         */
405         OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle);
406
407         /**
408         * Creates a resource proxy object so that get/put/observe functionality
409         * can be used without discovering the object in advance.  Note that the
410         * consumer of this method needs to provide all of the details required to
411         * correctly contact and observe the object. If the consumer lacks any of
412         * this information, they should discover the resource object normally.
413         * Additionally, you can only create this object if OCPlatform was initialized
414         * to be a Client or Client/Server.  Otherwise, this will return an empty
415         * shared ptr.
416         *
417         * @param host - a string containing a resolvable host address of the server
418         *           holding the resource. Currently this should be in the format
419         *           coap://address:port, though in the future, we expect this to
420         *           change to //address:port
421         *
422         * @param uri - the rest of the resource's URI that will permit messages to be
423         *           properly routed.  Example: /a/light
424         *
425         * @param connectivityType - @ref OCConnectivityType type of connectivity indicating the
426         *                           interface. Example: OC_WIFI, OC_ETHERNET, OC_ALL
427         *
428         * @param isObservable - a boolean containing whether the resource supports observation
429         *
430         * @param resourceTypes - a collection of resource types implemented by the resource
431         *
432         * @param interfaces - a collection of interfaces that the resource supports/implements
433         * @return OCResource::Ptr - a shared pointer to the new resource object
434         */
435         OCResource::Ptr constructResourceObject(const std::string& host, const std::string& uri,
436                         OCConnectivityType connectivityType, bool isObservable,
437                         const std::vector<std::string>& resourceTypes,
438                         const std::vector<std::string>& interfaces);
439
440         /**
441         * Allows application entity handler to send response to an incoming request.
442         *
443         * @param pResponse - OCResourceResponse pointer that will permit to set values related
444         * to resource response. <br>
445         * @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
446         */
447         OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse);
448     }
449 }
450
451 #endif //__OCPLATFORM_H
452
453