IoT managed integrations End Device SDK
Loading...
Searching...
No Matches
Classes | Functions
iotmi_device_data_model_handler.h File Reference
#include <stdint.h>
#include <stdio.h>
#include <iotmi_device_agent.h>
#include <iotmi_device_types.h>

Go to the source code of this file.

Classes

struct  iotmiDev_DataModelHandler_AttrMapping
 
struct  iotmiDev_DataModelHandler_CommandMapping
 
struct  iotmiDev_DataModelHandler_EventMapping
 
struct  iotmiDev_DataModelHandler_CustomSchemaMapping
 
struct  iotmiDev_DataModelHandler_Config
 The struct to hold the configuration of data model handler. More...
 

Functions

void iotmiDev_DataModelHandler_initDefaultConfig (struct iotmiDev_DataModelHandler_Config *config)
 This API initializes a default Data Model Handler config.
 
iotmiDev_DMStatus iotmiDev_DataModelHandler_threadLoop (const struct iotmiDev_DataModelHandler_Config *config)
 The thread loop function for the Data Model Handler task.
 
iotmiDev_DMStatus iotmiDev_DataModelHandler_stop ()
 This stops the data model handler loop.
 
iotmiDev_DMStatus iotmiDev_DataModelHandler_postAttrChange (struct iotmiDev_Agent *agent, const iotmiDev_AttributeMetaData *meta, const void *newValue, size_t newValueSize, bool immediate)
 The function to post an attribute change.
 
iotmiDev_DMStatus iotmiDev_DataModelHandler_postEvent (struct iotmiDev_Agent *agent, const iotmiDev_EventMetaData *meta, const void *event, size_t eventSize, bool immediate)
 The function to post an event.
 
iotmiDev_DMStatus iotmiDev_DataModelHandler_registerAttrMappings (const iotmiDev_DataModelHandler_AttrMapping *mappings, size_t len)
 This API registers attribute mappings for attributes.
 
iotmiDev_DMStatus iotmiDev_DataModelHandler_registerCommandMappings (const iotmiDev_DataModelHandler_CommandMapping *mappings, size_t len)
 This API registers command mappings for commands.
 
iotmiDev_DMStatus iotmiDev_DataModelHandler_registerEventMappings (const iotmiDev_DataModelHandler_EventMapping *mappings, size_t len)
 This API registers event mappings for events.
 
iotmiDev_DMStatus iotmiDev_DataModelHandler_registerCustomSchemaMappings (const iotmiDev_DataModelHandler_CustomSchemaMapping *mappings, size_t len)
 This API registers custom schema mappings for clusters.
 

Detailed Description

This file defines the API for data model handler.

Function Documentation

◆ iotmiDev_DataModelHandler_initDefaultConfig()

void iotmiDev_DataModelHandler_initDefaultConfig ( struct iotmiDev_DataModelHandler_Config *  config)

This API initializes a default Data Model Handler config.

This function fills the config with default reasonable values. We suggest to use the function to get the default values and then tweak values if necessary.

Parameters
[in]configPointer to the config

◆ iotmiDev_DataModelHandler_postAttrChange()

iotmiDev_DMStatus iotmiDev_DataModelHandler_postAttrChange ( struct iotmiDev_Agent *  agent,
const iotmiDev_AttributeMetaData *  meta,
const void *  newValue,
size_t  newValueSize,
bool  immediate 
)

The function to post an attribute change.

The function post an attribute change into the sending message queue of the data model handler. Note that the caller should know the exact type of the value, iotmiDev_DMStatusInvalidArg will be returned if the size of the value does not match.

Parameters
[in]agentThe agent passed in iotmiDev_DataModelHandler_ThreadLoop()
[in]metaThe metadata to identify an attribute.
[in]newValueA pointer to the new value.
[in]newValueSizethe size of the newValue, used to check if the caller used the right type
[in]immediateA hint to tell data model handler to send the message immediately or not.
Return values
iotmiDev_DMStatusInvalidArgif the size of the value does not match.
iotmiDev_DMStatusUnsupportedif the attribute is not supported.
iotmiDev_DMStatusInvalidInStateif the data model handler is not currently alive.
iotmiDev_DMStatusOkon successes.

◆ iotmiDev_DataModelHandler_postEvent()

iotmiDev_DMStatus iotmiDev_DataModelHandler_postEvent ( struct iotmiDev_Agent *  agent,
const iotmiDev_EventMetaData *  meta,
const void *  event,
size_t  eventSize,
bool  immediate 
)

The function to post an event.

