IoTivity-Lite
Collection Support

Optional group of functions to support OCF compliant collections. More...

Typedefs

typedef void(* oc_resource_free_instance_t) (oc_resource_t *)
 Callback invoked to delete an resource. More...
 
typedef oc_resource_t *(* oc_resource_get_instance_t) (const char *, const oc_string_array_t *, oc_resource_properties_t, oc_interface_mask_t, size_t)
 Callback invoked to retrieve an resource. More...
 

Functions

void oc_add_collection (oc_resource_t *collection)
 
bool oc_add_collection_v1 (oc_resource_t *collection)
 Adds a collection to the list of collections. More...
 
bool oc_check_if_collection (const oc_resource_t *resource)
 Check if resource is a global collection. More...
 
void oc_collection_add_link (oc_resource_t *collection, oc_link_t *link)
 Adds the link to the collection. More...
 
bool oc_collection_add_mandatory_rt (oc_resource_t *collection, const char *rt)
 Add a mandatory Resource Type to a collection. More...
 
bool oc_collection_add_supported_rt (oc_resource_t *collection, const char *rt)
 Add a supported Resource Type to a collection. More...
 
oc_resource_toc_collection_get_collections (void)
 Gets all known collections. More...
 
oc_link_t * oc_collection_get_links (oc_resource_t *collection)
 Returns the list of links belonging to this collection. More...
 
void oc_collection_remove_link (oc_resource_t *collection, const oc_link_t *link)
 Removes a link from the collection. More...
 
bool oc_collections_add_rt_factory (const char *rt, oc_resource_get_instance_t get_instance, oc_resource_free_instance_t free_instance)
 adds the resource type factory More...
 
void oc_delete_collection (oc_resource_t *collection)
 Deletes the specified collection. More...
 
oc_collection_t * oc_get_collection_by_uri (const char *uri_path, size_t uri_path_len, size_t device)
 Find a collection in the global collection by its URI. More...
 
oc_link_t * oc_get_link_by_uri (oc_collection_t *collection, const char *uri_path, size_t uri_path_len)
 Get a link from a collection by its URI. More...
 
oc_resource_toc_new_collection (const char *name, const char *uri, uint8_t num_resource_types, size_t device)
 Creates a new empty collection. More...
 
void oc_resource_set_properties_cbs (oc_resource_t *resource, oc_get_properties_cb_t get_properties, void *get_props_user_data, oc_set_properties_cb_t set_properties, void *set_props_user_data)
 sets the callback properties for set properties and get properties More...
 

Detailed Description

Optional group of functions to support OCF compliant collections.

Typedef Documentation

◆ oc_resource_free_instance_t

typedef void(* oc_resource_free_instance_t) (oc_resource_t *)

Callback invoked to delete an resource.

◆ oc_resource_get_instance_t

typedef oc_resource_t*(* oc_resource_get_instance_t) (const char *, const oc_string_array_t *, oc_resource_properties_t, oc_interface_mask_t, size_t)

Callback invoked to retrieve an resource.

Function Documentation

◆ oc_add_collection()

void oc_add_collection ( oc_resource_t collection)
Deprecated:
replaced by oc_add_collection_v1 in v2.2.5.7

◆ oc_add_collection_v1()

bool oc_add_collection_v1 ( oc_resource_t collection)

Adds a collection to the list of collections.

If the caller makes the collection discoverable, then it will be included in the collection discovery once it has been added with this function.

Parameters
[in]collectionCollection to add to the list of collections. Must not be NULL. Must not be added twice or a list corruption will occur. The collection is not copied.
See also
oc_resource_set_discoverable
oc_new_collection

◆ oc_check_if_collection()

bool oc_check_if_collection ( const oc_resource_t resource)

Check if resource is a global collection.

◆ oc_collection_add_link()

void oc_collection_add_link ( oc_resource_t collection,
oc_link_t *  link 
)

Adds the link to the collection.

Parameters
[in,out]collectionCollection to add the link to. Must not be NULL
[in]linkLink to add to the collection. The link is not copied. Must not be NULL. Must not be added again to this or a different collection or a list corruption will occur. To re-add it, remove the link first.
See also
oc_new_link
oc_collection_remove_link

◆ oc_collection_add_mandatory_rt()

bool oc_collection_add_mandatory_rt ( oc_resource_t collection,
const char *  rt 
)

Add a mandatory Resource Type to a collection.

This will be come the "rts-m" property of the collection. The "rts-m" property is an array of Resource Types that are mandatory to be exposed with in an array of Links exposed by the collection.

Note
adding a mandatory Resource Type multiple times will fail
Parameters
[in]collectionthe collection the the Resource Type will be added to (cannot be NULL)
[in]rtthe mandatory Resource Type being added to the collection (cannot be NULL)
Returns
true on success

