![]() |
Device Data Hub C API
|
Common types and utilities for Device Data Hub C Client API. More...
#include <stdbool.h>#include <stdint.h>

Go to the source code of this file.
Macros | |
| #define | DH_ERR_INVALID_PARAMS ((DHErrorCode)0) |
| Invalid or empty parameters provided to the API. | |
| #define | DH_ERROR_DATA_TOO_BIG ((DHErrorCode)1) |
| Request exceeds the maximum allowed size. | |
| #define | DH_ERR_NOT_CONNECTED ((DHErrorCode)2) |
| Operation requires connection but client is not connected. | |
| #define | DH_ERR_ALREADY_CONNECTED ((DHErrorCode)3) |
| Attempt to connect when already connected. | |
| #define | DH_ERR_UNKNOWN_ERROR ((DHErrorCode)4) |
| Unspecified or unknown error occurred. | |
| #define | DH_ERR_INTERNAL_ERROR ((DHErrorCode)5) |
| Internal library error or unexpected condition. | |
| #define | DH_ERR_INVALID_ID ((DHErrorCode)6) |
| Invalid identifier provided (subscription, production, etc.) | |
| #define | DH_ERR_INVALID_TOPIC ((DHErrorCode)7) |
| Topic with the given name does not exist. | |
| #define | DH_ERR_NOT_INITIALIZED ((DHErrorCode)8) |
| Component or resource not properly initialized. | |
| #define | DH_ERR_MAX_CLIENTS ((DHErrorCode)9) |
| Maximum number of clients for the server has been reached. | |
| #define | DH_ERR_MAX_CONNECTIONS ((DHErrorCode)10) |
| Maximum number of connections for this username exceeded. | |
| #define | DH_ERR_AUTHENTICATION_FAILED ((DHErrorCode)11) |
| Authentication process failed. | |
| #define | DH_ERR_TOPIC_EXISTS ((DHErrorCode)12) |
| Attempt to create a topic that already exists. | |
| #define | DH_ERR_MAX_TOPIC ((DHErrorCode)13) |
| Maximum number of topics exceeded. | |
| #define | DH_ERR_CONNECTION_ERROR ((DHErrorCode)14) |
| Network or communication connection error. | |
| #define | DH_ERR_INVALID_DATA ((DHErrorCode)15) |
| Invalid data format or content provided. | |
| #define | DH_ERR_INVALID_INSTANCE ((DHErrorCode)16) |
| Instance does not exist. | |
| #define | DH_ERR_INVALID_KEYS ((DHErrorCode)17) |
| Invalid instance keys provided. | |
| #define | DH_ERR_INVALID_SUBSCRIPTION ((DHErrorCode)18) |
| Subscription does not exist. | |
| #define | DH_ERR_INSTANCE_EXISTS ((DHErrorCode)19) |
| Attempt to create an instance that already exists. | |
| #define | DH_ERR_INSTANCES_NOT_SUPPORTED ((DHErrorCode)20) |
| Topic does not support instances. | |
| #define | DH_ERR_MAX_INSTANCES ((DHErrorCode)21) |
| Maximum number of instances exceeded for the topic. | |
| #define | DH_ERR_MAX_SUBSCRIPTIONS ((DHErrorCode)22) |
| Maximum number of subscriptions exceeded for this client. | |
| #define | DH_ERR_AUTHORIZATION_FAILED ((DHErrorCode)23) |
| Insufficient permissions for the requested operation. | |
| #define | DH_ERR_MAX_PRODUCTIONS ((DHErrorCode)24) |
| Maximum number of data productions exceeded for this client. | |
| #define | DH_ERR_INVALID_PRODUCTION ((DHErrorCode)25) |
| Production ID not found or not registered with RegisterProduction() | |
| #define | DH_ERR_INVALID_REQUEST ((DHErrorCode)26) |
| Malformed or invalid request. | |
| #define | DH_ERR_CREDENTIAL_ERROR ((DHErrorCode)27) |
| Invalid or missing credentials. | |
Typedefs | |
| typedef uint32_t | DHErrorCode |
| API error codes enumeration. More... | |
| typedef struct DHError_t | DHError |
| Opaque error. More... | |
| typedef struct DHTimestamp_t | DHTimestamp |
| Opaque UTC timestamp. More... | |
| typedef struct DHTopic_t | DHTopic |
| Opaque topic. More... | |
| typedef struct DHTopicData_t | DHTopicData |
| Opaque topic data. More... | |
| typedef struct DHInstanceKeys_t | DHInstanceKeys |
| Opaque instance keys. More... | |
| typedef struct DHTopicInstance_t | DHTopicInstance |
| Opaque topic instance. More... | |
| typedef struct DHTopicSample_t | DHTopicSample |
| Opaque topic sample. More... | |
| typedef struct DHTopicList_t | DHTopicList |
| Opaque topic list. More... | |
| typedef struct DHTopicInstanceList_t | DHTopicInstanceList |
| Opaque topic instance list. More... | |
Functions | |
| const char * | dh_error_get_message (const DHError *err) |
| Gets the error message from an error object. More... | |
| DHErrorCode | dh_error_get_code (const DHError *err) |
| Gets the error code from an error object. More... | |
| const char * | dh_error_code_to_string (DHErrorCode code) |
| Converts an error code to its string representation. More... | |
| const char * | dh_error_to_string (const DHError *err) |
| Gets a string representation of the complete error. More... | |
| void | dh_error_destroy (DHError *err) |
| Destroys an error object. More... | |
| DHTimestamp * | dh_timestamp_create (void) |
| Creates a timestamp set to the current time. More... | |
| void | dh_timestamp_set_with_sec (DHTimestamp *timestamp, int64_t seconds) |
| Sets the timestamp from a Unix epoch value in seconds. More... | |
| void | dh_timestamp_set_with_ms (DHTimestamp *timestamp, int64_t milliseconds) |
| Sets the timestamp from a Unix epoch value in milliseconds. More... | |
| void | dh_timestamp_set_current (DHTimestamp *timestamp) |
| Updates the timestamp to the current time. More... | |
| int64_t | dh_timestamp_get_as_sec (const DHTimestamp *timestamp) |
| Gets the timestamp value as seconds since Unix epoch. More... | |
| int64_t | dh_timestamp_get_as_ms (const DHTimestamp *timestamp) |
| Gets the timestamp value as milliseconds since Unix epoch. More... | |
| void | dh_timestamp_destroy (DHTimestamp *timestamp) |
| Destroys a timestamp. More... | |
| const char * | dh_topic_get_name (const DHTopic *topic) |
| Gets the name of a topic. More... | |
| const char * | dh_topic_get_json_definition (const DHTopic *topic, DHError **error) |
| Gets the topic definition as a JSON string. More... | |
| void | dh_topic_destroy (DHTopic *topic) |
| Destroys a topic. More... | |
| DHTopicData * | dh_topic_data_create (void) |
| Creates an empty topic data object. More... | |
| void | dh_topic_data_destroy (DHTopicData *topic_data) |
| Destroys a topic data object. More... | |
| bool | dh_topic_data_set_json_data (DHTopicData *topic_data, const char *json_str, DHError **error) |
| Sets the value of topic data from JSON string. More... | |
| const char * | dh_topic_data_get_json_data (const DHTopicData *topic_data) |
| Gets the topic data value as a JSON string. More... | |
| const char * | dh_topic_sample_get_topic_name (const DHTopicSample *topic_sample) |
| Gets the topic name from a sample. More... | |
| uint64_t | dh_topic_sample_get_sample_id (const DHTopicSample *topic_sample) |
| Gets the sample ID. More... | |
| bool | dh_topic_sample_is_historical (const DHTopicSample *topic_sample) |
| Checks if the sample is historical data. More... | |
| const DHTimestamp * | dh_topic_sample_get_timestamp (const DHTopicSample *topic_sample) |
| Gets the source timestamp. More... | |
| const DHTopicData * | dh_topic_sample_get_data (const DHTopicSample *topic_sample) |
| Gets the topic data from a sample. More... | |
| DHInstanceKeys * | dh_instance_keys_create (void) |
| Creates an empty instance keys object. More... | |
| void | dh_instance_keys_destroy (DHInstanceKeys *keys) |
| Destroys an instance keys object. More... | |
| bool | dh_instance_keys_add_string (DHInstanceKeys *keys, const char *name, const char *value, DHError **error) |
| Adds a string key-value pair. More... | |
| bool | dh_instance_keys_add_integer (DHInstanceKeys *keys, const char *name, int64_t value, DHError **error) |
| Adds an integer key-value pair. More... | |
| bool | dh_instance_keys_has_key (const DHInstanceKeys *keys, const char *name) |
| Checks whether a key exists. More... | |
| bool | dh_instance_keys_get_string (const DHInstanceKeys *keys, const char *name, const char **out_value, DHError **error) |
| Gets the string value of a key. More... | |
| bool | dh_instance_keys_get_integer (const DHInstanceKeys *keys, const char *name, int64_t *out_value, DHError **error) |
| Gets the integer value of a key. More... | |
| bool | dh_instance_keys_remove (DHInstanceKeys *keys, const char *name, DHError **error) |
| Removes a key. More... | |
| const char * | dh_topic_instance_get_topic_name (const DHTopicInstance *topic_instance) |
| Gets the topic name of an instance. More... | |
| const DHInstanceKeys * | dh_topic_instance_get_keys (const DHTopicInstance *topic_instance) |
| Gets the instance keys. More... | |
| const char * | dh_topic_instance_get_info (const DHTopicInstance *topic_instance) |
| Gets the instance information. More... | |
| void | dh_topic_instance_destroy (DHTopicInstance *topic_instance) |
| Destroys a topic instance. More... | |
| uint32_t | dh_topic_list_get_count (const DHTopicList *list) |
| Gets the number of topics in the list. More... | |
| const char * | dh_topic_list_get_name (const DHTopicList *list, uint32_t index) |
| Gets a topic name by index. More... | |
| void | dh_topic_list_destroy (DHTopicList *topic_list) |
| Frees a topic list. More... | |
| uint32_t | dh_topic_instance_list_get_count (const DHTopicInstanceList *list) |
| Gets the number of instances in the list. More... | |
| const DHTopicInstance * | dh_topic_instance_list_get (const DHTopicInstanceList *list, uint32_t index) |
| Gets a topic instance by index. More... | |
| void | dh_topic_instance_list_destroy (DHTopicInstanceList *instance_list) |
| Frees a topic instance list. More... | |
Common types and utilities for Device Data Hub C Client API.
This file contains fundamental types, structures, and utility functions used throughout the Device Data Hub C Client library. It provides the core data structures for topics, samples, instances, and error handling.
The data model is designed around topics which are units of information used to exchange data between decoupled components (consumer/producer). Each topic can have a subset of data groups called instances, and each instance can have samples as historical data.
Error handling is centralized through the DHError structure which provides both error codes and human-readable messages.
All data values are represented as JSON strings to provide structured data handling capabilities.
| typedef struct DHError_t DHError |
Opaque error.
Represents an error condition with both an error code and descriptive message. This structure encapsulates error information with both an error code and message.
| typedef uint32_t DHErrorCode |
API error codes enumeration.
Defines all possible error conditions that can occur when using the Device Data Hub C Client API.
| typedef struct DHInstanceKeys_t DHInstanceKeys |
Opaque instance keys.
Represents a set of typed key-value pairs that uniquely identify a topic instance. Keys can hold either string or integer values
| typedef struct DHTimestamp_t DHTimestamp |
Opaque UTC timestamp.
Represents a point in time with nanosecond precision. Use dh_timestamp_get_as_sec() or dh_timestamp_get_as_ms() to retrieve the value.
| typedef struct DHTopic_t DHTopic |
Opaque topic.
Represents a topic on the Device Data Hub. Topics are units of information used to exchange data between components. Each topic has a definition that describes its name, payload structure, QoS settings, etc.
| typedef struct DHTopicData_t DHTopicData |
Opaque topic data.
Represents the structured data content of a topic. The data is stored internally as JSON and can be manipulated using the topic_data_* functions.
| typedef struct DHTopicInstance_t DHTopicInstance |
Opaque topic instance.
Represents a specific instance of a topic. Instances are identified by a combination of key-value pairs and allow topics to contain multiple separate data streams (e.g., multiple detected objects, multiple I/O ports). TopicInstance objects represent specific instances of topics identified by their keys.
| typedef struct DHTopicInstanceList_t DHTopicInstanceList |
Opaque topic instance list.
Contains an array of topic instances returned by instance listing operations. Must be freed using dh_topic_instance_list_destroy().
| typedef struct DHTopicList_t DHTopicList |
Opaque topic list.
Contains an array of topic names returned by topic listing operations. Must be freed using dh_topic_list_destroy().
| typedef struct DHTopicSample_t DHTopicSample |
Opaque topic sample.
Represents a single data sample within a topic or topic instance. Samples contain the actual data along with metadata like timestamps.
| const char* dh_error_code_to_string | ( | DHErrorCode | code | ) |
Converts an error code to its string representation.
Returns a human-readable string name for the given error code. For example, DH_ERR_INVALID_PARAMS returns "DH_ERR_INVALID_PARAMS".
| code | The error code to convert |
| void dh_error_destroy | ( | DHError * | err | ) |
Destroys an error object.
Frees all resources associated with the error object.
| err | The error object to destroy (can be NULL) |
| DHErrorCode dh_error_get_code | ( | const DHError * | err | ) |
Gets the error code from an error object.
Returns the specific error code that identifies the type of error.
| err | The error object (must not be NULL) |
| const char* dh_error_get_message | ( | const DHError * | err | ) |
Gets the error message from an error object.
Returns a human-readable description of the error condition.
| err | The error object (must not be NULL) |
| const char* dh_error_to_string | ( | const DHError * | err | ) |
Gets a string representation of the complete error.
Returns a formatted string containing both the error code and message. The returned string is owned by the error object and should not be freed.
| err | The error object (must not be NULL) |
| bool dh_instance_keys_add_integer | ( | DHInstanceKeys * | keys, |
| const char * | name, | ||
| int64_t | value, | ||
| DHError ** | error | ||
| ) |
Adds an integer key-value pair.
| keys | The DHInstanceKeys (must not be NULL) |
| name | The key name (must not be NULL) |
| value | The integer value |
| error | Output parameter for error details on failure (can be NULL to ignore) |
| bool dh_instance_keys_add_string | ( | DHInstanceKeys * | keys, |
| const char * | name, | ||
| const char * | value, | ||
| DHError ** | error | ||
| ) |
Adds a string key-value pair.
| keys | The DHInstanceKeys (must not be NULL) |
| name | The key name (must not be NULL) |
| value | The string value (must not be NULL) |
| error | Output parameter for error details on failure (can be NULL to ignore) |
| DHInstanceKeys* dh_instance_keys_create | ( | void | ) |
Creates an empty instance keys object.
| void dh_instance_keys_destroy | ( | DHInstanceKeys * | keys | ) |
Destroys an instance keys object.
| keys | The DHInstanceKeys to destroy (can be NULL) |
| bool dh_instance_keys_get_integer | ( | const DHInstanceKeys * | keys, |
| const char * | name, | ||
| int64_t * | out_value, | ||
| DHError ** | error | ||
| ) |
Gets the integer value of a key.
| keys | The DHInstanceKeys (must not be NULL) |
| name | The key name (must not be NULL) |
| out_value | Output pointer set to the integer value on success (must not be NULL) |
| error | Output parameter for error details on failure (can be NULL to ignore) |
| bool dh_instance_keys_get_string | ( | const DHInstanceKeys * | keys, |
| const char * | name, | ||
| const char ** | out_value, | ||
| DHError ** | error | ||
| ) |
Gets the string value of a key.
| keys | The DHInstanceKeys (must not be NULL) |
| name | The key name (must not be NULL) |
| out_value | Output pointer set to the string value on success (must not be NULL). The returned string is owned by the DHInstanceKeys and must not be freed. |
| error | Output parameter for error details on failure (can be NULL to ignore) |
| bool dh_instance_keys_has_key | ( | const DHInstanceKeys * | keys, |
| const char * | name | ||
| ) |
Checks whether a key exists.
| keys | The DHInstanceKeys (must not be NULL) |
| name | The key name to look up (must not be NULL) |
| bool dh_instance_keys_remove | ( | DHInstanceKeys * | keys, |
| const char * | name, | ||
| DHError ** | error | ||
| ) |
Removes a key.
| keys | The DHInstanceKeys (must not be NULL) |
| name | The key name to remove (must not be NULL) |
| error | Output parameter for error details on failure (can be NULL to ignore) |
| DHTimestamp* dh_timestamp_create | ( | void | ) |
Creates a timestamp set to the current time.
| void dh_timestamp_destroy | ( | DHTimestamp * | timestamp | ) |
Destroys a timestamp.
Frees all resources associated with the DHTimestamp.
| timestamp | The timestamp to destroy (can be NULL) |
| int64_t dh_timestamp_get_as_ms | ( | const DHTimestamp * | timestamp | ) |
Gets the timestamp value as milliseconds since Unix epoch.
| timestamp | The timestamp (must not be NULL) |
| int64_t dh_timestamp_get_as_sec | ( | const DHTimestamp * | timestamp | ) |
Gets the timestamp value as seconds since Unix epoch.
| timestamp | The timestamp (must not be NULL) |
| void dh_timestamp_set_current | ( | DHTimestamp * | timestamp | ) |
Updates the timestamp to the current time.
| timestamp | The timestamp to update (must not be NULL) |
| void dh_timestamp_set_with_ms | ( | DHTimestamp * | timestamp, |
| int64_t | milliseconds | ||
| ) |
Sets the timestamp from a Unix epoch value in milliseconds.
| timestamp | The timestamp to update (must not be NULL) |
| milliseconds | Milliseconds since Unix epoch (1970-01-01 00:00:00 UTC) |
| void dh_timestamp_set_with_sec | ( | DHTimestamp * | timestamp, |
| int64_t | seconds | ||
| ) |
Sets the timestamp from a Unix epoch value in seconds.
| timestamp | The timestamp to update (must not be NULL) |
| seconds | Seconds since Unix epoch (1970-01-01 00:00:00 UTC) |
| DHTopicData* dh_topic_data_create | ( | void | ) |
Creates an empty topic data object.
Creates a new DHTopicData with an empty value.
| void dh_topic_data_destroy | ( | DHTopicData * | topic_data | ) |
Destroys a topic data object.
Frees all resources associated with the DHTopicData.
| topic_data | The DHTopicData to destroy (can be NULL) |
| const char* dh_topic_data_get_json_data | ( | const DHTopicData * | topic_data | ) |
Gets the topic data value as a JSON string.
Returns the current topic data value as a JSON-formatted string. The returned string is owned by the DHTopicData object and should not be freed.
| topic_data | The DHTopicData (must not be NULL) |
| bool dh_topic_data_set_json_data | ( | DHTopicData * | topic_data, |
| const char * | json_str, | ||
| DHError ** | error | ||
| ) |
Sets the value of topic data from JSON string.
Parses the JSON string and updates the topic data with the new value.
| topic_data | The DHTopicData (must not be NULL) |
| json_str | JSON string containing the new value (must not be NULL) |
| error | Output parameter for error details on failure (can be NULL to ignore) |
Possible error conditions:
DH_ERR_INVALID_PARAMS) | void dh_topic_destroy | ( | DHTopic * | topic | ) |
Destroys a topic.
Frees resources associated with a topic. Does not delete the topic from the Device Data Hub, only releases local resources.
| topic | The topic to destroy |
Gets the topic definition as a JSON string.
Returns a reference to the topic definition as a string in JSON format. The returned string is owned by the topic object and should not be freed.
| topic | The topic (must not be NULL) |
| error | Output parameter for error details on failure (can be NULL to ignore) |
| const char* dh_topic_get_name | ( | const DHTopic * | topic | ) |
Gets the name of a topic.
Returns the topic name as specified in the topic definition.
| topic | The topic (must not be NULL) |
| void dh_topic_instance_destroy | ( | DHTopicInstance * | topic_instance | ) |
Destroys a topic instance.
Frees all resources associated with the DHTopicInstance.
| topic_instance | The DHTopicInstance to destroy (can be NULL) |
| const char* dh_topic_instance_get_info | ( | const DHTopicInstance * | topic_instance | ) |
Gets the instance information.
Returns additional information associated with this instance, if any. The returned string is owned by the DHTopicInstance and should not be modified or freed.
| topic_instance | The DHTopicInstance (must not be NULL) |
| const DHInstanceKeys* dh_topic_instance_get_keys | ( | const DHTopicInstance * | topic_instance | ) |
Gets the instance keys.
Returns the key-value pairs that identify this specific instance. The returned DHInstanceKeys object is owned by the DHTopicInstance and should not be modified or freed.
| topic_instance | The TopicInstance (must not be NULL) |
| const char* dh_topic_instance_get_topic_name | ( | const DHTopicInstance * | topic_instance | ) |
Gets the topic name of an instance.
Returns the name of the topic that this instance belongs to.
| topic_instance | The TopicInstance (must not be NULL) |
| void dh_topic_instance_list_destroy | ( | DHTopicInstanceList * | instance_list | ) |
Frees a topic instance list.
Releases memory allocated for an instance list returned by dh_client_get_topic_instances().
| instance_list | The instance list to free (can be NULL) |
| const DHTopicInstance* dh_topic_instance_list_get | ( | const DHTopicInstanceList * | list, |
| uint32_t | index | ||
| ) |
Gets a topic instance by index.
Returns the topic instance at the specified index. The returned pointer is owned by the DHTopicInstanceList and should not be freed.
| list | The DHTopicInstanceList (must not be NULL) |
| index | Zero-based index into the list. Must be less than the value returned by dh_topic_instance_list_get_count() |
| uint32_t dh_topic_instance_list_get_count | ( | const DHTopicInstanceList * | list | ) |
Gets the number of instances in the list.
| list | The DHTopicInstanceList (must not be NULL) |
| void dh_topic_list_destroy | ( | DHTopicList * | topic_list | ) |
Frees a topic list.
Releases memory allocated for a topic list returned by dh_client_get_topic_list().
| topic_list | The topic list to free (can be NULL) |
| uint32_t dh_topic_list_get_count | ( | const DHTopicList * | list | ) |
Gets the number of topics in the list.
| list | The DHTopicList (must not be NULL) |
| const char* dh_topic_list_get_name | ( | const DHTopicList * | list, |
| uint32_t | index | ||
| ) |
Gets a topic name by index.
Returns the topic name at the specified index. The returned string is owned by the DHTopicList and should not be freed.
| list | The DHTopicList (must not be NULL) |
| index | Zero-based index into the list. Must be less than the value returned by dh_topic_list_get_count() |
| const DHTopicData* dh_topic_sample_get_data | ( | const DHTopicSample * | topic_sample | ) |
Gets the topic data from a sample.
Returns the topic data contained in this sample. The returned pointer is owned by the TopicSample and should not be freed.
| topic_sample | The TopicSample (must not be NULL) |
| uint64_t dh_topic_sample_get_sample_id | ( | const DHTopicSample * | topic_sample | ) |
Gets the sample ID.
Returns the unique identifier for this sample within its topic.
| topic_sample | The TopicSample (must not be NULL) |
| const DHTimestamp* dh_topic_sample_get_timestamp | ( | const DHTopicSample * | topic_sample | ) |
Gets the source timestamp.
Returns the timestamp provided by the producing application when the data was written.
| topic_sample | The TopicSample (must not be NULL) |
| const char* dh_topic_sample_get_topic_name | ( | const DHTopicSample * | topic_sample | ) |
Gets the topic name from a sample.
Returns the name of the topic this sample belongs to. The returned string is owned by the DHTopicSample and should not be freed.
| topic_sample | The TopicSample (must not be NULL) |
| bool dh_topic_sample_is_historical | ( | const DHTopicSample * | topic_sample | ) |
Checks if the sample is historical data.
Returns whether this sample was received as part of cached history rather than as a live update.
| topic_sample | The TopicSample (must not be NULL) |