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 *)
 
typedef oc_resource_t *(* oc_resource_get_instance_t) (const char *, oc_string_array_t *, oc_resource_properties_t, oc_interface_mask_t, size_t)
 

Functions

void oc_add_collection (oc_resource_t *collection)
 Adds a collection to the list of collections. 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_t * oc_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, 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)
 
void oc_delete_collection (oc_resource_t *collection)
 Deletes the specified collection. More...
 
void oc_delete_link (oc_link_t *link)
 Deletes the link. More...
 
void oc_link_add_link_param (oc_link_t *link, const char *key, const char *value)
 Adds a link parameter with specified key and value. More...
 
void oc_link_add_rel (oc_link_t *link, const char *rel)
 Adds a relation to the link. More...
 
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. More...
 
oc_link_t * oc_new_link (oc_resource_t *resource)
 Creates a new link for collections with the specified resource. More...
 

Detailed Description

Optional group of functions to support OCF compliant collections.

Function Documentation

◆ oc_add_collection()

void oc_add_collection ( 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_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.

Parameters
[in]collectionthe collection the the Resource Type will be added to
[in]rtthe mandatory Resource Type being added to the collection
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.

Parameters
[in]collectionthe collection the the Resource Type will be added to
[in]rtthe supported Resource Type being added to the collection
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,
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_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_delete_link()

void oc_delete_link ( oc_link_t *  link)

Deletes the link.

Note
The function neither removes the resource set on this link nor does it remove it from any collection.
Parameters
[in,out]linkThe link to delete. The function does nothing, if the parameter is NULL

◆ oc_link_add_link_param()

void oc_link_add_link_param ( oc_link_t *  link,
const char *  key,
const char *  value 
)

Adds a link parameter with specified key and value.

Parameters
[in,out]linkLink to which to add a link parameter. Must not be NULL
[in]keyKey to identify the link parameter. Must not be NULL
[in]valueLink parameter value. Must not be NULL

◆ oc_link_add_rel()

void oc_link_add_rel ( oc_link_t *  link,
const char *  rel 
)

Adds a relation to the link.

Parameters
[in,out]linkLink to add the relation to. Must not be NULL
[in]relRelation to add. Must not be NULL

◆ 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_new_link()

oc_link_t* oc_new_link ( oc_resource_t *  resource)

Creates a new link for collections with the specified resource.

Parameters
[in]resourceResource to set in the link. The resource is not copied. Must not be NULL
Returns
The created link or NULL if out of memory or resource is NULL.
See also
oc_delete_link
oc_collection_add_link
oc_new_resource