The function post an event into the sending message queue of the data model handler. Note that the caller should know the exact type of the event, iotmiDev_DMStatusInvalidArg will be returned if the size of the event does not match.

Parameters
[in]agentThe agent passed in iotmiDev_DataModelHandler_ThreadLoop()
[in]metaThe metadata to identify an attribute.
[in]eventA pointer to the event.
[in]eventSizethe size of the event, used to check if the caller used the right type
[in]immediateA hint to tell data model handler to send the message immediately or not.
Return values
iotmiDev_DMStatusInvalidArgif the size of the event does not match.
iotmiDev_DMStatusUnsupportedif the event is not supported.
iotmiDev_DMStatusInvalidInStateif the data model handler is not currently alive.
iotmiDev_DMStatusOkon successes.

◆ iotmiDev_DataModelHandler_registerAttrMappings()

iotmiDev_DMStatus iotmiDev_DataModelHandler_registerAttrMappings ( const iotmiDev_DataModelHandler_AttrMapping *  mappings,
size_t  len 
)

This API registers attribute mappings for attributes.

This function currently assumes all attributes for a cluster will be registered altogether at the same time. We might loosen this limitation later.

Note
This is not intended to be called by normal users. It should only be called by generated cluster-specific sources.
This should only be called before data model thread is running.
Parameters
[in]mappingsPointer to an array of mappings
[in]lenNumber of elements in mappings
Returns
iotmiDev_DMStatusFail on out of memory

◆ iotmiDev_DataModelHandler_registerCommandMappings()

iotmiDev_DMStatus iotmiDev_DataModelHandler_registerCommandMappings ( const iotmiDev_DataModelHandler_CommandMapping *  mappings,
size_t  len 
)

This API registers command mappings for commands.

This function currently assumes all commands for a cluster will be registered altogether at the same time. We might loosen this limitation later.

Note
This is not intended to be called by normal users. It should only be called by generated cluster-specific sources.
This should only be called before data model thread is running.
Parameters
[in]mappingsPointer to an array of mappings
[in]lenNumber of elements in mappings
Returns
iotmiDev_DMStatusFail on out of memory

◆ iotmiDev_DataModelHandler_registerCustomSchemaMappings()

iotmiDev_DMStatus iotmiDev_DataModelHandler_registerCustomSchemaMappings ( const iotmiDev_DataModelHandler_CustomSchemaMapping *  mappings,
size_t  len 
)

This API registers custom schema mappings for clusters.

This function handles registration of new custom schema mappings. Unlike other mapping types, custom schema mappings are identified only by clusterId without a secondary entity ID. The function checks for duplicate cluster IDs to avoid re-registration.

Note
This should only be called before data model thread is running.
Parameters
[in]mappingsPointer to an array of custom schema mappings
[in]lenNumber of elements in mappings
Returns
iotmiDev_DMStatusOk on success, iotmiDev_DMStatusOutOfResource if memory allocation fails

◆ iotmiDev_DataModelHandler_registerEventMappings()

iotmiDev_DMStatus iotmiDev_DataModelHandler_registerEventMappings ( const iotmiDev_DataModelHandler_EventMapping *  mappings,
size_t  len 
)

This API registers event mappings for events.

This function currently assumes all events for a cluster will be registered altogether at the same time. We might loosen this limitation later.

Note
This is not intended to be called by normal users. It should only be called by generated cluster-specific sources.
This should only be called before data model thread is running.
Parameters
[in]mappingsPointer to an array of mappings
[in]lenNumber of elements in mappings
Returns
iotmiDev_DMStatusFail on out of memory

◆ iotmiDev_DataModelHandler_stop()

iotmiDev_DMStatus iotmiDev_DataModelHandler_stop ( )

This stops the data model handler loop.

Note
the function does not wait the data model handler loop to stop completely. If the data model handler loop is handling requests, it will stop after finishing current work.
Return values
iotmiDev_DMStatusOkif the data model handler loop is running and now being stopped.
iotmiDev_DMStatusInvalidInStateif the data model handler loop is not running

◆ iotmiDev_DataModelHandler_threadLoop()

iotmiDev_DMStatus iotmiDev_DataModelHandler_threadLoop ( const struct iotmiDev_DataModelHandler_Config *  config)

The thread loop function for the Data Model Handler task.

It is responsible for handling incoming cloud messages. It is basically an endless loop, only stop by iotmiDev_DataModelHandler_stop() or fatal error occurs.

Parameters
[in]configThe configuration for the data model handler
Returns
iotmiDev_DMStatusOk if the thread is stopped by iotmiDev_DataModelHandler_Stop()