![]() |
Device Data Hub C API
|
subscription API for Device Data Hub Client More...
#include "datahub/common.h"

Go to the source code of this file.
Macros | |
| #define | DH_TOPIC_CREATED ((DHTopicUpdateType)0) |
| Topic was created. | |
| #define | DH_TOPIC_DELETED ((DHTopicUpdateType)1) |
| Topic was deleted. | |
| #define | DH_TOPIC_INSTANCE_CREATED ((DHTopicInstanceUpdateType)0) |
| Topic instance was created. | |
| #define | DH_TOPIC_INSTANCE_DELETED ((DHTopicInstanceUpdateType)1) |
| Topic instance was deleted. | |
| #define | DH_START_FROM_NOW ((DHStartFrom)0) |
| Start receiving only new data updates from the time of subscription. | |
| #define | DH_START_FROM_OLDEST ((DHStartFrom)1) |
| Start receiving data updates from the oldest available data. | |
Typedefs | |
| typedef uint32_t | DHTopicUpdateType |
| Topic update type enumeration. More... | |
| typedef uint32_t | DHTopicInstanceUpdateType |
| Topic instance update type enumeration. More... | |
| typedef struct DHSubscriber_t | DHSubscriber |
| Opaque subscriber handle. More... | |
| typedef void(* | DHOnTopicUpdateCallback) (const char *topic_name, DHTopicUpdateType update_type, void *user_data) |
| Topic update callback function type. More... | |
| typedef void(* | DHOnInstanceUpdateCallback) (const DHTopicInstance *topic_instance, DHTopicInstanceUpdateType update_type, void *user_data) |
| Instance update callback function type. More... | |
| typedef void(* | DHOnDataCallback) (const DHTopicSample *topic_sample, void *user_data) |
| Data update callback function type. More... | |
| typedef struct DHFilter_t | DHFilter |
| Opaque subscription filter. More... | |
| typedef uint32_t | DHStartFrom |
| typedef struct DHSubscribeOptions_t | DHSubscribeOptions |
| Opaque subscription options. More... | |
Functions | |
| DHFilter * | dh_filter_create (void) |
| Creates an empty filter. More... | |
| void | dh_filter_destroy (DHFilter *filter) |
| Destroys a filter. More... | |
| bool | dh_filter_add_topic_name (DHFilter *filter, const char *topic_name, DHError **error) |
| Adds a topic name to the filter. A sample matches if its topic name matches any of the added topic names (logical OR). More... | |
| bool | dh_filter_add_instance (DHFilter *filter, const DHInstanceKeys *instance_keys, DHError **error) |
| Adds an instance key filter. A sample matches if it matches any of the added instance key filters (logical OR). Each instance key filter can contain multiple key-value pairs that must all match (logical AND). More... | |
| bool | dh_filter_add_data_expression (DHFilter *filter, const char *data_expression, DHError **error) |
Adds a data expression to the filter. A sample matches if it matches any of the data expressions. The data expression is an expression string applied to each incoming sample to filter based on sample data content. Multiple expressions are logically OR-ed: a sample passes if it satisfies any of the added expressions. The expression is a limited subset of operators. The following operators are supported: (), ==, !=, >, >=, <=, <, and, or, not, has(). Data fields can be accessed using . notation, e.g. .field.subfield. More... | |
| DHSubscribeOptions * | dh_subscribe_options_create (void) |
| Creates a subscription options object with default settings. More... | |
| void | dh_subscribe_options_destroy (DHSubscribeOptions *options) |
| Destroys a subscription options object. More... | |
| bool | dh_subscribe_options_add_filter (DHSubscribeOptions *options, const DHFilter *filter, DHError **error) |
| Adds a filter to the subscription options. Each filter is evaluated independently and matches if any filter matches (logical OR). More... | |
| void | dh_subscribe_options_set_enable_topic_updates (DHSubscribeOptions *options, bool enable) |
| Enables or disables topic creation/deletion notifications. More... | |
| void | dh_subscribe_options_set_enable_instance_updates (DHSubscribeOptions *options, bool enable) |
| Enables or disables instance creation/deletion notifications. More... | |
| void | dh_subscribe_options_set_enable_data_updates (DHSubscribeOptions *options, bool enable) |
| Enables or disables data update notifications. More... | |
| void | dh_subscribe_options_set_start_from (DHSubscribeOptions *options, DHStartFrom start_from) |
| Sets the starting point for data delivery. More... | |
| void | dh_subscriber_destroy (DHSubscriber *subscriber) |
| Destroys a subscriber. More... | |
| const char * | dh_subscriber_get_name (const DHSubscriber *subscriber) |
| Gets the name of a subscriber. More... | |
| bool | dh_subscriber_set_topic_update_callback (DHSubscriber *subscriber, DHOnTopicUpdateCallback on_topic_update, void *user_data, DHError **error) |
| Sets the topic update callback. More... | |
| bool | dh_subscriber_set_instance_update_callback (DHSubscriber *subscriber, DHOnInstanceUpdateCallback on_instance_update, void *user_data, DHError **error) |
| Sets the instance update callback. More... | |
| bool | dh_subscriber_set_data_callback (DHSubscriber *subscriber, DHOnDataCallback on_data, void *user_data, DHError **error) |
| Sets the data callback. More... | |
| bool | dh_subscriber_subscribe (DHSubscriber *subscriber, const DHSubscribeOptions *options, DHError **error) |
| Subscribes to one or more topics with optional instance and data filtering. More... | |
| bool | dh_subscriber_unsubscribe (DHSubscriber *subscriber, DHError **error) |
| Unsubscribes from all topics. More... | |
subscription API for Device Data Hub Client
This file provides the subscription functionality for the Device Data Hub Client library. It enables applications to receive real-time data updates from topics without polling.
The subscription system provides the following subscriber type:
DHSubscriber uses a callback-based approach where the application registers listener functions that are invoked when matching data is received. Callbacks are executed on internal library threads — keep them lightweight and thread-safe.
Each subscription can be configured to receive any combination of:
Content filtering can be applied to receive only data matching specific criteria.
| typedef struct DHFilter_t DHFilter |
Opaque subscription filter.
Represents a single filter used to match incoming samples. A filter carries three independent criteria — topic names, instance key sets, and data expressions — that are each logically OR-ed within the filter: a sample passes if its topic name matches any added topic name, its instance matches any added instance key set, or its data satisfies any added data expression.
Create with dh_filter_create() and destroy with dh_filter_destroy().
| typedef void(* DHOnDataCallback) (const DHTopicSample *topic_sample, void *user_data) |
Data update callback function type.
Called when new data matching the subscription filters is received. This is the primary callback for receiving topic data.
| topic_sample | The received topic sample (must not be NULL) |
| user_data | User-provided context pointer |
| typedef void(* DHOnInstanceUpdateCallback) (const DHTopicInstance *topic_instance, DHTopicInstanceUpdateType update_type, void *user_data) |
Instance update callback function type.
Called when a topic instance matching the subscription filters is created or deleted.
| topic_instance | The topic instance that was updated (must not be NULL) |
| update_type | Whether the instance was created or deleted |
| user_data | User-provided context pointer |
| typedef void(* DHOnTopicUpdateCallback) (const char *topic_name, DHTopicUpdateType update_type, void *user_data) |
Topic update callback function type.
Called when a topic matching the subscription filters is created or deleted.
| topic_name | Name of the topic that was updated (must not be NULL) |
| update_type | Whether the topic was created or deleted |
| user_data | User-provided context pointer |
| typedef struct DHSubscribeOptions_t DHSubscribeOptions |
Opaque subscription options.
Aggregates one or more DHFilter objects and update-enable flags into a single configuration passed to a subscribe call. Multiple filters are logically OR-ed: a sample matches if any filter matches.
Create with dh_subscribe_options_create() and destroy with dh_subscribe_options_destroy().
| typedef struct DHSubscriber_t DHSubscriber |
Opaque subscriber handle.
Represents a subscriber for receiving data from one or more topics simultaneously.
| typedef uint32_t DHTopicInstanceUpdateType |
Topic instance update type enumeration.
Indicates whether a topic instance was created or deleted. Used in topic instance update callbacks.
| typedef uint32_t DHTopicUpdateType |
Topic update type enumeration.
Indicates whether a topic was created or deleted. Used in topic update callbacks.
| bool dh_filter_add_data_expression | ( | DHFilter * | filter, |
| const char * | data_expression, | ||
| DHError ** | error | ||
| ) |
Adds a data expression to the filter. A sample matches if it matches any of the data expressions. The data expression is an expression string applied to each incoming sample to filter based on sample data content. Multiple expressions are logically OR-ed: a sample passes if it satisfies any of the added expressions. The expression is a limited subset of operators. The following operators are supported: (), ==, !=, >, >=, <=, <, and, or, not, has(). Data fields can be accessed using . notation, e.g. .field.subfield.
| filter | The filter to modify (must not be NULL) |
| data_expression | The data expression (must not be NULL) |
| error | Output parameter for error details on failure (can be NULL to ignore) |
| bool dh_filter_add_instance | ( | DHFilter * | filter, |
| const DHInstanceKeys * | instance_keys, | ||
| DHError ** | error | ||
| ) |
Adds an instance key filter. A sample matches if it matches any of the added instance key filters (logical OR). Each instance key filter can contain multiple key-value pairs that must all match (logical AND).
| filter | The filter to modify (must not be NULL) |
| instance_keys | The instance keys to add as a filter (must not be NULL) |
| error | Output parameter for error details on failure (can be NULL to ignore) |
Adds a topic name to the filter. A sample matches if its topic name matches any of the added topic names (logical OR).
| filter | The filter to modify (must not be NULL) |
| topic_name | The topic name to add (must not be NULL) |
| error | Output parameter for error details on failure (can be NULL to ignore) |
| DHFilter* dh_filter_create | ( | void | ) |
Creates an empty filter.
| void dh_filter_destroy | ( | DHFilter * | filter | ) |
Destroys a filter.
Frees all resources associated with the filter.
| filter | The filter to destroy (can be NULL) |
| bool dh_subscribe_options_add_filter | ( | DHSubscribeOptions * | options, |
| const DHFilter * | filter, | ||
| DHError ** | error | ||
| ) |
Adds a filter to the subscription options. Each filter is evaluated independently and matches if any filter matches (logical OR).
| options | The subscription options (must not be NULL) |
| filter | The filter to add (must not be NULL) |
| error | Output parameter for error details on failure (can be NULL to ignore) |
| DHSubscribeOptions* dh_subscribe_options_create | ( | void | ) |
Creates a subscription options object with default settings.
Default: no filters, all update types disabled, start from now.
| void dh_subscribe_options_destroy | ( | DHSubscribeOptions * | options | ) |
Destroys a subscription options object.
| options | The options to destroy (can be NULL) |
| void dh_subscribe_options_set_enable_data_updates | ( | DHSubscribeOptions * | options, |
| bool | enable | ||
| ) |
Enables or disables data update notifications.
| options | The options to modify (must not be NULL) |
| enable | true to enable, false to disable |
| void dh_subscribe_options_set_enable_instance_updates | ( | DHSubscribeOptions * | options, |
| bool | enable | ||
| ) |
Enables or disables instance creation/deletion notifications.
| options | The options to modify (must not be NULL) |
| enable | true to enable, false to disable |
| void dh_subscribe_options_set_enable_topic_updates | ( | DHSubscribeOptions * | options, |
| bool | enable | ||
| ) |
Enables or disables topic creation/deletion notifications.
| options | The options to modify (must not be NULL) |
| enable | true to enable, false to disable |
| void dh_subscribe_options_set_start_from | ( | DHSubscribeOptions * | options, |
| DHStartFrom | start_from | ||
| ) |
Sets the starting point for data delivery.
| options | The options to modify (must not be NULL) |
| start_from | DH_START_FROM_NOW or DH_START_FROM_OLDEST |
| void dh_subscriber_destroy | ( | DHSubscriber * | subscriber | ) |
Destroys a subscriber.
Automatically unsubscribes if still subscribed and frees all resources associated with the subscriber.
| subscriber | The subscriber to destroy (can be NULL) |
| const char* dh_subscriber_get_name | ( | const DHSubscriber * | subscriber | ) |
Gets the name of a subscriber.
Returns the name that was specified when the subscriber was created.
| subscriber | The subscriber (must not be NULL) |
| bool dh_subscriber_set_data_callback | ( | DHSubscriber * | subscriber, |
| DHOnDataCallback | on_data, | ||
| void * | user_data, | ||
| DHError ** | error | ||
| ) |
Sets the data callback.
Registers a callback to be invoked when a data sample matching the subscription is received. Pass NULL to remove the callback.
| subscriber | The subscriber (must not be NULL) |
| on_data | Callback function (can be NULL to remove) |
| user_data | Opaque pointer passed to the callback on each invocation (can be NULL) |
| error | Output parameter for error details on failure (can be NULL to ignore) |
| bool dh_subscriber_set_instance_update_callback | ( | DHSubscriber * | subscriber, |
| DHOnInstanceUpdateCallback | on_instance_update, | ||
| void * | user_data, | ||
| DHError ** | error | ||
| ) |
Sets the instance update callback.
Registers a callback to be invoked when a topic instance matching the subscription is created or deleted. Pass NULL to remove the callback.
| subscriber | The subscriber (must not be NULL) |
| on_instance_update | Callback function (can be NULL to remove) |
| user_data | Opaque pointer passed to the callback on each invocation (can be NULL) |
| error | Output parameter for error details on failure (can be NULL to ignore) |
| bool dh_subscriber_set_topic_update_callback | ( | DHSubscriber * | subscriber, |
| DHOnTopicUpdateCallback | on_topic_update, | ||
| void * | user_data, | ||
| DHError ** | error | ||
| ) |
Sets the topic update callback.
Registers a callback to be invoked when a topic matching the subscription is created or deleted. Pass NULL to remove the callback.
| subscriber | The subscriber (must not be NULL) |
| on_topic_update | Callback function (can be NULL to remove) |
| user_data | Opaque pointer passed to the callback on each invocation (can be NULL) |
| error | Output parameter for error details on failure (can be NULL to ignore) |
| bool dh_subscriber_subscribe | ( | DHSubscriber * | subscriber, |
| const DHSubscribeOptions * | options, | ||
| DHError ** | error | ||
| ) |
Subscribes to one or more topics with optional instance and data filtering.
Establishes a subscription to receive data from one or more topics, with optional filtering by instance keys and/or a data filter expression.
| subscriber | The subscriber (must not be NULL) |
| options | Subscription options specifying filters and update types (must not be NULL) |
| error | Output parameter for error details on failure (can be NULL to ignore) |
Possible error codes:
DH_ERR_INVALID_PARAMSDH_ERR_INVALID_DATADH_ERR_INVALID_REQUESTDH_ERR_NOT_CONNECTEDDH_ERR_MAX_SUBSCRIPTIONSDH_ERROR_DATA_TOO_BIGDH_ERR_INTERNAL_ERROR | bool dh_subscriber_unsubscribe | ( | DHSubscriber * | subscriber, |
| DHError ** | error | ||
| ) |
Unsubscribes from all topics.
Terminates all active subscriptions for this subscriber. No further callbacks will be received after this call completes successfully.
| subscriber | The subscriber (must not be NULL) |
| error | Output parameter for error details on failure (can be NULL to ignore) |
Possible error codes:
DH_ERR_INVALID_REQUESTDH_ERR_NOT_CONNECTEDDH_ERR_INVALID_SUBSCRIPTIONDH_ERR_INTERNAL_ERROR