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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
24 * This file contains the declaration of classes and its members related to
28 #ifndef __OCPLATFORM_H
29 #define __OCPLATFORM_H
31 #include <OCPlatform_impl.h>
35 * @brief: 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.
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
47 void Configure(const PlatformConfig& config);
49 // typedef for handle to cancel presence info with
50 typedef OCDoHandle OCPresenceHandle;
53 * API for notifying base that resource's attributes have changed.
55 * @param OCResourceHandle resource handle of the resource
56 * @param QualityOfService the quality of communication
58 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
59 * NOTE: This API is for server side only.
60 * NOTE: OCResourceHandle is defined in ocstack.h.
61 * NOTE: OCStackResult is defined in ocstack.h.
63 OCStackResult notifyAllObservers(OCResourceHandle resourceHandle);
64 OCStackResult notifyAllObservers(OCResourceHandle resourceHandle, QualityOfService QoS);
67 * API for notifying only specific clients that resource's attributes have changed.
69 * @param OCResourceHandle resource handle of the resource
70 * @param observationIds std vector of observationIds. These set of ids are ones which
71 * which will be notified upon resource change.
72 * @param responsePtr OCResourceResponse pointer used by app to fill the response for this
74 * @param QualityOfService the quality of communication
76 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
78 * NOTE: This API is for server side only.
79 * NOTE: OCResourceHandle is defined in ocstack.h.
80 * NOTE: OCStackResult is defined in ocstack.h.
82 OCStackResult notifyListOfObservers(
83 OCResourceHandle resourceHandle,
84 ObservationIds& observationIds,
85 const std::shared_ptr<OCResourceResponse> responsePtr);
86 OCStackResult notifyListOfObservers(
87 OCResourceHandle resourceHandle,
88 ObservationIds& observationIds,
89 const std::shared_ptr<OCResourceResponse> responsePtr,
90 QualityOfService QoS);
93 * API for Service and Resource Discovery.
94 * NOTE: This API applies to client side only.
96 * @param host - Host IP Address of a service to direct resource discovery query. If null or
97 * empty, performs multicast resource discovery query
98 * @param resourceURI - name of the resource. If null or empty, performs search for all
100 * @param connectivityType - @ref OCConnectivityType type of connectivity indicating the
101 * interface. Example: OC_WIFI, OC_ETHERNET, OC_ALL
102 * @param handler - Handles callbacks, success states and failure states.
104 * Four modes of discovery defined as follows:
105 * (NULL/Empty, NULL/Empty) - Performs ALL service discovery AND ALL resource
107 * (NULL/Empty, Not Empty) - Performs query for a filtered/scoped/particular
108 * resource(s) from ALL services.
109 * (Not Empty, NULL/Empty) - Performs ALL resource discovery on a particular service.
110 * (Not Empty, Not Empty) - Performs query for a filtered/scoped/particular
112 * from a particular service.
113 * @param QualityOfService the quality of communication
115 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
116 * NOTE: First parameter 'host' currently represents an IP address. This will change in
117 * future and will refer to endpoint interface so that we can refer to other transports such
119 * NOTE: OCStackResult is defined in ocstack.h.
121 OCStackResult findResource(const std::string& host, const std::string& resourceURI,
122 OCConnectivityType connectivityType, FindCallback resourceHandler);
123 OCStackResult findResource(const std::string& host, const std::string& resourceURI,
124 OCConnectivityType connectivityType, FindCallback resourceHandler,
125 QualityOfService QoS);
128 * API for Device Discovery
131 * @param host - Host IP Address. If null or empty, Multicast is performed.
132 * @param deviceURI - Uri containing address to the virtual device in C Stack
134 * @param connectivityType - @ref OCConnectivityType type of connectivity indicating the
135 * interface. Example: OC_WIFI, OC_ETHERNET, OC_ALL
136 * @param deviceInfoHandler - device discovery callback
137 * @param QoS the quality of communication
140 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
141 OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler);
142 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
143 OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler,
144 QualityOfService QoS);
147 * This API registers a resource with the server
148 * NOTE: This API applies to server side only.
150 * @param resourceHandle - Upon successful registration, resourceHandle will be filled
151 * @param resourceURI - The URI of the resource. Example: "a/light". See NOTE below
152 * @param resourceTypeName - The resource type. Example: "light"
153 * @param resourceInterface - The resource interface (whether it is collection etc).
154 * @param entityHandler - entity handler callback.
155 * @param resourceProperty - indicates the property of the resource. Defined in ocstack.h.
156 * setting resourceProperty as OC_DISCOVERABLE will allow Discovery of this resource
157 * setting resourceProperty as OC_OBSERVABLE will allow observation
158 * settings resourceProperty as OC_DISCOVERABLE | OC_OBSERVABLE will allow both discovery and
161 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
162 * NOTE: "a/light" is a relative URI.
163 * Above relative URI will be prepended (by core) with a host IP + namespace "oc"
164 * Therefore, fully qualified URI format would be //HostIP-Address/namespace/relativeURI"
165 * Example, a relative URI: 'a/light' will result in a fully qualified URI:
166 * //192.168.1.1/oc/a/light"
167 * First parameter can take a relative URI and core will take care of preparing the fully
169 * first parameter can take fully qualified URI and core will take that as is for further
171 * NOTE: OCStackResult is defined in ocstack.h.
173 OCStackResult registerResource(OCResourceHandle& resourceHandle,
174 std::string& resourceURI,
175 const std::string& resourceTypeName,
176 const std::string& resourceInterface,
177 EntityHandler entityHandler,
178 uint8_t resourceProperty);
181 * This API registers a resource with the server
182 * NOTE: This API applies to server & client side.
184 * @param resourceHandle - Upon successful registration, resourceHandle will be filled
185 * @param OCResource - The instance of OCResource that all data filled.
187 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
189 OCStackResult registerResource(OCResourceHandle& resourceHandle,
190 const std::shared_ptr< OCResource > resource);
193 * Register Device Info
195 * @param deviceInfo - structure containing all the device specific information
198 * OC_STACK_OK - no errors
199 * OC_STACK_ERROR - stack process error
201 OCStackResult registerDeviceInfo(const OCDeviceInfo deviceInfo);
204 * Set default device entity handler
206 * @param entityHandler - entity handler to handle requests for
207 * any undefined resources or default actions.
208 * if NULL is passed it removes the device default entity handler.
211 * OC_STACK_OK - no errors
212 * OC_STACK_ERROR - stack process error
214 OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler);
217 * This API unregisters a resource with the server
218 * NOTE: This API applies to server side only.
220 * @param resourceHandle - This is the resource handle which we which to unregister from the
223 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
224 * NOTE: OCStackResult is defined in ocstack.h.
226 OCStackResult unregisterResource(const OCResourceHandle& resourceHandle);
229 * Add a resource to a collection resource.
231 * @param collectionHandle - handle to the collection resource
232 * @param addedResourceHandle - handle to resource to be added to the collection resource
234 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.<br>
235 * NOTE: OCStackResult is defined in ocstack.h. <br>
236 * NOTE: bindResource must be used only after the both collection resource and
237 * resource to add under a collections are created and respective handles obtained<br>
238 * <b>Example:</b> <br>
239 * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
240 * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
241 * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
242 * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
243 * Step 3: bindResource(homeResourceHandle, kitchenResourceHandle);<br>
244 * At the end of Step 3, resource "a/home" will contain a reference to "a/kitchen".<br>
246 OCStackResult bindResource(const OCResourceHandle collectionHandle,
247 const OCResourceHandle resourceHandle);
250 * Add multiple resources to a collection resource.
252 * @param collectionHandle - handle to the collection resource
253 * @param addedResourceHandleList reference to list of resource handles to be added to the
254 * collection resource
256 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
257 * NOTE: OCStackResult is defined in ocstack.h. <br>
258 * NOTE: bindResources must be used only after the both collection resource and
259 * list of resources to add under a collection are created and respective handles
261 * <b> Example: </b> <br>
262 * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
263 * homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
264 * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
265 * kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
266 * Step 3: registerResource(roomResourceHandle, "a/room", "room", Link_Interface,
267 * roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
268 * Step 4: std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle);
269 * rList.push_back(roomResourceHandle);<br>
270 * Step 5: bindResource(homeResourceHandle, rList);<br>
271 * At the end of Step 5, resource "a/home" will contain a references to "a/kitchen" and
274 OCStackResult bindResources(const OCResourceHandle collectionHandle,
275 const std::vector<OCResourceHandle>& addedResourceHandleList);
278 * Unbind a resource from a collection resource.
280 * @param collectionHandle - handle to the collection resource
281 * @param resourceHandle resource handle to be unbound from the collection resource
283 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
284 * NOTE: OCStackResult is defined in ocstack.h.<br>
285 * NOTE: unbindResource must be used only after the both collection resource and
286 * resource to unbind from a collection are created and respective handles obtained<br>
287 * <b> Example </b> <br>
288 * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
289 * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
290 * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
291 * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
292 * Step 3: bindResource(homeResourceHandle, kitchenResourceHandle);<br>
293 * Step 4: unbindResource(homeResourceHandle, kitchenResourceHandle);<br>
294 * At the end of Step 4, resource "a/home" will no longer reference "a/kitchen". <br>
296 OCStackResult unbindResource(const OCResourceHandle collectionHandle,
297 const OCResourceHandle resourceHandle);
300 * Unbind resources from a collection resource.
302 * @param collectionHandle - handle to the collection resource
303 * @param resourceHandleList List of resource handles to be unbound from the collection
306 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
308 * NOTE: OCStackResult is defined in ocstack.h.<br>
309 * NOTE: unbindResources must be used only after the both collection resource and
310 * list of resources resource to unbind from a collection are created and respective handles
312 * <b>Example</b> <br>
313 * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
314 * homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
315 * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
316 * kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
317 * Step 3: registerResource(roomResourceHandle, "a/room", "room", Link_Interface,
318 * roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
319 * Step 4: std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle);
320 * rList.push_back(roomResourceHandle);<br>
321 * Step 5: bindResource(homeResourceHandle, rList);<br>
322 * Step 6: unbindResources(homeResourceHandle, rList);<br>
323 * At the end of Step 6, resource "a/home" will no longer reference to "a/kitchen" and
326 OCStackResult unbindResources(const OCResourceHandle collectionHandle,
327 const std::vector<OCResourceHandle>& resourceHandleList);
330 * Binds a type to a particular resource
331 * @param resourceHandle - handle to the resource
332 * @param resourceTypeName - new typename to bind to the resource
334 * @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
336 OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
337 const std::string& resourceTypeName);
340 * Binds an interface to a particular resource
341 * @param resourceHandle - handle to the resource
342 * @param resourceTypeName - new interface to bind to the resource
344 * @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
346 OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
347 const std::string& resourceInterfaceName);
351 * Start Presence announcements.
353 * @param ttl - time to live
354 * @return OCStackResult - Returns OCSTACK_OK if success <br>
356 * Server can call this function when it comes online for the
357 * first time, or when it comes back online from offline mode,
358 * or when it re enters network.
361 OCStackResult startPresence(const unsigned int ttl);
364 * Stop Presence announcements.
366 * @return OCStackResult - Returns OCSTACK_OK if success <br>
368 * Server can call this function when it is terminating,
369 * going offline, or when going away from network.
372 OCStackResult stopPresence();
375 * subscribes to a server's presence change events. By making this subscription,
376 * every time a server adds/removes/alters a resource, starts or is intentionally
377 * stopped (potentially more to be added later).
379 * @param presenceHandle - a handle object that can be used to identify this subscription
380 * request. It can be used to unsubscribe from these events in the future.
381 * It will be set upon successful return of this method.
382 * @param host - The IP address/addressable name of the server to subscribe to.
383 * This should be in the format coap://address:port
384 * @param connectivityType - @ref OCConnectivityType type of connectivity indicating the
385 * interface. Example: OC_WIFI, OC_ETHERNET, OC_ALL
386 * @param resourceType - a resource type specified as a filter for subscription callbacks.
387 * @param presenceHandler - callback function that will receive notifications/subscription
390 * @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
392 OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
393 OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
394 OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
395 const std::string& resourceType, OCConnectivityType connectivityType,
396 SubscribeCallback presenceHandler);
399 * unsubscribes from a previously subscribed server's presence events. Note that
400 * you may for a short time still receive events from the server since it may take time
401 * for the unsubscribe to take effect.
403 * @param presenceHandle - the handle object provided by the subscribePresence call that
404 * identifies this subscription.
406 * @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
408 OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle);
411 * Creates a resource proxy object so that get/put/observe functionality
412 * can be used without discovering the object in advance. Note that the
413 * consumer of this method needs to provide all of the details required to
414 * correctly contact and observe the object. If the consumer lacks any of
415 * this information, they should discover the resource object normally.
416 * Additionally, you can only create this object if OCPlatform was initialized
417 * to be a Client or Client/Server. Otherwise, this will return an empty
420 * @param host - a string containing a resolvable host address of the server
421 * holding the resource. Currently this should be in the format
422 * coap://address:port, though in the future, we expect this to
423 * change to //address:port
425 * @param uri - the rest of the resource's URI that will permit messages to be
426 * properly routed. Example: /a/light
428 * @param connectivityType - @ref OCConnectivityType type of connectivity indicating the
429 * interface. Example: OC_WIFI, OC_ETHERNET, OC_ALL
431 * @param isObservable - a boolean containing whether the resource supports observation
433 * @param resourceTypes - a collection of resource types implemented by the resource
435 * @param interfaces - a collection of interfaces that the resource supports/implements
436 * @return OCResource::Ptr - a shared pointer to the new resource object
438 OCResource::Ptr constructResourceObject(const std::string& host, const std::string& uri,
439 OCConnectivityType connectivityType, bool isObservable,
440 const std::vector<std::string>& resourceTypes,
441 const std::vector<std::string>& interfaces);
444 * Allows application entity handler to send response to an incoming request.
446 * @param pResponse - OCResourceResponse pointer that will permit to set values related
447 * to resource response. <br>
448 * @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
450 OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse);
454 #endif //__OCPLATFORM_H