99036110441b5bfacb8c8f1eaa939f42ec66c82c
[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         OCStackResult findResourceList(const std::string& host, const std::string& resourceURI,
177                     OCConnectivityType connectivityType, FindResListCallback resourceHandler,
178                     QualityOfService QoS = QualityOfService::LowQos);
179
180         OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::string& value);
181         OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::vector<std::string>& value);
182         OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag, std::string& value);
183         OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag, std::vector<std::string>& value);
184         /**
185          * API for Device Discovery
186          *
187          *
188          * @param host Host IP Address. If null or empty, Multicast is performed.
189          * @param deviceURI Uri containing address to the virtual device in C Stack
190                                 ("/oic/d")
191          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
192          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
193          * @param deviceInfoHandler device discovery callback
194          *
195          * @return Returns ::OC_STACK_OK if success.
196          * @note OCStackResult is defined in ocstack.h.
197          * @see getDeviceInfo(const std::string&, const std::string&, OCConnectivityType, FindDeviceCallback, QualityOfService)
198          */
199         OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
200                     OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler);
201         /**
202          * @overload
203          *
204          * @param host Host IP Address. If null or empty, Multicast is performed.
205          * @param deviceURI Uri containing address to the virtual device in C Stack
206                                 ("/oic/d")
207          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
208          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
209          * @param deviceInfoHandler device discovery callback
210          * @param QoS the quality of communication
211          * @see getDeviceInfo(const std::string&, const std::string&, OCConnectivityType, FindDeviceCallback)
212          */
213         OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
214                     OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler,
215                     QualityOfService QoS);
216
217         /**
218          * API for Platform Discovery
219          *
220          *
221          * @param host Host IP Address. If null or empty, Multicast is performed.
222          * @param platformURI Uri containing address to the virtual platform in C Stack
223                                 ("/oic/p")
224          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
225          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
226          * @param platformInfoHandler platform discovery callback
227          *
228          * @return Returns ::OC_STACK_OK if success.
229          *
230          * @note OCStackResult is defined in ocstack.h.
231          * @see getPlatformInfo(const std::string&, const std::string&, OCConnectivityType, FindPlatformCallback, QualityOfService)
232          */
233         OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
234                     OCConnectivityType connectivityType, FindPlatformCallback platformInfoHandler);
235         /**
236          * @overload
237          *
238          * @param host Host IP Address. If null or empty, Multicast is performed.
239          * @param platformURI Uri containing address to the virtual platform in C Stack
240                                 ("/oic/p")
241          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
242          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
243          * @param platformInfoHandler platform discovery callback
244          * @param QoS the quality of communication
245          * @see getPlatformInfo(const std::string&, const std::string&, OCConnectivityType, FindPlatformCallback)
246          */
247         OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
248                     OCConnectivityType connectivityType, FindPlatformCallback platformInfoHandler,
249                     QualityOfService QoS);
250
251         /**
252         * This API registers a resource with the server
253         * @note This API applies to server side only.
254         *
255         * @param resourceHandle Upon successful registration, resourceHandle will be filled
256         * @param resourceURI The URI of the resource. Example: "a/light". See NOTE below
257         * @param resourceTypeName The resource type. Example: "light"
258         * @param resourceInterface The resource interface (whether it is collection etc).
259         * @param entityHandler entity handler callback.
260         * @param resourceProperty indicates the property of the resource. Defined in ocstack.h.
261         * setting resourceProperty as OC_DISCOVERABLE will allow Discovery of this resource
262         * setting resourceProperty as OC_OBSERVABLE will allow observation
263         * settings resourceProperty as OC_DISCOVERABLE | OC_OBSERVABLE will allow both discovery and
264         * observation
265         *
266         * @return Returns ::OC_STACK_OK if success.
267         * @note "a/light" is a relative URI.
268         * Above relative URI will be prepended (by core) with a host IP + namespace "oic"
269         * Therefore, fully qualified URI format would be //HostIP-Address/namespace/relativeURI"
270         * Example, a relative URI: 'a/light' will result in a fully qualified URI:
271         *   //192.168.1.1/oic/a/light"
272         * First parameter can take a relative URI and core will take care of preparing the fully
273         * qualified URI OR
274         * first parameter can take fully qualified URI and core will take that as is for further
275         * operations
276         * @note OCStackResult is defined in ocstack.h.
277         * @note entity handler callback :
278         * When you set specific return value like OC_EH_CHANGED, OC_EH_CONTENT,
279         * OC_EH_SLOW and etc in entity handler callback,
280         * ocstack will be not send response automatically to client
281         * except for error return value like OC_EH_ERROR
282         * If you want to send response to client with specific result,
283         * OCDoResponse API should be called with the result value.
284         */
285         OCStackResult registerResource(OCResourceHandle& resourceHandle,
286                         std::string& resourceURI,
287                         const std::string& resourceTypeName,
288                         const std::string& resourceInterface,
289                         EntityHandler entityHandler,
290                         uint8_t resourceProperty);
291
292         /**
293          * This API registers a resource with the server
294          * @note This API applies to server & client side.
295          *
296          * @param resourceHandle Upon successful registration, resourceHandle will be filled
297          * @param resource The instance of OCResource that all data filled.
298          *
299          * @return Returns ::OC_STACK_OK if success.
300          * @note OCStackResult is defined in ocstack.h.
301          */
302         OCStackResult registerResource(OCResourceHandle& resourceHandle,
303                         const std::shared_ptr< OCResource > resource);
304
305         /**
306         * Register Device Info
307         *
308         * @param deviceInfo structure containing all the device specific information
309         * @return Returns ::OC_STACK_OK  if no errors and ::OC_STACK_ERROR in case of stack process error
310         */
311         OCStackResult registerDeviceInfo(const OCDeviceInfo deviceInfo);
312
313         /**
314         * Register Platform Info
315         *
316         * @param platformInfo structure containing all the platform specific information
317         * @return Returns ::OC_STACK_OK if no errors and ::OC_STACK_ERROR in case of stack process error
318         */
319         OCStackResult registerPlatformInfo(const OCPlatformInfo platformInfo);
320
321         /**
322         * Set default device entity handler
323         *
324         * @param entityHandler entity handler to handle requests for
325         *                      any undefined resources or default actions.
326         *                      if NULL is passed it removes the device default entity handler.
327         * @return Returns ::OC_STACK_OK  if no errors and ::OC_STACK_ERROR in case of stack process error
328         * @note entity handler callback :
329         * When you set specific return value like OC_EH_CHANGED, OC_EH_CONTENT,
330         * OC_EH_SLOW and etc in entity handler callback,
331         * ocstack will be not send response automatically to client
332         * except for error return value like OC_EH_ERROR
333         * If you want to send response to client with specific result,
334         * sendResponse API should be called with the result value.
335         */
336         OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler);
337
338         /**
339         * This API unregisters a resource with the server
340         * @note This API applies to server side only.
341         *
342         * @param resourceHandle This is the resource handle which we need to unregister from the
343         * server
344         *
345         * @return Returns ::OC_STACK_OK if success.
346         * @note OCStackResult is defined in ocstack.h.
347         */
348         OCStackResult unregisterResource(const OCResourceHandle& resourceHandle);
349
350         /**
351         * Add a resource to a collection resource.
352         *
353         * @param collectionHandle handle to the collection resource
354         * @param resourceHandle handle to resource to be added to the collection resource
355         *
356         * @return Returns ::OC_STACK_OK if success.
357         * @note OCStackResult is defined in ocstack.h.
358         * @note bindResource must be used only after the both collection resource and
359         * resource to add under a collections are created and respective handles obtained
360         *
361         * @par Example:
362         * -# registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
363         *   entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
364         * -# registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
365         *   entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
366         * -# bindResource(homeResourceHandle, kitchenResourceHandle);
367         * @par
368         * At the end of Step 3, resource "a/home" will contain a reference to "a/kitchen".
369         */
370         OCStackResult bindResource(const OCResourceHandle collectionHandle,
371                 const OCResourceHandle resourceHandle);
372
373         /**
374         * Add multiple resources to a collection resource.
375         *
376         * @param collectionHandle handle to the collection resource
377         * @param addedResourceHandleList reference to list of resource handles to be added to the
378         *   collection resource
379         *
380         * @return Returns ::OC_STACK_OK if success.
381         * @note OCStackResult is defined in ocstack.h.
382         * @note bindResources must be used only after the both collection resource and
383         * list of resources to add under a collection are created and respective handles
384         * obtained.
385         *
386         * @par Example:
387         * -# registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
388         *   homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
389         * -# registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
390         *   kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
391         * -# registerResource(roomResourceHandle, "a/room", "room", Link_Interface,
392         *   roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
393         * -# std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle);
394         *   rList.push_back(roomResourceHandle);
395         * -# bindResource(homeResourceHandle, rList);
396         * @par
397         * At the end of Step 5, resource "a/home" will contain a references to "a/kitchen" and
398         *   "a/room"
399         */
400         OCStackResult bindResources(const OCResourceHandle collectionHandle,
401                 const std::vector<OCResourceHandle>& addedResourceHandleList);
402
403         /**
404         * Unbind a resource from a collection resource.
405         *
406         * @param collectionHandle handle to the collection resource
407         * @param resourceHandle resource handle to be unbound from the collection resource
408         *
409         * @return Returns ::OC_STACK_OK if success.
410         * @note OCStackResult is defined in ocstack.h.
411         * @note unbindResource must be used only after the both collection resource and
412         * resource to unbind from a collection are created and respective handles obtained
413         *
414         * @par Example:
415         * -# registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
416         *   entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
417         * -# registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
418         *   entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
419         * -# bindResource(homeResourceHandle, kitchenResourceHandle);
420         * -# unbindResource(homeResourceHandle, kitchenResourceHandle);
421         * @par
422         * At the end of Step 4, resource "a/home" will no longer reference "a/kitchen".
423         */
424         OCStackResult unbindResource(const OCResourceHandle collectionHandle,
425                     const OCResourceHandle resourceHandle);
426
427         /**
428         * Unbind resources from a collection resource.
429         *
430         * @param collectionHandle handle to the collection resource
431         * @param resourceHandleList List of resource handles to be unbound from the collection
432         *   resource
433         *
434         * @return Returns ::OC_STACK_OK if success.
435         * @note OCStackResult is defined in ocstack.h.
436         * @note unbindResources must be used only after the both collection resource and
437         * list of resources resource to unbind from a collection are created and respective handles
438         *   obtained.
439         *
440         * @par Example:
441         * -# registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
442         *   homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
443         * -# registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
444         *   kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
445         * -# registerResource(roomResourceHandle, "a/room", "room", Link_Interface,
446         *   roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
447         * -# std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle);
448         *   rList.push_back(roomResourceHandle);
449         * -# bindResource(homeResourceHandle, rList);
450         * -# unbindResources(homeResourceHandle, rList);
451         * @par
452         * At the end of Step 6, resource "a/home" will no longer reference to "a/kitchen" and
453         *   "a/room"
454         */
455         OCStackResult unbindResources(const OCResourceHandle collectionHandle,
456                         const std::vector<OCResourceHandle>& resourceHandleList);
457
458         /**
459         * Binds a type to a particular resource
460         * @param resourceHandle handle to the resource
461         * @param resourceTypeName new typename to bind to the resource
462         *
463         * @return Returns ::OC_STACK_OK if success.
464         */
465         OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
466                         const std::string& resourceTypeName);
467
468         /**
469         * Binds an interface to a particular resource
470         * @param resourceHandle handle to the resource
471         * @param resourceInterfaceName new interface  to bind to the resource
472         *
473         * @return Returns ::OC_STACK_OK if success.
474         */
475         OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
476                         const std::string& resourceInterfaceName);
477
478
479         /**
480         * Start Presence announcements.
481         *
482         * @param ttl time to live
483         * @par
484         * If ttl is '0', then the default stack value will be used (60 Seconds).
485         * If ttl is greater than OC_MAX_PRESENCE_TTL_SECONDS, then the ttl will be set to
486         * OC_MAX_PRESENCE_TTL_SECONDS.
487         * @par
488         * @return Returns ::OC_STACK_OK if success.
489         *
490         * Server can call this function when it comes online for the
491         * first time, or when it comes back online from offline mode,
492         * or when it re enters network.
493         *
494         */
495         OCStackResult startPresence(const unsigned int ttl);
496
497         /**
498         * Stop Presence announcements.
499         *
500         * @return Returns ::OC_STACK_OK if success.
501         *
502         * Server can call this function when it is terminating,
503         * going offline, or when going away from network.
504         *
505         */
506         OCStackResult stopPresence();
507
508         /**
509          * subscribes to a server's presence change events.  By making this subscription,
510          * every time a server adds/removes/alters a resource, starts or is intentionally
511          * stopped (potentially more to be added later).
512          *
513          * @param presenceHandle a handle object that can be used to identify this subscription
514          *               request.  It can be used to unsubscribe from these events in the future.
515          *               It will be set upon successful return of this method.
516          * @param host The IP address/addressable name of the server to subscribe to.
517          *               This should be in the format coap://address:port
518          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
519          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
520          * @param presenceHandler callback function that will receive notifications/subscription
521          *               events
522          *
523          * @return Returns ::OC_STACK_OK if success.
524          * @copydoc subscribePresence(OCPresenceHandle&, const std::string&, resourceType, OCConnectivityType, SubscribeCallback)
525          */
526         OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
527                         OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
528         /**
529          * @overload
530          *
531          * @param presenceHandle a handle object that can be used to identify this subscription
532          *               request.  It can be used to unsubscribe from these events in the future.
533          *               It will be set upon successful return of this method.
534          * @param host The IP address/addressable name of the server to subscribe to.
535          *               This should be in the format coap://address:port
536          * @param resourceType a resource type specified as a filter for subscription callbacks.
537          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
538          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
539          * @param presenceHandler callback function that will receive notifications/subscription
540          *               events
541          * @see subscribePresence(OCPresenceHandle&, const std::string&, OCConnectivityType, SubscribeCallback)
542          */
543         OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
544                         const std::string& resourceType, OCConnectivityType connectivityType,
545                         SubscribeCallback presenceHandler);
546
547         /**
548          * unsubscribes from a previously subscribed server's presence events. Note that
549          * you may for a short time still receive events from the server since it may take time
550          * for the unsubscribe to take effect.
551          *
552          * @param presenceHandle the handle object provided by the subscribePresence call that
553          *               identifies this subscription.
554          *
555          * @return Returns ::OC_STACK_OK if success.
556          */
557         OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle);
558
559 #ifdef WITH_CLOUD
560         /**
561          * Subscribes to a server's device presence change events.
562          *
563          * @param presenceHandle a handle object that can be used to identify this subscription
564          *               request.  It can be used to unsubscribe from these events in the future.
565          *               It will be set upon successful return of this method.
566          * @param host The IP address/addressable name of the server to subscribe to.
567          *               This should be in the format coap://address:port
568          * @param di Vector which can have the devices id.
569          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
570          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
571          * @param observeHandler handles callback
572          *        The callback function will be invoked with a map of attribute name and values.
573          *        The callback function will also have the result from this observe operation
574          *        This will have error codes
575          *
576          * @return Returns ::OC_STACK_OK if success.
577          */
578         OCStackResult subscribeDevicePresence(OCPresenceHandle& presenceHandle,
579                                               const std::string& host,
580                                               const std::vector<std::string>& di,
581                                               OCConnectivityType connectivityType,
582                                               ObserveCallback callback);
583 #endif
584
585         /**
586          * Creates a resource proxy object so that get/put/observe functionality
587          * can be used without discovering the object in advance.  Note that the
588          * consumer of this method needs to provide all of the details required to
589          * correctly contact and observe the object. If the consumer lacks any of
590          * this information, they should discover the resource object normally.
591          * Additionally, you can only create this object if OCPlatform was initialized
592          * to be a Client or Client/Server.  Otherwise, this will return an empty
593          * shared ptr.
594          *
595          * @param host a string containing a resolvable host address of the server
596          *           holding the resource. Currently this should be in the format
597          *           coap://address:port, though in the future, we expect this to
598          *           change to //address:port
599          *
600          * @param uri the rest of the resource's URI that will permit messages to be
601          *           properly routed.  Example: /a/light
602          *
603          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
604          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
605          *                           if you want to use a specific Flag like IPv4,
606          *                           you should apply OR operation for the flag in here.
607          *                           Example: static_cast<OCConnectivityType>(CT_ADAPTER_TCP
608          *                                                                    | OC_IP_USE_V4)
609          *
610          * @param isObservable a boolean containing whether the resource supports observation
611          *
612          * @param resourceTypes a collection of resource types implemented by the resource
613          *
614          * @param interfaces a collection of interfaces that the resource supports/implements
615          * @return OCResource::Ptr a shared pointer to the new resource object
616          */
617         OCResource::Ptr constructResourceObject(const std::string& host,
618                         const std::string& uri,
619                         OCConnectivityType connectivityType, bool isObservable,
620                         const std::vector<std::string>& resourceTypes,
621                         const std::vector<std::string>& interfaces);
622
623         /**
624          * Allows application entity handler to send response to an incoming request.
625          *
626          * @param pResponse OCResourceResponse pointer that will permit to set values related
627          * to resource response.
628          *
629          * @return Returns ::OC_STACK_OK if success.
630          */
631         OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse);
632
633         /**
634          * Find all the Direct Pairing capable devices.
635          *
636          * @param waittime timeoutbefore the callback is called
637          * @param callback function to callback with discovered devices after timeout
638          *
639          * @return Returns ::OC_STACK_OK if success
640          */
641         OCStackResult findDirectPairingDevices(unsigned short waittime,
642                                      GetDirectPairedCallback callback);
643
644         /**
645          * Get all the Direct paired devices.
646          *
647          * @param callback function to callback with the list of paired devices
648          *
649          * @return Returns ::OC_STACK_OK if success
650          */
651         OCStackResult getDirectPairedDevices(GetDirectPairedCallback callback);
652
653         /**
654          * Perform the Direct Pairing with the selected peer device
655          *
656          * @param peer device to direct pair with
657          * @param pmSel Selected pairing method
658          * @param pinNumber pin to validate peer & perform the direct pairing
659          * @param resultCallback callback function that will get the result of the operation
660          *
661          * @return Returns ::OC_STACK_OK if success
662          */
663         OCStackResult doDirectPairing(std::shared_ptr<OCDirectPairing> peer, OCPrm_t pmSel,
664                                      const std::string& pinNumber,
665                                      DirectPairingCallback resultCallback);
666 #ifdef WITH_CLOUD
667         /**
668          * Create an account manager object that can be used for doing request to account server.
669          * You can only create this object if OCPlatform was initialized to be a Client or
670          * Client/Server. Otherwise, this will return an empty shared ptr.
671          *
672          * @note For now, OCPlatform SHOULD be initialized to be a Client/Server(Both) for the
673          *       methods of this object to work since device id is not generated on Client mode.
674          *
675          * @param host Host IP Address of a account server.
676          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
677          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
678          *                           if you want to use a specific Flag like IPv4,
679          *                           you should apply OR operation for the flag in here.
680          *                           Example: static_cast<OCConnectivityType>(CT_ADAPTER_TCP
681          *                                                                    | OC_IP_USE_V4)
682          *
683          * @return OCAccountManager::Ptr a shared pointer to the new account manager object
684          */
685         OCAccountManager::Ptr constructAccountManagerObject(const std::string& host,
686                                                             OCConnectivityType connectivityType);
687 #endif // WITH_CLOUD
688
689         /**
690          * gets the deviceId of the client
691          *
692          * @param deviceId pointer.
693          * @return Returns ::OC_STACK_OK if success.
694          */
695         OCStackResult getDeviceId(OCUUIdentity *deviceId);
696
697         /**
698          * sets the deviceId of the client
699          *
700          * @param deviceId pointer.
701          * @return Returns ::OC_STACK_OK if success.
702          */
703         OCStackResult setDeviceId(const OCUUIdentity *deviceId);
704     }
705 }
706
707 #endif // OC_PLATFORM_H_