◆ oc_collection_add_supported_rt()

bool oc_collection_add_supported_rt ( oc_resource_t collection,
const char *  rt 
)

Add a supported Resource Type to a collection.

This will become the "rts" property of the collection. The "rts" property is an array of Resource Types that are supported within an array of Links exposed by the collection.

Note
adding a supported Resource Type multiple times will fail
Parameters
[in]collectionthe collection the the Resource Type will be added to (cannot be NULL)
[in]rtthe supported Resource Type being added to the collection (cannot be NULL)
Returns
true on success

◆ oc_collection_get_collections()

oc_resource_t* oc_collection_get_collections ( void  )

Gets all known collections.

Returns
All collections that have been added via oc_add_collection(). The collections are not copied. Returns NULL if there are no collections. Collections created only via oc_new_collection() but not added will not be returned by this function.

◆ oc_collection_get_links()

oc_link_t* oc_collection_get_links ( oc_resource_t collection)

Returns the list of links belonging to this collection.

Parameters
[in]collectionCollection to get the links from.
Returns
All links of this collection. The links are not copied. Returns NULL if the collection is NULL or contains no links.
See also
oc_collection_add_link

◆ oc_collection_remove_link()

void oc_collection_remove_link ( oc_resource_t collection,
const oc_link_t *  link 
)

Removes a link from the collection.

Parameters
[in,out]collectionCollection to remove the link from. Does nothing if this is NULL
[in]linkThe link to remove. Does nothing if this is NULL or not part of the collection. The link and its resource are not freed.

◆ oc_collections_add_rt_factory()

bool oc_collections_add_rt_factory ( const char *  rt,
oc_resource_get_instance_t  get_instance,
oc_resource_free_instance_t  free_instance 
)

adds the resource type factory

Parameters
rtthe resource type
get_instancecreates the instance of the resource type
free_instancesets callback to free the created instance of the resource tupe
Returns
true
false

◆ oc_delete_collection()

void oc_delete_collection ( oc_resource_t collection)

Deletes the specified collection.

The function removes the collection from the internal list of collections and releases all direct resources and links associated with this collection.

Note
The function does not delete the resources set in the links. The caller needs to do this on her/his own in case these are no longer required.
Parameters
[in,out]collectionThe pointer to the collection to delete. If this is NULL, the function does nothing
See also
oc_collection_get_links
oc_delete_link

◆ oc_get_collection_by_uri()

oc_collection_t* oc_get_collection_by_uri ( const char *  uri_path,
size_t  uri_path_len,
size_t  device 
)

Find a collection in the global collection by its URI.

Parameters
uri_paththe URI path of the collection (with or without the leading slash)
uri_path_lenthe length of the URI path
devicedevice index
Returns
the collection if found
NULL otherwise

◆ oc_get_link_by_uri()

oc_link_t* oc_get_link_by_uri ( oc_collection_t *  collection,
const char *  uri_path,
size_t  uri_path_len 
)

Get a link from a collection by its URI.

Parameters
collectioncollection to search
uri_paththe URI path of the link (with or without the leading slash)
uri_path_lenthe length of the URI path
Returns
oc_link_t* the link if found
NULL otherwise

◆ oc_new_collection()

oc_resource_t* oc_new_collection ( const char *  name,
const char *  uri,
uint8_t  num_resource_types,
size_t  device 
)

Creates a new empty collection.

The collection is created with interfaces OC_IF_BASELINE, OC_IF_LL (also default) and OC_IF_B. Initially it is neither discoverable nor observable.

The function only allocates the collection. Use oc_add_collection() after the setup of the collection is complete.

Parameters
[in]namename of the collection
[in]uriUnique URI of this collection. Must not be NULL.
[in]num_resource_typesNumber of resources the caller will bind with this resource (e.g. by invoking oc_resource_bind_resource_type(col, OIC_WK_COLLECTION)). Must be 1 or higher.
[in]deviceThe internal device that should carry this collection. This is typically 0.
Returns
A pointer to the new collection (actually oc_collection_t *) or NULL if out of memory.
See also
oc_add_collection
oc_collection_add_link

◆ oc_resource_set_properties_cbs()

void oc_resource_set_properties_cbs ( oc_resource_t resource,
oc_get_properties_cb_t  get_properties,
void *  get_props_user_data,
oc_set_properties_cb_t  set_properties,
void *  set_props_user_data 
)

sets the callback properties for set properties and get properties

Parameters
resourcethe resource for the callback data
get_propertiescallback function for retrieving the properties
get_props_user_datathe user data for the get_properties callback function
set_propertiescallback function for setting the properties
set_props_user_datathe user data for the set_properties callback function