Added preprocessor WITH_CLOUD for Subscribe device presence.
[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         */
270         OCStackResult registerResource(OCResourceHandle& resourceHandle,
271                         std::string& resourceURI,
272                         const std::string& resourceTypeName,
273                         const std::string& resourceInterface,
274                         EntityHandler entityHandler,
275                         uint8_t resourceProperty);
276
277         /**
278          * This API registers a resource with the server
279          * @note This API applies to server & client side.
280          *
281          * @param resourceHandle Upon successful registration, resourceHandle will be filled
282          * @param resource The instance of OCResource that all data filled.
283          *
284          * @return Returns ::OC_STACK_OK if success.
285          * @note OCStackResult is defined in ocstack.h.
286          */
287         OCStackResult registerResource(OCResourceHandle& resourceHandle,
288                         const std::shared_ptr< OCResource > resource);
289
290         /**
291         * Register Device Info
292         *
293         * @param deviceInfo structure containing all the device specific information
294         * @return Returns ::OC_STACK_OK  if no errors and ::OC_STACK_ERROR in case of stack process error
295         */
296         OCStackResult registerDeviceInfo(const OCDeviceInfo deviceInfo);
297
298         /**
299         * Register Platform Info
300         *
301         * @param platformInfo structure containing all the platform specific information
302         * @return Returns ::OC_STACK_OK if no errors and ::OC_STACK_ERROR in case of stack process error
303         */
304         OCStackResult registerPlatformInfo(const OCPlatformInfo platformInfo);
305
306         /**
307         * Set default device entity handler
308         *
309         * @param entityHandler entity handler to handle requests for
310         *                      any undefined resources or default actions.
311         *                      if NULL is passed it removes the device default entity handler.
312         * @return Returns ::OC_STACK_OK  if no errors and ::OC_STACK_ERROR in case of stack process error
313         */
314         OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler);
315
316         /**
317         * This API unregisters a resource with the server
318         * @note This API applies to server side only.
319         *
320         * @param resourceHandle This is the resource handle which we need to unregister from the
321         * server
322         *
323         * @return Returns ::OC_STACK_OK if success.
324         * @note OCStackResult is defined in ocstack.h.
325         */
326         OCStackResult unregisterResource(const OCResourceHandle& resourceHandle);
327
328         /**
329         * Add a resource to a collection resource.
330         *
331         * @param collectionHandle handle to the collection resource
332         * @param resourceHandle handle to resource to be added to the collection resource
333         *
334         * @return Returns ::OC_STACK_OK if success.
335         * @note OCStackResult is defined in ocstack.h.
336         * @note bindResource must be used only after the both collection resource and
337         * resource to add under a collections are created and respective handles obtained
338         *
339         * @par Example:
340         * -# registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
341         *   entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
342         * -# registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
343         *   entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
344         * -# bindResource(homeResourceHandle, kitchenResourceHandle);
345         * @par
346         * At the end of Step 3, resource "a/home" will contain a reference to "a/kitchen".
347         */
348         OCStackResult bindResource(const OCResourceHandle collectionHandle,
349                 const OCResourceHandle resourceHandle);
350
351         /**
352         * Add multiple resources to a collection resource.
353         *
354         * @param collectionHandle handle to the collection resource
355         * @param addedResourceHandleList reference to list of resource handles to be added to the
356         *   collection resource
357         *
358         * @return Returns ::OC_STACK_OK if success.
359         * @note OCStackResult is defined in ocstack.h.
360         * @note bindResources must be used only after the both collection resource and
361         * list of resources to add under a collection are created and respective handles
362         * obtained.
363         *
364         * @par Example:
365         * -# registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
366         *   homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
367         * -# registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
368         *   kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
369         * -# registerResource(roomResourceHandle, "a/room", "room", Link_Interface,
370         *   roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
371         * -# std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle);
372         *   rList.push_back(roomResourceHandle);
373         * -# bindResource(homeResourceHandle, rList);
374         * @par
375         * At the end of Step 5, resource "a/home" will contain a references to "a/kitchen" and
376         *   "a/room"
377         */
378         OCStackResult bindResources(const OCResourceHandle collectionHandle,
379                 const std::vector<OCResourceHandle>& addedResourceHandleList);
380
381         /**
382         * Unbind a resource from a collection resource.
383         *
384         * @param collectionHandle handle to the collection resource
385         * @param resourceHandle resource handle to be unbound from the collection resource
386         *
387         * @return Returns ::OC_STACK_OK if success.
388         * @note OCStackResult is defined in ocstack.h.
389         * @note unbindResource must be used only after the both collection resource and
390         * resource to unbind from a collection are created and respective handles obtained
391         *
392         * @par Example:
393         * -# registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
394         *   entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
395         * -# registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
396         *   entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
397         * -# bindResource(homeResourceHandle, kitchenResourceHandle);
398         * -# unbindResource(homeResourceHandle, kitchenResourceHandle);
399         * @par
400         * At the end of Step 4, resource "a/home" will no longer reference "a/kitchen".
401         */
402         OCStackResult unbindResource(const OCResourceHandle collectionHandle,
403                     const OCResourceHandle resourceHandle);
404
405         /**
406         * Unbind resources from a collection resource.
407         *
408         * @param collectionHandle handle to the collection resource
409         * @param resourceHandleList List of resource handles to be unbound from the collection
410         *   resource
411         *
412         * @return Returns ::OC_STACK_OK if success.
413         * @note OCStackResult is defined in ocstack.h.
414         * @note unbindResources must be used only after the both collection resource and
415         * list of resources resource to unbind from a collection are created and respective handles
416         *   obtained.
417         *
418         * @par Example:
419         * -# registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
420         *   homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
421         * -# registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
422         *   kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
423         * -# registerResource(roomResourceHandle, "a/room", "room", Link_Interface,
424         *   roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
425         * -# std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle);
426         *   rList.push_back(roomResourceHandle);
427         * -# bindResource(homeResourceHandle, rList);
428         * -# unbindResources(homeResourceHandle, rList);
429         * @par
430         * At the end of Step 6, resource "a/home" will no longer reference to "a/kitchen" and
431         *   "a/room"
432         */
433         OCStackResult unbindResources(const OCResourceHandle collectionHandle,
434                         const std::vector<OCResourceHandle>& resourceHandleList);
435
436         /**
437         * Binds a type to a particular resource
438         * @param resourceHandle handle to the resource
439         * @param resourceTypeName new typename to bind to the resource
440         *
441         * @return Returns ::OC_STACK_OK if success.
442         */
443         OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
444                         const std::string& resourceTypeName);
445
446         /**
447         * Binds an interface to a particular resource
448         * @param resourceHandle handle to the resource
449         * @param resourceInterfaceName new interface  to bind to the resource
450         *
451         * @return Returns ::OC_STACK_OK if success.
452         */
453         OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
454                         const std::string& resourceInterfaceName);
455
456
457         /**
458         * Start Presence announcements.
459         *
460         * @param ttl time to live
461         * @par
462         * If ttl is '0', then the default stack value will be used (60 Seconds).
463         * If ttl is greater than OC_MAX_PRESENCE_TTL_SECONDS, then the ttl will be set to
464         * OC_MAX_PRESENCE_TTL_SECONDS.
465         * @par
466         * @return Returns ::OC_STACK_OK if success.
467         *
468         * Server can call this function when it comes online for the
469         * first time, or when it comes back online from offline mode,
470         * or when it re enters network.
471         *
472         */
473         OCStackResult startPresence(const unsigned int ttl);
474
475         /**
476         * Stop Presence announcements.
477         *
478         * @return Returns ::OC_STACK_OK if success.
479         *
480         * Server can call this function when it is terminating,
481         * going offline, or when going away from network.
482         *
483         */
484         OCStackResult stopPresence();
485
486         /**
487          * subscribes to a server's presence change events.  By making this subscription,
488          * every time a server adds/removes/alters a resource, starts or is intentionally
489          * stopped (potentially more to be added later).
490          *
491          * @param presenceHandle a handle object that can be used to identify this subscription
492          *               request.  It can be used to unsubscribe from these events in the future.
493          *               It will be set upon successful return of this method.
494          * @param host The IP address/addressable name of the server to subscribe to.
495          *               This should be in the format coap://address:port
496          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
497          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
498          * @param presenceHandler callback function that will receive notifications/subscription
499          *               events
500          *
501          * @return Returns ::OC_STACK_OK if success.
502          * @copydoc subscribePresence(OCPresenceHandle&, const std::string&, resourceType, OCConnectivityType, SubscribeCallback)
503          */
504         OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
505                         OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
506         /**
507          * @overload
508          *
509          * @param presenceHandle a handle object that can be used to identify this subscription
510          *               request.  It can be used to unsubscribe from these events in the future.
511          *               It will be set upon successful return of this method.
512          * @param host The IP address/addressable name of the server to subscribe to.
513          *               This should be in the format coap://address:port
514          * @param resourceType a resource type specified as a filter for subscription callbacks.
515          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
516          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
517          * @param presenceHandler callback function that will receive notifications/subscription
518          *               events
519          * @see subscribePresence(OCPresenceHandle&, const std::string&, OCConnectivityType, SubscribeCallback)
520          */
521         OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
522                         const std::string& resourceType, OCConnectivityType connectivityType,
523                         SubscribeCallback presenceHandler);
524
525         /**
526          * unsubscribes from a previously subscribed server's presence events. Note that
527          * you may for a short time still receive events from the server since it may take time
528          * for the unsubscribe to take effect.
529          *
530          * @param presenceHandle the handle object provided by the subscribePresence call that
531          *               identifies this subscription.
532          *
533          * @return Returns ::OC_STACK_OK if success.
534          */
535         OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle);
536
537 #ifdef WITH_CLOUD
538         /**
539          * Subscribes to a server's device presence change events.
540          *
541          * @param presenceHandle a handle object that can be used to identify this subscription
542          *               request.  It can be used to unsubscribe from these events in the future.
543          *               It will be set upon successful return of this method.
544          * @param host The IP address/addressable name of the server to subscribe to.
545          *               This should be in the format coap://address:port
546          * @param queryParams map which can have the query parameter name and list of value.
547          * @param observeHandler handles callback
548          *        The callback function will be invoked with a map of attribute name and values.
549          *        The callback function will also have the result from this observe operation
550          *        This will have error codes
551          *
552          * @return Returns ::OC_STACK_OK if success.
553          */
554         OCStackResult subscribeDevicePresence(OCPresenceHandle& presenceHandle,
555                                               const std::string& host,
556                                               const QueryParamsList& queryParams,
557                                               OCConnectivityType connectivityType,
558                                               ObserveCallback callback);
559 #endif
560
561         /**
562          * Creates a resource proxy object so that get/put/observe functionality
563          * can be used without discovering the object in advance.  Note that the
564          * consumer of this method needs to provide all of the details required to
565          * correctly contact and observe the object. If the consumer lacks any of
566          * this information, they should discover the resource object normally.
567          * Additionally, you can only create this object if OCPlatform was initialized
568          * to be a Client or Client/Server.  Otherwise, this will return an empty
569          * shared ptr.
570          *
571          * @param host a string containing a resolvable host address of the server
572          *           holding the resource. Currently this should be in the format
573          *           coap://address:port, though in the future, we expect this to
574          *           change to //address:port
575          *
576          * @param uri the rest of the resource's URI that will permit messages to be
577          *           properly routed.  Example: /a/light
578          *
579          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
580          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
581          *                           if you want to use specific a Flag like IPv4
582          *                           you should apply OR operation for the flag in here.
583          *                           Example: static_cast<OCConnectivityType>(CT_ADAPTER_TCP
584          *                                                                    | OC_IP_USE_V4)
585          *
586          * @param isObservable a boolean containing whether the resource supports observation
587          *
588          * @param resourceTypes a collection of resource types implemented by the resource
589          *
590          * @param interfaces a collection of interfaces that the resource supports/implements
591          * @return OCResource::Ptr a shared pointer to the new resource object
592          */
593         OCResource::Ptr constructResourceObject(const std::string& host,
594                         const std::string& uri,
595                         OCConnectivityType connectivityType, bool isObservable,
596                         const std::vector<std::string>& resourceTypes,
597                         const std::vector<std::string>& interfaces);
598
599         /**
600          * Allows application entity handler to send response to an incoming request.
601          *
602          * @param pResponse OCResourceResponse pointer that will permit to set values related
603          * to resource response.
604          *
605          * @return Returns ::OC_STACK_OK if success.
606          */
607         OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse);
608
609         /**
610          * Find all the Direct Pairing capable devices.
611          *
612          * @param waittime timeoutbefore the callback is called
613          * @param callback function to callback with discovered devices after timeout
614          *
615          * @return Returns ::OC_STACK_OK if success
616          */
617         OCStackResult findDirectPairingDevices(unsigned short waittime,
618                                      GetDirectPairedCallback callback);
619
620         /**
621          * Get all the Direct paired devices.
622          *
623          * @param callback function to callback with the list of paired devices
624          *
625          * @return Returns ::OC_STACK_OK if success
626          */
627         OCStackResult getDirectPairedDevices(GetDirectPairedCallback callback);
628
629         /**
630          * Perform the Direct Pairing with the selected peer device
631          *
632          * @param peer device to direct pair with
633          * @param pmSel Selected pairing method
634          * @param pinNumber pin to validate peer & perform the direct pairing
635          * @param resultCallback callback function that will get the result of the operation
636          *
637          * @return Returns ::OC_STACK_OK if success
638          */
639         OCStackResult doDirectPairing(std::shared_ptr<OCDirectPairing> peer, OCPrm_t pmSel,
640                                      const std::string& pinNumber,
641                                      DirectPairingCallback resultCallback);
642 #ifdef WITH_CLOUD
643         /**
644          * API for Account Registration to Account Server
645          * @note Not supported on client mode for now since device id is not generated yet on
646          *       client mode. So it should be server or both mode for API to work.
647          *
648          * @param host Host IP Address of a account server.
649          * @param authProvider Provider name used for authentication.
650          * @param authCode The authorization code obtained by using an authorization server
651          *                 as an intermediary between the client and resource owner.
652          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
653          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
654          * @param cloudConnectHandler Callback function that will get the result of the operation.
655          *
656          * @return Returns ::OC_STACK_OK if success
657          */
658         OCStackResult signUp(const std::string& host,
659                              const std::string& authProvider,
660                              const std::string& authCode,
661                              OCConnectivityType connectivityType,
662                              PostCallback cloudConnectHandler);
663
664         /**
665          * API for Sign-In to Account Server
666          * @note Not supported on client mode for now since device id is not generated yet on
667          *       client mode. So it should be server or both mode for API to work.
668          *
669          * @param host Host IP Address of a account server.
670          * @param accessToken Identifier of the resource obtained by account registration.
671          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
672          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
673          * @param cloudConnectHandler Callback function that will get the result of the operation.
674          *
675          * @return Returns ::OC_STACK_OK if success
676          */
677         OCStackResult signIn(const std::string& host,
678                              const std::string& accessToken,
679                              OCConnectivityType connectivityType,
680                              PostCallback cloudConnectHandler);
681
682         /**
683          * API for Sign-Out to Account Server
684          * @note Not supported on client mode for now since device id is not generated yet on
685          *       client mode. So it should be server or both mode for API to work.
686          *
687          * @param host Host IP Address of a account server.
688          * @param accessToken Identifier of the resource obtained by account registration.
689          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
690          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
691          * @param cloudConnectHandler Callback function that will get the result of the operation.
692          *
693          * @return Returns ::OC_STACK_OK if success
694          */
695         OCStackResult signOut(const std::string& host,
696                               const std::string& accessToken,
697                               OCConnectivityType connectivityType,
698                               PostCallback cloudConnectHandler);
699
700         /**
701          * API for Refresh Access token to Account Server
702          * @note Not supported on client mode for now since device id is not generated yet on
703          *       client mode. So it should be server or both mode for API to work.
704          *
705          * @param host Host IP Address of a account server.
706          * @param refreshToken Refresh token used for access token refresh.
707          * @param connectivityType ::OCConnectivityType type of connectivity indicating the
708          *                           interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
709          * @param cloudConnectHandler Callback function that will get the result of the operation.
710          *
711          * @return Returns ::OC_STACK_OK if success
712          */
713         OCStackResult refreshAccessToken(const std::string& host,
714                                          const std::string& refreshToken,
715                                          OCConnectivityType connectivityType,
716                                          PostCallback cloudConnectHandler);
717 #endif // WITH_CLOUD
718     }
719 }
720
721 #endif // OC_PLATFORM_H_
722
723
724