add specific comment for entity handler result usage.
[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 /**
22  * @file
23  *
24  * This file contains the declaration of classes and its members related to
25  * OCPlatform.
26  */
27
28 #ifndef OC_PLATFORM_H_
29 #define OC_PLATFORM_H_
30 #include <OCApi.h>
31 #include <OCPlatform_impl.h>
32 namespace OC
33 {
34     /**
35     * This namespace contains the main entrance/functionality of the product.
36     * It may be used with OC::OCPlatform::functionName.  To set a custom configuration,
37     * the implementer must make a call to OCPlatform::Configure before the first usage
38     * of a function in this namespace.
39     */
40     namespace OCPlatform
41     {
42         /**
43         * API for overwriting the default configuration of the OCPlatform object.
44         * @note Any calls made to this AFTER the first call to OCPlatform::Instance
45         * will have no affect
46         */
47         void Configure(const PlatformConfig& config);
48
49         // typedef for handle to cancel presence info with
50         typedef OCDoHandle OCPresenceHandle;
51
52         /**
53          * API for notifying base that resource's attributes have changed.
54          *
55          * @param resourceHandle resource handle of the resource
56          *
57          * @return Returns ::OC_STACK_OK if success.
58          * @note This API is for server side only.
59          * @note OCResourceHandle is defined in ocstack.h
60          * @note OCStackResult is defined in ocstack.h.
61          * @see notifyAllObservers(OCResourceHandle, QualityOfService)
62          */
63         OCStackResult notifyAllObservers(OCResourceHandle resourceHandle);
64
65         /**
66          * @overload
67          *
68          * @param resourceHandle resource handle of the resource
69          * @param QoS the quality of communication
70          * @see notifyAllObservers(OCResourceHandle)
71          */
72         OCStackResult notifyAllObservers(OCResourceHandle resourceHandle, QualityOfService QoS);
73
74         /**
75          * API for notifying only specific clients that resource's attributes have changed.
76          *
77          * @param resourceHandle resource handle of the resource
78          * @param observationIds std vector of observationIds. These set of ids are ones which
79          * which will be notified upon resource change.
80          * @param responsePtr OCResourceResponse pointer used by app to fill the response for this
81          * resource change.
82          *
83          * @return Returns ::OC_STACK_OK if success.
84          * @note This API is for server side only.
85          * @note OCResourceHandle is defined in ocstack.h.
86          * @note OCStackResult is defined in ocstack.h.
87          * @see notifyListOfObservers(OCResourceHandle, ObservationIds&, const std::shared_ptr<OCResourceResponse>, QualityOfService)
88          */
89         OCStackResult notifyListOfObservers(
90                     OCResourceHandle resourceHandle,
91                     ObservationIds& observationIds,
92                     const std::shared_ptr<OCResourceResponse> responsePtr);
93         /**
94          * @overload
95          *
96          * @param resourceHandle resource handle of the resource
97          * @param observationIds std vector of observationIds. These set of ids are ones which
98          * which will be notified upon resource change.
99          * @param responsePtr OCResourceResponse pointer used by app to fill the response for this
100          * resource change.
101          * @param QoS the quality of communication
102          * @see notifyListOfObservers(OCResourceHandle, ObservationIds&, const std::shared_ptr<OCResourceResponse>)
103          */
104         OCStackResult notifyListOfObservers(
105                     OCResourceHandle resourceHandle,
106                     ObservationIds& observationIds,
107                     const std::shared_ptr<OCResourceResponse> responsePtr,
108                     QualityOfService QoS);
109
110         /**
111          * API for Service and Resource Discovery.
112          * @note This API applies to client side only.
113          *
114          * @param host Host IP Address of a service to direct resource discovery query. If null or
115          *        empty, performs multicast resource discovery query
116          * @param resourceURI name of the resource. If null or empty, performs search for all
117          *       resource names
118          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
119          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
120          * @param resourceHandler Handles callbacks, success states and failure states.
121          *
122          *        Four modes of discovery defined as follows:
123          *        (NULL/Empty, NULL/Empty) - Performs ALL service discovery AND ALL resource
124          *           discovery.
125          *        (NULL/Empty, Not Empty) - Performs query for a filtered/scoped/particular
126          *                                   resource(s) from ALL services.
127          *        (Not Empty, NULL/Empty) - Performs ALL resource discovery on a particular service.
128          *        (Not Empty, Not Empty) - Performs query for a filtered/scoped/particular
129          *                                   resource(s)
130          *                                  from a particular service.
131          *
132          * @return Returns ::OC_STACK_OK if success.
133          * @note First parameter 'host' currently represents an IP address. This will change in
134          * future and will refer to endpoint interface so that we can refer to other transports such
135          * as BTH etc.
136          * @note OCStackResult is defined in ocstack.h.
137          * @see findResource(const std::string&, const std::string&, OCConnectivityType, FindCallback, QualityOfService)
138          */
139         OCStackResult findResource(const std::string& host, const std::string& resourceURI,
140                     OCConnectivityType connectivityType, FindCallback resourceHandler);
141         /**
142          * @overload
143          *
144          * @param host Host IP Address of a service to direct resource discovery query. If null or
145          *        empty, performs multicast resource discovery query
146          * @param resourceURI name of the resource. If null or empty, performs search for all
147          *       resource names
148          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
149          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
150          * @param resourceHandler Handles callbacks, success states and failure states.
151          *
152          *        Four modes of discovery defined as follows:
153          *        (NULL/Empty, NULL/Empty) - Performs ALL service discovery AND ALL resource
154          *           discovery.
155          *        (NULL/Empty, Not Empty) - Performs query for a filtered/scoped/particular
156          *                                   resource(s) from ALL services.
157          *        (Not Empty, NULL/Empty) - Performs ALL resource discovery on a particular service.
158          *        (Not Empty, Not Empty) - Performs query for a filtered/scoped/particular
159          *                                   resource(s)
160          *                                  from a particular service.
161          * @param QoS QualityOfService the quality of communication
162          * @see findResource(const std::string&, const std::string&, OCConnectivityType, FindCallback)
163          */
164         OCStackResult findResource(const std::string& host, const std::string& resourceURI,
165                     OCConnectivityType connectivityType, FindCallback resourceHandler,
166                     QualityOfService QoS);
167
168         OCStackResult findResource(const std::string& host, const std::string& resourceURI,
169                     OCConnectivityType connectivityType, FindCallback resourceHandler,
170                     FindErrorCallback errorHandler);
171
172         OCStackResult findResource(const std::string& host, const std::string& resourceURI,
173                     OCConnectivityType connectivityType, FindCallback resourceHandler,
174                     FindErrorCallback errorHandler, QualityOfService QoS);
175
176         /**
177          * API for Device Discovery
178          *
179          *
180          * @param host Host IP Address. If null or empty, Multicast is performed.
181          * @param deviceURI Uri containing address to the virtual device in C Stack
182                                 ("/oic/d")
183          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
184          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
185          * @param deviceInfoHandler device discovery callback
186          *
187          * @return Returns ::OC_STACK_OK if success.
188          * @note OCStackResult is defined in ocstack.h.
189          * @see getDeviceInfo(const std::string&, const std::string&, OCConnectivityType, FindDeviceCallback, QualityOfService)
190          */
191         OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
192                     OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler);
193         /**
194          * @overload
195          *
196          * @param host Host IP Address. If null or empty, Multicast is performed.
197          * @param deviceURI Uri containing address to the virtual device in C Stack
198                                 ("/oic/d")
199          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
200          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
201          * @param deviceInfoHandler device discovery callback
202          * @param QoS the quality of communication
203          * @see getDeviceInfo(const std::string&, const std::string&, OCConnectivityType, FindDeviceCallback)
204          */
205         OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
206                     OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler,
207                     QualityOfService QoS);
208
209         /**
210          * API for Platform Discovery
211          *
212          *
213          * @param host Host IP Address. If null or empty, Multicast is performed.
214          * @param platformURI Uri containing address to the virtual platform in C Stack
215                                 ("/oic/p")
216          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
217          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
218          * @param platformInfoHandler platform discovery callback
219          *
220          * @return Returns ::OC_STACK_OK if success.
221          *
222          * @note OCStackResult is defined in ocstack.h.
223          * @see getPlatformInfo(const std::string&, const std::string&, OCConnectivityType, FindPlatformCallback, QualityOfService)
224          */
225         OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
226                     OCConnectivityType connectivityType, FindPlatformCallback platformInfoHandler);
227         /**
228          * @overload
229          *
230          * @param host Host IP Address. If null or empty, Multicast is performed.
231          * @param platformURI Uri containing address to the virtual platform in C Stack
232                                 ("/oic/p")
233          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
234          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
235          * @param platformInfoHandler platform discovery callback
236          * @param QoS the quality of communication
237          * @see getPlatformInfo(const std::string&, const std::string&, OCConnectivityType, FindPlatformCallback)
238          */
239         OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
240                     OCConnectivityType connectivityType, FindPlatformCallback platformInfoHandler,
241                     QualityOfService QoS);
242
243         /**
244         * This API registers a resource with the server
245         * @note This API applies to server side only.
246         *
247         * @param resourceHandle Upon successful registration, resourceHandle will be filled
248         * @param resourceURI The URI of the resource. Example: "a/light". See NOTE below
249         * @param resourceTypeName The resource type. Example: "light"
250         * @param resourceInterface The resource interface (whether it is collection etc).
251         * @param entityHandler entity handler callback.
252         * @param resourceProperty indicates the property of the resource. Defined in ocstack.h.
253         * setting resourceProperty as OC_DISCOVERABLE will allow Discovery of this resource
254         * setting resourceProperty as OC_OBSERVABLE will allow observation
255         * settings resourceProperty as OC_DISCOVERABLE | OC_OBSERVABLE will allow both discovery and
256         * observation
257         *
258         * @return Returns ::OC_STACK_OK if success.
259         * @note "a/light" is a relative URI.
260         * Above relative URI will be prepended (by core) with a host IP + namespace "oic"
261         * Therefore, fully qualified URI format would be //HostIP-Address/namespace/relativeURI"
262         * Example, a relative URI: 'a/light' will result in a fully qualified URI:
263         *   //192.168.1.1/oic/a/light"
264         * First parameter can take a relative URI and core will take care of preparing the fully
265         * qualified URI OR
266         * first parameter can take fully qualified URI and core will take that as is for further
267         * operations
268         * @note OCStackResult is defined in ocstack.h.
269         * @note entity handler callback :
270         * When you set specific return value like OC_EH_CHANGED, OC_EH_CONTENT,
271         * OC_EH_SLOW and etc in entity handler callback,
272         * ocstack will be not send response automatically to client
273         * except for error return value like OC_EH_ERROR
274         * If you want to send response to client with specific result,
275         * OCDoResponse API should be called with the result value.
276         */
277         OCStackResult registerResource(OCResourceHandle& resourceHandle,
278                         std::string& resourceURI,
279                         const std::string& resourceTypeName,
280                         const std::string& resourceInterface,
281                         EntityHandler entityHandler,
282                         uint8_t resourceProperty);
283
284         /**
285          * This API registers a resource with the server
286          * @note This API applies to server & client side.
287          *
288          * @param resourceHandle Upon successful registration, resourceHandle will be filled
289          * @param resource The instance of OCResource that all data filled.
290          *
291          * @return Returns ::OC_STACK_OK if success.
292          * @note OCStackResult is defined in ocstack.h.
293          */
294         OCStackResult registerResource(OCResourceHandle& resourceHandle,
295                         const std::shared_ptr< OCResource > resource);
296
297         /**
298         * Register Device Info
299         *
300         * @param deviceInfo structure containing all the device specific information
301         * @return Returns ::OC_STACK_OK  if no errors and ::OC_STACK_ERROR in case of stack process error
302         */
303         OCStackResult registerDeviceInfo(const OCDeviceInfo deviceInfo);
304
305         /**
306         * Register Platform Info
307         *
308         * @param platformInfo structure containing all the platform specific information
309         * @return Returns ::OC_STACK_OK if no errors and ::OC_STACK_ERROR in case of stack process error
310         */
311         OCStackResult registerPlatformInfo(const OCPlatformInfo platformInfo);
312
313         /**
314         * Set default device entity handler
315         *
316         * @param entityHandler entity handler to handle requests for
317         *                      any undefined resources or default actions.
318         *                      if NULL is passed it removes the device default entity handler.
319         * @return Returns ::OC_STACK_OK  if no errors and ::OC_STACK_ERROR in case of stack process error
320         * @note entity handler callback :
321         * When you set specific return value like OC_EH_CHANGED, OC_EH_CONTENT,
322         * OC_EH_SLOW and etc in entity handler callback,
323         * ocstack will be not send response automatically to client
324         * except for error return value like OC_EH_ERROR
325         * If you want to send response to client with specific result,
326         * sendResponse API should be called with the result value.
327         */
328         OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler);
329
330         /**
331         * This API unregisters a resource with the server
332         * @note This API applies to server side only.
333         *
334         * @param resourceHandle This is the resource handle which we need to unregister from the
335         * server
336         *
337         * @return Returns ::OC_STACK_OK if success.
338         * @note OCStackResult is defined in ocstack.h.
339         */
340         OCStackResult unregisterResource(const OCResourceHandle& resourceHandle);
341
342         /**
343         * Add a resource to a collection resource.
344         *
345         * @param collectionHandle handle to the collection resource
346         * @param resourceHandle handle to resource to be added to the collection resource
347         *
348         * @return Returns ::OC_STACK_OK if success.
349         * @note OCStackResult is defined in ocstack.h.
350         * @note bindResource must be used only after the both collection resource and
351         * resource to add under a collections are created and respective handles obtained
352         *
353         * @par Example:
354         * -# registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
355         *   entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
356         * -# registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
357         *   entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
358         * -# bindResource(homeResourceHandle, kitchenResourceHandle);
359         * @par
360         * At the end of Step 3, resource "a/home" will contain a reference to "a/kitchen".
361         */
362         OCStackResult bindResource(const OCResourceHandle collectionHandle,
363                 const OCResourceHandle resourceHandle);
364
365         /**
366         * Add multiple resources to a collection resource.
367         *
368         * @param collectionHandle handle to the collection resource
369         * @param addedResourceHandleList reference to list of resource handles to be added to the
370         *   collection resource
371         *
372         * @return Returns ::OC_STACK_OK if success.
373         * @note OCStackResult is defined in ocstack.h.
374         * @note bindResources must be used only after the both collection resource and
375         * list of resources to add under a collection are created and respective handles
376         * obtained.
377         *
378         * @par Example:
379         * -# registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
380         *   homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
381         * -# registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
382         *   kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
383         * -# registerResource(roomResourceHandle, "a/room", "room", Link_Interface,
384         *   roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
385         * -# std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle);
386         *   rList.push_back(roomResourceHandle);
387         * -# bindResource(homeResourceHandle, rList);
388         * @par
389         * At the end of Step 5, resource "a/home" will contain a references to "a/kitchen" and
390         *   "a/room"
391         */
392         OCStackResult bindResources(const OCResourceHandle collectionHandle,
393                 const std::vector<OCResourceHandle>& addedResourceHandleList);
394
395         /**
396         * Unbind a resource from a collection resource.
397         *
398         * @param collectionHandle handle to the collection resource
399         * @param resourceHandle resource handle to be unbound from the collection resource
400         *
401         * @return Returns ::OC_STACK_OK if success.
402         * @note OCStackResult is defined in ocstack.h.
403         * @note unbindResource must be used only after the both collection resource and
404         * resource to unbind from a collection are created and respective handles obtained
405         *
406         * @par Example:
407         * -# registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
408         *   entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
409         * -# registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
410         *   entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
411         * -# bindResource(homeResourceHandle, kitchenResourceHandle);
412         * -# unbindResource(homeResourceHandle, kitchenResourceHandle);
413         * @par
414         * At the end of Step 4, resource "a/home" will no longer reference "a/kitchen".
415         */
416         OCStackResult unbindResource(const OCResourceHandle collectionHandle,
417                     const OCResourceHandle resourceHandle);
418
419         /**
420         * Unbind resources from a collection resource.
421         *
422         * @param collectionHandle handle to the collection resource
423         * @param resourceHandleList List of resource handles to be unbound from the collection
424         *   resource
425         *
426         * @return Returns ::OC_STACK_OK if success.
427         * @note OCStackResult is defined in ocstack.h.
428         * @note unbindResources must be used only after the both collection resource and
429         * list of resources resource to unbind from a collection are created and respective handles
430         *   obtained.
431         *
432         * @par Example:
433         * -# registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
434         *   homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
435         * -# registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
436         *   kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
437         * -# registerResource(roomResourceHandle, "a/room", "room", Link_Interface,
438         *   roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
439         * -# std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle);
440         *   rList.push_back(roomResourceHandle);
441         * -# bindResource(homeResourceHandle, rList);
442         * -# unbindResources(homeResourceHandle, rList);
443         * @par
444         * At the end of Step 6, resource "a/home" will no longer reference to "a/kitchen" and
445         *   "a/room"
446         */
447         OCStackResult unbindResources(const OCResourceHandle collectionHandle,
448                         const std::vector<OCResourceHandle>& resourceHandleList);
449
450         /**
451         * Binds a type to a particular resource
452         * @param resourceHandle handle to the resource
453         * @param resourceTypeName new typename to bind to the resource
454         *
455         * @return Returns ::OC_STACK_OK if success.
456         */
457         OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
458                         const std::string& resourceTypeName);
459
460         /**
461         * Binds an interface to a particular resource
462         * @param resourceHandle handle to the resource
463         * @param resourceInterfaceName new interface  to bind to the resource
464         *
465         * @return Returns ::OC_STACK_OK if success.
466         */
467         OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
468                         const std::string& resourceInterfaceName);
469
470
471         /**
472         * Start Presence announcements.
473         *
474         * @param ttl time to live
475         * @par
476         * If ttl is '0', then the default stack value will be used (60 Seconds).
477         * If ttl is greater than OC_MAX_PRESENCE_TTL_SECONDS, then the ttl will be set to
478         * OC_MAX_PRESENCE_TTL_SECONDS.
479         * @par
480         * @return Returns ::OC_STACK_OK if success.
481         *
482         * Server can call this function when it comes online for the
483         * first time, or when it comes back online from offline mode,
484         * or when it re enters network.
485         *
486         */
487         OCStackResult startPresence(const unsigned int ttl);
488
489         /**
490         * Stop Presence announcements.
491         *
492         * @return Returns ::OC_STACK_OK if success.
493         *
494         * Server can call this function when it is terminating,
495         * going offline, or when going away from network.
496         *
497         */
498         OCStackResult stopPresence();
499
500         /**
501          * subscribes to a server's presence change events.  By making this subscription,
502          * every time a server adds/removes/alters a resource, starts or is intentionally
503          * stopped (potentially more to be added later).
504          *
505          * @param presenceHandle a handle object that can be used to identify this subscription
506          *               request.  It can be used to unsubscribe from these events in the future.
507          *               It will be set upon successful return of this method.
508          * @param host The IP address/addressable name of the server to subscribe to.
509          *               This should be in the format coap://address:port
510          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
511          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
512          * @param presenceHandler callback function that will receive notifications/subscription
513          *               events
514          *
515          * @return Returns ::OC_STACK_OK if success.
516          * @copydoc subscribePresence(OCPresenceHandle&, const std::string&, resourceType, OCConnectivityType, SubscribeCallback)
517          */
518         OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
519                         OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
520         /**
521          * @overload
522          *
523          * @param presenceHandle a handle object that can be used to identify this subscription
524          *               request.  It can be used to unsubscribe from these events in the future.
525          *               It will be set upon successful return of this method.
526          * @param host The IP address/addressable name of the server to subscribe to.
527          *               This should be in the format coap://address:port
528          * @param resourceType a resource type specified as a filter for subscription callbacks.
529          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
530          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
531          * @param presenceHandler callback function that will receive notifications/subscription
532          *               events
533          * @see subscribePresence(OCPresenceHandle&, const std::string&, OCConnectivityType, SubscribeCallback)
534          */
535         OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
536                         const std::string& resourceType, OCConnectivityType connectivityType,
537                         SubscribeCallback presenceHandler);
538
539         /**
540          * unsubscribes from a previously subscribed server's presence events. Note that
541          * you may for a short time still receive events from the server since it may take time
542          * for the unsubscribe to take effect.
543          *
544          * @param presenceHandle the handle object provided by the subscribePresence call that
545          *               identifies this subscription.
546          *
547          * @return Returns ::OC_STACK_OK if success.
548          */
549         OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle);
550
551 #ifdef WITH_CLOUD
552         /**
553          * Subscribes to a server's device presence change events.
554          *
555          * @param presenceHandle a handle object that can be used to identify this subscription
556          *               request.  It can be used to unsubscribe from these events in the future.
557          *               It will be set upon successful return of this method.
558          * @param host The IP address/addressable name of the server to subscribe to.
559          *               This should be in the format coap://address:port
560          * @param di Vector which can have the devices id.
561          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
562          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
563          * @param observeHandler handles callback
564          *        The callback function will be invoked with a map of attribute name and values.
565          *        The callback function will also have the result from this observe operation
566          *        This will have error codes
567          *
568          * @return Returns ::OC_STACK_OK if success.
569          */
570         OCStackResult subscribeDevicePresence(OCPresenceHandle& presenceHandle,
571                                               const std::string& host,
572                                               const std::vector<std::string>& di,
573                                               OCConnectivityType connectivityType,
574                                               ObserveCallback callback);
575 #endif
576
577         /**
578          * Creates a resource proxy object so that get/put/observe functionality
579          * can be used without discovering the object in advance.  Note that the
580          * consumer of this method needs to provide all of the details required to
581          * correctly contact and observe the object. If the consumer lacks any of
582          * this information, they should discover the resource object normally.
583          * Additionally, you can only create this object if OCPlatform was initialized
584          * to be a Client or Client/Server.  Otherwise, this will return an empty
585          * shared ptr.
586          *
587          * @param host a string containing a resolvable host address of the server
588          *           holding the resource. Currently this should be in the format
589          *           coap://address:port, though in the future, we expect this to
590          *           change to //address:port
591          *
592          * @param uri the rest of the resource's URI that will permit messages to be
593          *           properly routed.  Example: /a/light
594          *
595          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
596          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
597          *                           if you want to use a specific Flag like IPv4,
598          *                           you should apply OR operation for the flag in here.
599          *                           Example: static_cast<OCConnectivityType>(CT_ADAPTER_TCP
600          *                                                                    | OC_IP_USE_V4)
601          *
602          * @param isObservable a boolean containing whether the resource supports observation
603          *
604          * @param resourceTypes a collection of resource types implemented by the resource
605          *
606          * @param interfaces a collection of interfaces that the resource supports/implements
607          * @return OCResource::Ptr a shared pointer to the new resource object
608          */
609         OCResource::Ptr constructResourceObject(const std::string& host,
610                         const std::string& uri,
611                         OCConnectivityType connectivityType, bool isObservable,
612                         const std::vector<std::string>& resourceTypes,
613                         const std::vector<std::string>& interfaces);
614
615         /**
616          * Allows application entity handler to send response to an incoming request.
617          *
618          * @param pResponse OCResourceResponse pointer that will permit to set values related
619          * to resource response.
620          *
621          * @return Returns ::OC_STACK_OK if success.
622          */
623         OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse);
624
625         /**
626          * Find all the Direct Pairing capable devices.
627          *
628          * @param waittime timeoutbefore the callback is called
629          * @param callback function to callback with discovered devices after timeout
630          *
631          * @return Returns ::OC_STACK_OK if success
632          */
633         OCStackResult findDirectPairingDevices(unsigned short waittime,
634                                      GetDirectPairedCallback callback);
635
636         /**
637          * Get all the Direct paired devices.
638          *
639          * @param callback function to callback with the list of paired devices
640          *
641          * @return Returns ::OC_STACK_OK if success
642          */
643         OCStackResult getDirectPairedDevices(GetDirectPairedCallback callback);
644
645         /**
646          * Perform the Direct Pairing with the selected peer device
647          *
648          * @param peer device to direct pair with
649          * @param pmSel Selected pairing method
650          * @param pinNumber pin to validate peer & perform the direct pairing
651          * @param resultCallback callback function that will get the result of the operation
652          *
653          * @return Returns ::OC_STACK_OK if success
654          */
655         OCStackResult doDirectPairing(std::shared_ptr<OCDirectPairing> peer, OCPrm_t pmSel,
656                                      const std::string& pinNumber,
657                                      DirectPairingCallback resultCallback);
658 #ifdef WITH_CLOUD
659         /**
660          * Create an account manager object that can be used for doing request to account server.
661          * You can only create this object if OCPlatform was initialized to be a Client or
662          * Client/Server. Otherwise, this will return an empty shared ptr.
663          *
664          * @note For now, OCPlatform SHOULD be initialized to be a Client/Server(Both) for the
665          *       methods of this object to work since device id is not generated on Client mode.
666          *
667          * @param host Host IP Address of a account server.
668          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
669          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
670          *                           if you want to use a specific Flag like IPv4,
671          *                           you should apply OR operation for the flag in here.
672          *                           Example: static_cast<OCConnectivityType>(CT_ADAPTER_TCP
673          *                                                                    | OC_IP_USE_V4)
674          *
675          * @return OCAccountManager::Ptr a shared pointer to the new account manager object
676          */
677         OCAccountManager::Ptr constructAccountManagerObject(const std::string& host,
678                                                             OCConnectivityType connectivityType);
679 #endif // WITH_CLOUD
680 #ifdef RD_CLIENT
681         /**
682          * API for Virtual Resource("/oic/d" and "/oic/p") Publish to Resource Directory.
683          * @note This API applies to resource server side only.
684          *
685          * @param host Host IP Address of a service to direct resource publish query.
686          * @param connectivityType ::OCConnectivityType type of connectivity.
687          * @param callback Handles callbacks, success states and failure states.
688          *
689          * @return Returns ::OC_STACK_OK if success.
690          */
691         OCStackResult publishResourceToRD(const std::string& host,
692                                           OCConnectivityType connectivityType,
693                                           PublishResourceCallback callback);
694
695         /**
696          * @overload
697          *
698          * @param host Host IP Address of a service to direct resource publish query.
699          * @param connectivityType ::OCConnectivityType type of connectivity.
700          * @param callback Handles callbacks, success states and failure states.
701          * @param QoS the quality of communication.
702          *
703          * @return Returns ::OC_STACK_OK if success.
704          */
705         OCStackResult publishResourceToRD(const std::string& host,
706                                           OCConnectivityType connectivityType,
707                                           PublishResourceCallback callback,
708                                           QualityOfService QoS);
709
710         /**
711          * API for Resource Publish to Resource Directory.
712          * @note This API applies to resource server side only.
713          *
714          * @param host Host IP Address of a service to direct resource publish query.
715          * @param connectivityType ::OCConnectivityType type of connectivity.
716          * @param resourceHandle resource handle of the resource.
717          * @param callback Handles callbacks, success states and failure states.
718          *
719          * @return Returns ::OC_STACK_OK if success.
720          */
721         OCStackResult publishResourceToRD(const std::string& host,
722                                           OCConnectivityType connectivityType,
723                                           ResourceHandles& resourceHandles,
724                                           PublishResourceCallback callback);
725
726         /**
727          * @overload
728          *
729          * @param host Host IP Address of a service to direct resource publish query.
730          * @param connectivityType ::OCConnectivityType type of connectivity.
731          * @param resourceHandle resource handle of the resource.
732          * @param callback function to callback with published resources.
733          * @param QoS the quality of communication.
734          * @see publishResourceToRD(const std::string&, OCConnectivityType, OCResourceHandle,
735          * uint8_t, PublishResourceCallback)
736          */
737         OCStackResult publishResourceToRD(const std::string& host,
738                                           OCConnectivityType connectivityType,
739                                           ResourceHandles& resourceHandles,
740                                           PublishResourceCallback callback, QualityOfService QoS);
741
742         /**
743          * API for published resource delete from Resource Directory.
744          * @note This API applies to resource server side only.
745          *
746          * @param host Host IP Address of a service to direct resource delete query.
747          * @param connectivityType ::OCConnectivityType type of connectivity.
748          * @param callback Handles callbacks, success states and failure states.
749          *
750          * @return Returns ::OC_STACK_OK if success.
751          */
752         OCStackResult deleteResourceFromRD(const std::string& host,
753                                            OCConnectivityType connectivityType,
754                                            DeleteResourceCallback callback);
755
756         /**
757          * @overload
758          *
759          * @param host Host IP Address of a service to direct resource delete query.
760          * @param connectivityType ::OCConnectivityType type of connectivity.
761          * @param callback Handles callbacks, success states and failure states.
762          * @param QoS the quality of communication.
763          *
764          * @return Returns ::OC_STACK_OK if success.
765          */
766         OCStackResult deleteResourceFromRD(const std::string& host,
767                                            OCConnectivityType connectivityType,
768                                            DeleteResourceCallback callback,
769                                            QualityOfService QoS);
770
771         /**
772          * @overload
773          *
774          * @param host Host IP Address of a service to direct resource delete query.
775          * @param connectivityType ::OCConnectivityType type of connectivity.
776          * @param resourceHandle resource handle of the resource.
777          * @param callback function to callback with published resources.
778          * @see publishResourceToRD(const std::string&, OCConnectivityType, OCResourceHandle,
779          * uint8_t, PublishResourceCallback)
780          */
781         OCStackResult deleteResourceFromRD(const std::string& host,
782                                            OCConnectivityType connectivityType,
783                                            ResourceHandles& resourceHandles,
784                                            DeleteResourceCallback callback);
785
786         /**
787          * @overload
788          *
789          * @param host Host IP Address of a service to direct resource delete query.
790          * @param connectivityType ::OCConnectivityType type of connectivity.
791          * @param resourceHandle resource handle of the resource.
792          * @param callback function to callback with published resources.
793          * @param QoS the quality of communication.
794          * @see publishResourceToRD(const std::string&, OCConnectivityType, OCResourceHandle,
795          * uint8_t, PublishResourceCallback)
796          */
797         OCStackResult deleteResourceFromRD(const std::string& host,
798                                            OCConnectivityType connectivityType,
799                                            ResourceHandles& resourceHandles,
800                                            DeleteResourceCallback callback, QualityOfService QoS);
801 #endif
802     }
803 }
804
805 #endif // OC_PLATFORM_H_
806
807
808