1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 /// @file OCPlatform.h
23 /// @brief This file contains the declaration of classes and its members related to
26 #ifndef __OCPLATFORM_H
27 #define __OCPLATFORM_H
29 #include <OCPlatform_impl.h>
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.
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
45 void Configure(const PlatformConfig& config);
47 // typedef for handle to cancel presence info with
48 typedef OCDoHandle OCPresenceHandle;
51 * API for notifying base that resource's attributes have changed.
53 * @param OCResourceHandle resource handle of the resource
54 * @param QualityOfService the quality of communication
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.
61 OCStackResult notifyAllObservers(OCResourceHandle resourceHandle);
62 OCStackResult notifyAllObservers(OCResourceHandle resourceHandle, QualityOfService QoS);
65 * API for notifying only specific clients that resource's attributes have changed.
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
72 * @param QualityOfService the quality of communication
74 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
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.
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);
91 * API for Service and Resource Discovery.
92 * NOTE: This API applies to client side only.
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
98 * @param handler - Handles callbacks, success states and failure states.
100 * Four modes of discovery defined as follows:
101 * (NULL/Empty, NULL/Empty) - Performs ALL service discovery AND ALL resource
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
108 * from a particular service.
109 * @param QualityOfService the quality of communication
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
115 * NOTE: OCStackResult is defined in ocstack.h.
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);
123 * This API registers a resource with the server
124 * NOTE: This API applies to server side only.
126 * @param resourceHandle - Upon successful registration, resourceHandle will be filled
127 * @param resourceURI - The URI of the resource. Example: "a/light". See NOTE below
128 * @param resourceTypeName - The resource type. Example: "light"
129 * @param resourceInterface - The resource interface (whether it is collection etc).
130 * @param entityHandler - entity handler callback.
131 * @param resourceProperty - indicates the property of the resource. Defined in ocstack.h.
132 * setting resourceProperty as OC_DISCOVERABLE will allow Discovery of this resource
133 * setting resourceProperty as OC_OBSERVABLE will allow observation
134 * settings resourceProperty as OC_DISCOVERABLE | OC_OBSERVABLE will allow both discovery and
137 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
138 * NOTE: "a/light" is a relative URI.
139 * Above relative URI will be prepended (by core) with a host IP + namespace "oc"
140 * Therefore, fully qualified URI format would be //HostIP-Address/namespace/relativeURI"
141 * Example, a relative URI: 'a/light' will result in a fully qualified URI:
142 * //192.168.1.1/oc/a/light"
143 * First parameter can take a relative URI and core will take care of preparing the fully
145 * first paramter can take fully qualified URI and core will take that as is for further
147 * NOTE: OCStackResult is defined in ocstack.h.
149 OCStackResult registerResource(OCResourceHandle& resourceHandle,
150 std::string& resourceURI,
151 const std::string& resourceTypeName,
152 const std::string& resourceInterface,
153 EntityHandler entityHandler,
154 uint8_t resourceProperty);
157 * Set default device entity handler
159 * @param entityHandler - entity handler to handle requests for
160 * any undefined resources or default actions.
161 * if NULL is passed it removes the device default entity handler.
164 * OC_STACK_OK - no errors
165 * OC_STACK_ERROR - stack process error
167 OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler);
170 * This API unregisters a resource with the server
171 * NOTE: This API applies to server side only.
173 * @param resourceHandle - This is the resource handle which we which to unregister from the
176 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
177 * NOTE: OCStackResult is defined in ocstack.h.
179 OCStackResult unregisterResource(const OCResourceHandle& resourceHandle);
182 * Add a resource to a collection resource.
184 * @param collectionHandle - handle to the collection resource
185 * @param addedResourceHandle - handle to resource to be added to the collection resource
187 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.<br>
188 * NOTE: OCStackResult is defined in ocstack.h. <br>
189 * NOTE: bindResource must be used only after the both collection resource and
190 * resource to add under a collections are created and respective handles obtained<br>
191 * <b>Example:</b> <br>
192 * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
193 * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
194 * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
195 * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
196 * Step 3: bindResource(homeResourceHandle, kitchenResourceHandle);<br>
197 * At the end of Step 3, resource "a/home" will contain a reference to "a/kitchen".<br>
199 OCStackResult bindResource(const OCResourceHandle collectionHandle,
200 const OCResourceHandle resourceHandle);
203 * Add multiple resources to a collection resource.
205 * @param collectionHandle - handle to the collection resource
206 * @param addedResourceHandleList reference to list of resource handles to be added to the
207 * collection resource
209 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
210 * NOTE: OCStackResult is defined in ocstack.h. <br>
211 * NOTE: bindResources must be used only after the both collection resource and
212 * list of resources to add under a collection are created and respective handles
214 * <b> Example: </b> <br>
215 * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
216 * homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
217 * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
218 * kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
219 * Step 3: registerResource(roomResourceHandle, "a/room", "room", Link_Interface,
220 * roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
221 * Step 4: std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle);
222 * rList.push_back(roomResourceHandle);<br>
223 * Step 5: bindResource(homeResourceHandle, rList);<br>
224 * At the end of Step 5, resource "a/home" will contain a references to "a/kitchen" and
227 OCStackResult bindResources(const OCResourceHandle collectionHandle,
228 const std::vector<OCResourceHandle>& addedResourceHandleList);
231 * Unbind a resource from a collection resource.
233 * @param collectionHandle - handle to the collection resource
234 * @param resourceHandle resource handle to be unbound from the collection resource
236 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
237 * NOTE: OCStackResult is defined in ocstack.h.<br>
238 * NOTE: unbindResource must be used only after the both collection resource and
239 * resource to unbind from a collection are created and respective handles obtained<br>
240 * <b> Example </b> <br>
241 * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
242 * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
243 * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
244 * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
245 * Step 3: bindResource(homeResourceHandle, kitchenResourceHandle);<br>
246 * Step 4: unbindResource(homeResourceHandle, kitchenResourceHandle);<br>
247 * At the end of Step 4, resource "a/home" will no longer reference "a/kitchen". <br>
249 OCStackResult unbindResource(const OCResourceHandle collectionHandle,
250 const OCResourceHandle resourceHandle);
253 * Unbind resources from a collection resource.
255 * @param collectionHandle - handle to the collection resource
256 * @param resourceHandleList List of resource handles to be unbound from the collection
259 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
261 * NOTE: OCStackResult is defined in ocstack.h.<br>
262 * NOTE: unbindResources must be used only after the both collection resource and
263 * list of resources resource to unbind from a collection are created and respective handles
265 * <b>Example</b> <br>
266 * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
267 * homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
268 * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
269 * kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
270 * Step 3: registerResource(roomResourceHandle, "a/room", "room", Link_Interface,
271 * roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
272 * Step 4: std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle);
273 * rList.push_back(roomResourceHandle);<br>
274 * Step 5: bindResource(homeResourceHandle, rList);<br>
275 * Step 6: unbindResources(homeResourceHandle, rList);<br>
276 * At the end of Step 6, resource "a/home" will no longer reference to "a/kitchen" and
279 OCStackResult unbindResources(const OCResourceHandle collectionHandle,
280 const std::vector<OCResourceHandle>& resourceHandleList);
283 * Binds a type to a particular resource
284 * @param resourceHandle - handle to the resource
285 * @param resourceTypeName - new typename to bind to the resource
287 * @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
289 OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
290 const std::string& resourceTypeName);
293 * Binds an interface to a particular resource
294 * @param resourceHandle - handle to the resource
295 * @param resourceTypeName - new interface to bind to the resource
297 * @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
299 OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
300 const std::string& resourceInterfaceName);
304 * Start Presence announcements.
306 * @param ttl - time to live
307 * @return OCStackResult - Returns OCSTACK_OK if success <br>
309 * Server can call this function when it comes online for the
310 * first time, or when it comes back online from offline mode,
311 * or when it re enters network.
315 OCStackResult startPresence(const unsigned int ttl);
318 * Stop Presence announcements.
320 * @return OCStackResult - Returns OCSTACK_OK if success <br>
322 * Server can call this function when it is terminating,
323 * going offline, or when going away from network.
327 OCStackResult stopPresence();
330 * subscribes to a server's presence change events. By making this subscription,
331 * every time a server adds/removes/alters a resource, starts or is intentionally
332 * stopped (potentially more to be added later).
334 * @param presenceHandle - a handle object that can be used to identify this subscription
335 * request. It can be used to unsubscribe from these events in the future.
336 * It will be set upon successful return of this method.
337 * @param host - The IP address/addressable name of the server to subscribe to.
338 * @param presenceHandler - callback function that will receive notifications/subscription
341 * @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
343 OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
344 SubscribeCallback presenceHandler);
347 * unsubscribes from a previously subscribed server's presence events. Note that
348 * you may for a short time still receive events from the server since it may take time
349 * for the unsubscribe to take effect.
351 * @param presenceHandle - the handle object provided by the subscribePresence call that
352 * identifies this subscription.
354 * @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
356 OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle);
359 * Creates a resource proxy object so that get/put/observe functionality
360 * can be used without discovering the object in advance. Note that the
361 * consumer of this method needs to provide all of the details required to
362 * correctly contact and observe the object. If the consumer lacks any of
363 * this information, they should discover the resource object normally.
364 * Additionally, you can only create this object if OCPlatform was initialized
365 * to be a Client or Client/Server. Otherwise, this will return an empty
368 * @param host - a string containing a resolvable host address of the server
369 * holding the resource. Currently this should be in the format
370 * coap://address:port, though in the future, we expect this to
371 * change to //address:port
373 * @param uri - the rest of the resource's URI that will permit messages to be
374 * properly routed. Example: /a/light
376 * @param isObservable - a boolean containing whether the resource supports observation
378 * @param resourceTypes - a collection of resource types implemented by the resource
380 * @param interfaces - a collection of interfaces that the resource supports/implements
381 * @return OCResource::Ptr - a shared pointer to the new resource object
383 OCResource::Ptr constructResourceObject(const std::string& host, const std::string& uri,
384 bool isObservable, const std::vector<std::string>& resourceTypes,
385 const std::vector<std::string>& interfaces);
389 #endif //__OCPLATFORM_H