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