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 * 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 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.
62 * @see notifyAllObservers(OCResourceHandle)
63 * @see notifyAllObservers(OCResourceHandle, QualityOfService)
65 OCStackResult notifyAllObservers(OCResourceHandle resourceHandle);
66 OCStackResult notifyAllObservers(OCResourceHandle resourceHandle, QualityOfService QoS);
69 * API for notifying only specific clients that resource's attributes have changed.
71 * @param OCResourceHandle resource handle of the resource
72 * @param observationIds std vector of observationIds. These set of ids are ones which
73 * which will be notified upon resource change.
74 * @param responsePtr OCResourceResponse pointer used by app to fill the response for this
76 * @param QualityOfService the quality of communication
78 * @return Returns ::OC_STACK_OK if success.
79 * @note This API is for server side only.
80 * @note OCResourceHandle is defined in ocstack.h.
81 * @note OCStackResult is defined in ocstack.h.
83 OCStackResult notifyListOfObservers(
84 OCResourceHandle resourceHandle,
85 ObservationIds& observationIds,
86 const std::shared_ptr<OCResourceResponse> responsePtr);
87 OCStackResult notifyListOfObservers(
88 OCResourceHandle resourceHandle,
89 ObservationIds& observationIds,
90 const std::shared_ptr<OCResourceResponse> responsePtr,
91 QualityOfService QoS);
94 * API for Service and Resource Discovery.
95 * @note This API applies to client side only.
97 * @param host Host IP Address of a service to direct resource discovery query. If null or
98 * empty, performs multicast resource discovery query
99 * @param resourceURI name of the resource. If null or empty, performs search for all
101 * @param connectivityType ::OCConnectivityType type of connectivity indicating the
102 * interface. Example: OC_WIFI, OC_ETHERNET, OC_ALL
103 * @param resourceHandler Handles callbacks, success states and failure states.
105 * Four modes of discovery defined as follows:
106 * (NULL/Empty, NULL/Empty) - Performs ALL service discovery AND ALL resource
108 * (NULL/Empty, Not Empty) - Performs query for a filtered/scoped/particular
109 * resource(s) from ALL services.
110 * (Not Empty, NULL/Empty) - Performs ALL resource discovery on a particular service.
111 * (Not Empty, Not Empty) - Performs query for a filtered/scoped/particular
113 * from a particular service.
114 * @param QualityOfService the quality of communication
116 * @return Returns ::OC_STACK_OK if success.
117 * @note First parameter 'host' currently represents an IP address. This will change in
118 * future and will refer to endpoint interface so that we can refer to other transports such
120 * @note OCStackResult is defined in ocstack.h.
122 OCStackResult findResource(const std::string& host, const std::string& resourceURI,
123 OCConnectivityType connectivityType, FindCallback resourceHandler);
124 OCStackResult findResource(const std::string& host, const std::string& resourceURI,
125 OCConnectivityType connectivityType, FindCallback resourceHandler,
126 QualityOfService QoS);
129 * API for Device Discovery
132 * @param host Host IP Address. If null or empty, Multicast is performed.
133 * @param deviceURI Uri containing address to the virtual device in C Stack
135 * @param connectivityType ::OCConnectivityType type of connectivity indicating the
136 * interface. Example: OC_WIFI, OC_ETHERNET, OC_ALL
137 * @param deviceInfoHandler device discovery callback
138 * @param QoS the quality of communication
140 * @return Returns ::OC_STACK_OK if success.
141 * @note OCStackResult is defined in ocstack.h.
143 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
144 OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler);
145 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
146 OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler,
147 QualityOfService QoS);
150 * API for Platform Discovery
153 * @param host Host IP Address. If null or empty, Multicast is performed.
154 * @param platformURI Uri containing address to the virtual platform in C Stack
156 * @param connectivityType ::OCConnectivityType type of connectivity indicating the
157 * interface. Example: OC_WIFI, OC_ETHERNET, OC_ALL
158 * @param platformInfoHandler platform discovery callback
159 * @param QoS the quality of communication
161 * @return Returns ::OC_STACK_OK if success.
162 * @note OCStackResult is defined in ocstack.h.
164 OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
165 OCConnectivityType connectivityType, FindPlatformCallback platformInfoHandler);
166 OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
167 OCConnectivityType connectivityType, FindPlatformCallback platformInfoHandler,
168 QualityOfService QoS);
171 * This API registers a resource with the server
172 * @note This API applies to server side only.
174 * @param resourceHandle Upon successful registration, resourceHandle will be filled
175 * @param resourceURI The URI of the resource. Example: "a/light". See NOTE below
176 * @param resourceTypeName The resource type. Example: "light"
177 * @param resourceInterface The resource interface (whether it is collection etc).
178 * @param entityHandler entity handler callback.
179 * @param resourceProperty indicates the property of the resource. Defined in ocstack.h.
180 * setting resourceProperty as OC_DISCOVERABLE will allow Discovery of this resource
181 * setting resourceProperty as OC_OBSERVABLE will allow observation
182 * settings resourceProperty as OC_DISCOVERABLE | OC_OBSERVABLE will allow both discovery and
185 * @return Returns ::OC_STACK_OK if success.
186 * @note "a/light" is a relative URI.
187 * Above relative URI will be prepended (by core) with a host IP + namespace "oic"
188 * Therefore, fully qualified URI format would be //HostIP-Address/namespace/relativeURI"
189 * Example, a relative URI: 'a/light' will result in a fully qualified URI:
190 * //192.168.1.1/oic/a/light"
191 * First parameter can take a relative URI and core will take care of preparing the fully
193 * first parameter can take fully qualified URI and core will take that as is for further
195 * @note OCStackResult is defined in ocstack.h.
197 OCStackResult registerResource(OCResourceHandle& resourceHandle,
198 std::string& resourceURI,
199 const std::string& resourceTypeName,
200 const std::string& resourceInterface,
201 EntityHandler entityHandler,
202 uint8_t resourceProperty);
205 * This API registers a resource with the server
206 * @note This API applies to server & client side.
208 * @param resourceHandle Upon successful registration, resourceHandle will be filled
209 * @param OCResource The instance of OCResource that all data filled.
211 * @return Returns ::OC_STACK_OK if success.
212 * @note OCStackResult is defined in ocstack.h.
214 OCStackResult registerResource(OCResourceHandle& resourceHandle,
215 const std::shared_ptr< OCResource > resource);
218 * Register Device Info
220 * @param deviceInfo structure containing all the device specific information
221 * @return Returns ::OC_STACK_OK if no errors and ::OC_STACK_ERROR in case of stack process error
223 OCStackResult registerDeviceInfo(const OCDeviceInfo deviceInfo);
226 * Register Platform Info
228 * @param platformInfo structure containing all the platform specific information
229 * @return Returns ::OC_STACK_OK if no errors and ::OC_STACK_ERROR in case of stack process error
231 OCStackResult registerPlatformInfo(const OCPlatformInfo platformInfo);
234 * Set default device entity handler
236 * @param entityHandler entity handler to handle requests for
237 * any undefined resources or default actions.
238 * if NULL is passed it removes the device default entity handler.
239 * @return Returns ::OC_STACK_OK if no errors and ::OC_STACK_ERROR in case of stack process error
241 OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler);
244 * This API unregisters a resource with the server
245 * @note This API applies to server side only.
247 * @param resourceHandle This is the resource handle which we need to unregister from the
250 * @return Returns ::OC_STACK_OK if success.
251 * @note OCStackResult is defined in ocstack.h.
253 OCStackResult unregisterResource(const OCResourceHandle& resourceHandle);
256 * Add a resource to a collection resource.
258 * @param collectionHandle handle to the collection resource
259 * @param resourceHandle handle to resource to be added to the collection resource
261 * @return Returns ::OC_STACK_OK if success.
262 * @note OCStackResult is defined in ocstack.h.
263 * @note bindResource must be used only after the both collection resource and
264 * resource to add under a collections are created and respective handles obtained
267 * -# registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
268 * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
269 * -# registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
270 * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
271 * -# bindResource(homeResourceHandle, kitchenResourceHandle);
273 * At the end of Step 3, resource "a/home" will contain a reference to "a/kitchen".
275 OCStackResult bindResource(const OCResourceHandle collectionHandle,
276 const OCResourceHandle resourceHandle);
279 * Add multiple resources to a collection resource.
281 * @param collectionHandle handle to the collection resource
282 * @param addedResourceHandleList reference to list of resource handles to be added to the
283 * collection resource
285 * @return Returns ::OC_STACK_OK if success.
286 * @note OCStackResult is defined in ocstack.h.
287 * @note bindResources must be used only after the both collection resource and
288 * list of resources to add under a collection are created and respective handles
292 * -# registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
293 * homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
294 * -# registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
295 * kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
296 * -# registerResource(roomResourceHandle, "a/room", "room", Link_Interface,
297 * roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
298 * -# std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle);
299 * rList.push_back(roomResourceHandle);
300 * -# bindResource(homeResourceHandle, rList);
302 * At the end of Step 5, resource "a/home" will contain a references to "a/kitchen" and
305 OCStackResult bindResources(const OCResourceHandle collectionHandle,
306 const std::vector<OCResourceHandle>& addedResourceHandleList);
309 * Unbind a resource from a collection resource.
311 * @param collectionHandle handle to the collection resource
312 * @param resourceHandle resource handle to be unbound from the collection resource
314 * @return Returns ::OC_STACK_OK if success.
315 * @note OCStackResult is defined in ocstack.h.
316 * @note unbindResource must be used only after the both collection resource and
317 * resource to unbind from a collection are created and respective handles obtained
320 * -# registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
321 * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
322 * -# registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
323 * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
324 * -# bindResource(homeResourceHandle, kitchenResourceHandle);
325 * -# unbindResource(homeResourceHandle, kitchenResourceHandle);
327 * At the end of Step 4, resource "a/home" will no longer reference "a/kitchen".
329 OCStackResult unbindResource(const OCResourceHandle collectionHandle,
330 const OCResourceHandle resourceHandle);
333 * Unbind resources from a collection resource.
335 * @param collectionHandle handle to the collection resource
336 * @param resourceHandleList List of resource handles to be unbound from the collection
339 * @return Returns ::OC_STACK_OK if success.
340 * @note OCStackResult is defined in ocstack.h.
341 * @note unbindResources must be used only after the both collection resource and
342 * list of resources resource to unbind from a collection are created and respective handles
346 * -# registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
347 * homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
348 * -# registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
349 * kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
350 * -# registerResource(roomResourceHandle, "a/room", "room", Link_Interface,
351 * roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
352 * -# std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle);
353 * rList.push_back(roomResourceHandle);
354 * -# bindResource(homeResourceHandle, rList);
355 * -# unbindResources(homeResourceHandle, rList);
357 * At the end of Step 6, resource "a/home" will no longer reference to "a/kitchen" and
360 OCStackResult unbindResources(const OCResourceHandle collectionHandle,
361 const std::vector<OCResourceHandle>& resourceHandleList);
364 * Binds a type to a particular resource
365 * @param resourceHandle handle to the resource
366 * @param resourceTypeName new typename to bind to the resource
368 * @return Returns ::OC_STACK_OK if success.
370 OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
371 const std::string& resourceTypeName);
374 * Binds an interface to a particular resource
375 * @param resourceHandle handle to the resource
376 * @param resourceInterfaceName new interface to bind to the resource
378 * @return Returns ::OC_STACK_OK if success.
380 OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
381 const std::string& resourceInterfaceName);
385 * Start Presence announcements.
387 * @param ttl time to live
389 * If ttl is '0', then the default stack value will be used (60 Seconds).
390 * If ttl is greater than OC_MAX_PRESENCE_TTL_SECONDS, then the ttl will be set to
391 * OC_MAX_PRESENCE_TTL_SECONDS.
393 * @return Returns ::OC_STACK_OK if success.
395 * Server can call this function when it comes online for the
396 * first time, or when it comes back online from offline mode,
397 * or when it re enters network.
400 OCStackResult startPresence(const unsigned int ttl);
403 * Stop Presence announcements.
405 * @return Returns ::OC_STACK_OK if success.
407 * Server can call this function when it is terminating,
408 * going offline, or when going away from network.
411 OCStackResult stopPresence();
414 * subscribes to a server's presence change events. By making this subscription,
415 * every time a server adds/removes/alters a resource, starts or is intentionally
416 * stopped (potentially more to be added later).
418 * @param presenceHandle a handle object that can be used to identify this subscription
419 * request. It can be used to unsubscribe from these events in the future.
420 * It will be set upon successful return of this method.
421 * @param host The IP address/addressable name of the server to subscribe to.
422 * This should be in the format coap://address:port
423 * @param connectivityType ::OCConnectivityType type of connectivity indicating the
424 * interface. Example: OC_WIFI, OC_ETHERNET, OC_ALL
425 * @param resourceType a resource type specified as a filter for subscription callbacks.
426 * @param presenceHandler callback function that will receive notifications/subscription
429 * @return Returns ::OC_STACK_OK if success.
431 OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
432 OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
433 OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
434 const std::string& resourceType, OCConnectivityType connectivityType,
435 SubscribeCallback presenceHandler);
438 * unsubscribes from a previously subscribed server's presence events. Note that
439 * you may for a short time still receive events from the server since it may take time
440 * for the unsubscribe to take effect.
442 * @param presenceHandle the handle object provided by the subscribePresence call that
443 * identifies this subscription.
445 * @return Returns ::OC_STACK_OK if success.
447 OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle);
450 * Creates a resource proxy object so that get/put/observe functionality
451 * can be used without discovering the object in advance. Note that the
452 * consumer of this method needs to provide all of the details required to
453 * correctly contact and observe the object. If the consumer lacks any of
454 * this information, they should discover the resource object normally.
455 * Additionally, you can only create this object if OCPlatform was initialized
456 * to be a Client or Client/Server. Otherwise, this will return an empty
459 * @param host a string containing a resolvable host address of the server
460 * holding the resource. Currently this should be in the format
461 * coap://address:port, though in the future, we expect this to
462 * change to //address:port
464 * @param uri the rest of the resource's URI that will permit messages to be
465 * properly routed. Example: /a/light
467 * @param connectivityType ::OCConnectivityType type of connectivity indicating the
468 * interface. Example: OC_WIFI, OC_ETHERNET, OC_ALL
470 * @param isObservable a boolean containing whether the resource supports observation
472 * @param resourceTypes a collection of resource types implemented by the resource
474 * @param interfaces a collection of interfaces that the resource supports/implements
475 * @return OCResource::Ptr a shared pointer to the new resource object
477 OCResource::Ptr constructResourceObject(const std::string& host,
478 const std::string& uri,
479 OCConnectivityType connectivityType, bool isObservable,
480 const std::vector<std::string>& resourceTypes,
481 const std::vector<std::string>& interfaces);
484 * Allows application entity handler to send response to an incoming request.
486 * @param pResponse OCResourceResponse pointer that will permit to set values related
487 * to resource response.
489 * @return Returns ::OC_STACK_OK if success.
491 OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse);
495 #endif //__OCPLATFORM_H