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

Go to the source code of this file.
Macros | |
| #define | DH_CONSUMER_NO_MATCH ((DHConsumerMatchStatus)0) |
| #define | DH_CONSUMER_MATCH ((DHConsumerMatchStatus)1) |
Typedefs | |
| typedef uint32_t | DHConsumerMatchStatus |
| Consumer match status enumeration. More... | |
| typedef uint64_t | DHProductionId |
| Production identifier type. More... | |
| typedef struct DHWriter_t | DHWriter |
| Opaque writer handle. More... | |
| typedef void(* | DHOnConsumerMatchUpdateCallback) (DHProductionId production_id, DHConsumerMatchStatus status, void *user_data) |
| Consumer match update callback function type for DHWriter. More... | |
Functions | |
| void | dh_writer_destroy (DHWriter *writer) |
| Destroys a writer. More... | |
| void | dh_writer_set_consumer_match_update_callback (DHWriter *writer, DHOnConsumerMatchUpdateCallback callback, void *user_data) |
| Sets the consumer match update callback. More... | |
| const char * | dh_writer_get_name (const DHWriter *writer) |
| Gets the name of a writer. More... | |
| const char * | dh_writer_get_topic_name (const DHWriter *writer) |
| Gets the topic name this writer is initialized for. More... | |
| bool | dh_writer_write_data (DHWriter *writer, const DHInstanceKeys *instance_keys, const DHTopicData *topic_data, const DHTimestamp *timestamp, DHError **error) |
| Writes data to the topic. More... | |
| bool | dh_writer_create_instance (DHWriter *writer, const DHInstanceKeys *instance_keys, const char *instance_info, bool delete_on_disconnect, DHError **error) |
| Creates a topic instance explicitly. More... | |
| bool | dh_writer_delete_instance (DHWriter *writer, const DHInstanceKeys *instance_keys, DHError **error) |
| Deletes a specific topic instance. More... | |
| bool | dh_writer_delete_all_instances (DHWriter *writer, DHError **error) |
| Deletes all instances of the topic. More... | |
| bool | dh_writer_register_production (DHWriter *writer, const DHInstanceKeys *instance_keys, DHProductionId *production_id, DHError **error) |
| Registers production intent for consumer matching. More... | |
| bool | dh_writer_unregister_production (DHWriter *writer, DHProductionId production_id, DHError **error) |
| Unregisters a production registration. More... | |
| bool | dh_writer_get_consumer_match_status (DHWriter *writer, DHProductionId production_id, DHConsumerMatchStatus *status, DHError **error) |
| Gets the current consumer match status for a production. More... | |
Writer API for Device Data Hub Client.
Provides an API for publishing data to topics via DHWriter.
DHWriter supports:
Consumer-producer matching allows applications to register their intent to produce certain types of data and receive notifications when consumers are interested in that data. This enables efficient resource management by avoiding unnecessary data production when no consumers are present.
DHWriter handles both topics with instances (where data is organized by key-value pairs) and topics without instances (where all data belongs to a single stream).
All callbacks are executed on internal library threads, so applications should keep callback processing lightweight and thread-safe.
| typedef uint32_t DHConsumerMatchStatus |
Consumer match status enumeration.
Indicates whether there are consumers interested in the data being produced. Used for consumer-producer matching to optimize resource usage.
| typedef void(* DHOnConsumerMatchUpdateCallback) (DHProductionId production_id, DHConsumerMatchStatus status, void *user_data) |
Consumer match update callback function type for DHWriter.
Called when the consumer match status changes for a registered production. This allows applications to start/stop data production based on consumer interest.
| production_id | Production ID that this update relates to |
| status | New consumer match status |
| typedef uint64_t DHProductionId |
Production identifier type.
Unique identifier for a production registration. Used to track and manage producer-consumer matching registrations.
| typedef struct DHWriter_t DHWriter |
Opaque writer handle.
Publishes data to a topic, handling both instanced and non-instanced topics with automatic instance management.
| bool dh_writer_create_instance | ( | DHWriter * | writer, |
| const DHInstanceKeys * | instance_keys, | ||
| const char * | instance_info, | ||
| bool | delete_on_disconnect, | ||
| DHError ** | error | ||
| ) |
Creates a topic instance explicitly.
Creates a new instance for the topic identified by the given key-value pairs. This is useful for pre-creating instances or when you need explicit control over instance lifecycle.
| writer | The writer (must not be NULL) |
| instance_keys | Key-value pairs that uniquely identify the instance (must not be NULL) |
| instance_info | Optional string with additional instance information (can be NULL) |
| delete_on_disconnect | If true, the instance will be deleted when the client disconnects |
| error | Output parameter for error details on failure (can be NULL to ignore) |
Possible error codes:
DH_ERR_INVALID_TOPICDH_ERR_INVALID_REQUESTDH_ERR_NOT_CONNECTEDDH_ERR_INVALID_KEYSDH_ERR_INSTANCES_NOT_SUPPORTEDDH_ERR_INSTANCE_EXISTSDH_ERR_AUTHORIZATION_FAILEDDH_ERR_MAX_INSTANCESDH_ERROR_DATA_TOO_BIGDH_ERR_INTERNAL_ERROR Deletes all instances of the topic.
Removes all instances and their samples from the topic. Use with caution as this affects all data in the topic.
| writer | The writer (must not be NULL) |
| error | Output parameter for error details on failure (can be NULL to ignore) |
Possible error codes:
DH_ERR_INVALID_TOPICDH_ERR_INVALID_REQUESTDH_ERR_AUTHORIZATION_FAILEDDH_ERR_INVALID_PARAMSDH_ERR_INVALID_KEYSDH_ERR_INSTANCES_NOT_SUPPORTEDDH_ERR_INVALID_INSTANCEDH_ERR_NOT_CONNECTEDDH_ERROR_DATA_TOO_BIGDH_ERR_INTERNAL_ERROR | bool dh_writer_delete_instance | ( | DHWriter * | writer, |
| const DHInstanceKeys * | instance_keys, | ||
| DHError ** | error | ||
| ) |
Deletes a specific topic instance.
Removes the instance identified by the given key-value pairs and all its samples from the topic.
| writer | The writer (must not be NULL) |
| instance_keys | Key-value pairs identifying the instance to delete (must not be NULL) |
| error | Output parameter for error details on failure (can be NULL to ignore) |
Possible error codes:
DH_ERR_INVALID_TOPICDH_ERR_INVALID_REQUESTDH_ERR_AUTHORIZATION_FAILEDDH_ERR_INVALID_PARAMSDH_ERR_INVALID_KEYSDH_ERR_INSTANCES_NOT_SUPPORTEDDH_ERR_INVALID_INSTANCEDH_ERR_NOT_CONNECTEDDH_ERROR_DATA_TOO_BIGDH_ERR_INTERNAL_ERROR | void dh_writer_destroy | ( | DHWriter * | writer | ) |
Destroys a writer.
Automatically cleans up any registered productions and frees all resources associated with the writer. Active instances may be deleted based on their configuration.
| writer | The writer to destroy (can be NULL) |
| bool dh_writer_get_consumer_match_status | ( | DHWriter * | writer, |
| DHProductionId | production_id, | ||
| DHConsumerMatchStatus * | status, | ||
| DHError ** | error | ||
| ) |
Gets the current consumer match status for a production.
Checks whether there are currently consumers interested in the data associated with the specified production registration.
| writer | The writer (must not be NULL) |
| production_id | The production ID to check |
| status | Output parameter for the consumer match status (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_INVALID_PRODUCTION | const char* dh_writer_get_name | ( | const DHWriter * | writer | ) |
Gets the name of a writer.
Returns the name that was specified when the writer was created.
| writer | The writer (must not be NULL) |
| const char* dh_writer_get_topic_name | ( | const DHWriter * | writer | ) |
Gets the topic name this writer is initialized for.
Returns the name of the topic that was specified when the writer was created with dh_client_create_writer(). The returned string is owned by the writer and must not be freed.
| writer | The writer (must not be NULL) |
| bool dh_writer_register_production | ( | DHWriter * | writer, |
| const DHInstanceKeys * | instance_keys, | ||
| DHProductionId * | production_id, | ||
| DHError ** | error | ||
| ) |
Registers production intent for consumer matching.
Registers the instance keys identifying the data this writer intends to produce. This enables consumer-producer matching, allowing the application to receive notifications when consumers are interested in this type of data. This is useful for optimizing resource usage by avoiding unnecessary data production.
The application will be notified via the callback set with dh_writer_set_consumer_match_update_callback() when consumers show interest in or lose interest in the registered data.
| writer | The writer (must not be NULL) |
| instance_keys | Key-value pairs identifying the instance to register production for (can be NULL). If NULL, all instances will be considered as matching. |
| production_id | Output parameter for the production ID (must not be NULL) |
| error | Output parameter for error details on failure (can be NULL to ignore) |
Possible error codes:
DH_ERR_INVALID_TOPICDH_ERR_INVALID_REQUESTDH_ERR_NOT_CONNECTEDDH_ERR_MAX_PRODUCTIONSDH_ERR_INVALID_PARAMSDH_ERROR_DATA_TOO_BIGDH_ERR_INTERNAL_ERROR | void dh_writer_set_consumer_match_update_callback | ( | DHWriter * | writer, |
| DHOnConsumerMatchUpdateCallback | callback, | ||
| void * | user_data | ||
| ) |
Sets the consumer match update callback.
Registers a callback to be invoked when the consumer match status changes for any registered production. Pass NULL to remove the callback.
| writer | The writer (must not be NULL) |
| callback | Callback function (can be NULL to remove) |
| user_data | Opaque pointer passed to the callback on each invocation (can be NULL) |
| bool dh_writer_unregister_production | ( | DHWriter * | writer, |
| DHProductionId | production_id, | ||
| DHError ** | error | ||
| ) |
Unregisters a production registration.
Removes a previously registered production. No further consumer match notifications will be received for this production ID.
| writer | The writer (must not be NULL) |
| production_id | The production ID to unregister |
| error | Output parameter for error details on failure (can be NULL to ignore) |
Possible error codes:
DH_ERR_INVALID_TOPICDH_ERR_INVALID_REQUESTDH_ERR_NOT_CONNECTEDDH_ERR_INVALID_PRODUCTIONDH_ERR_INTERNAL_ERROR | bool dh_writer_write_data | ( | DHWriter * | writer, |
| const DHInstanceKeys * | instance_keys, | ||
| const DHTopicData * | topic_data, | ||
| const DHTimestamp * | timestamp, | ||
| DHError ** | error | ||
| ) |
Writes data to the topic.
Writes the given data to the associated topic.
If the topic is defined to have instances, the data will be written to the corresponding instance. If the instance doesn't exist it must be created first.
If the topic doesn't support instances the data will be written to the default instance.
If the sample number has reached the limit the oldest sample will be removed before adding the new sample.
| writer | The writer (must not be NULL) |
| instance_keys | The instance keys identifying the target instance (can be NULL for topics without instances) |
| topic_data | The data to write (must not be NULL) |
| timestamp | Optional source timestamp (can be NULL for automatic timestamp) |
| error | Output parameter for error details on failure (can be NULL to ignore) |
Possible error codes:
DH_ERR_INVALID_TOPICDH_ERR_INVALID_REQUESTDH_ERR_NOT_CONNECTEDDH_ERR_INVALID_INSTANCEDH_ERR_AUTHORIZATION_FAILEDDH_ERR_INVALID_DATADH_ERROR_DATA_TOO_BIGDH_ERR_INTERNAL_ERROR