Device Data Hub C API
Macros | Typedefs | Functions
writer.h File Reference

Writer API for Device Data Hub Client. More...

#include "datahub/common.h"
Include dependency graph for writer.h:
This graph shows which files directly or indirectly include this file:

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...
 

Detailed Description

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 Documentation

◆ DHConsumerMatchStatus

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.

◆ DHOnConsumerMatchUpdateCallback

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.

Parameters
production_idProduction ID that this update relates to
statusNew consumer match status

◆ DHProductionId

typedef uint64_t DHProductionId

Production identifier type.

Unique identifier for a production registration. Used to track and manage producer-consumer matching registrations.

◆ DHWriter

typedef struct DHWriter_t DHWriter

Opaque writer handle.

Publishes data to a topic, handling both instanced and non-instanced topics with automatic instance management.

Function Documentation

◆ dh_writer_create_instance()

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.

Parameters
writerThe writer (must not be NULL)
instance_keysKey-value pairs that uniquely identify the instance (must not be NULL)
instance_infoOptional string with additional instance information (can be NULL)
delete_on_disconnectIf true, the instance will be deleted when the client disconnects
errorOutput parameter for error details on failure (can be NULL to ignore)
Returns
true on success, false on failure

Possible error codes:

  • DH_ERR_INVALID_TOPIC
  • DH_ERR_INVALID_REQUEST
  • DH_ERR_NOT_CONNECTED
  • DH_ERR_INVALID_KEYS
  • DH_ERR_INSTANCES_NOT_SUPPORTED
  • DH_ERR_INSTANCE_EXISTS
  • DH_ERR_AUTHORIZATION_FAILED
  • DH_ERR_MAX_INSTANCES
  • DH_ERROR_DATA_TOO_BIG
  • DH_ERR_INTERNAL_ERROR

◆ dh_writer_delete_all_instances()

bool dh_writer_delete_all_instances ( DHWriter *  writer,
DHError **  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.

Parameters
writerThe writer (must not be NULL)
errorOutput parameter for error details on failure (can be NULL to ignore)
Returns
true on success, false on failure

Possible error codes:

  • DH_ERR_INVALID_TOPIC
  • DH_ERR_INVALID_REQUEST
  • DH_ERR_AUTHORIZATION_FAILED
  • DH_ERR_INVALID_PARAMS
  • DH_ERR_INVALID_KEYS
  • DH_ERR_INSTANCES_NOT_SUPPORTED
  • DH_ERR_INVALID_INSTANCE
  • DH_ERR_NOT_CONNECTED
  • DH_ERROR_DATA_TOO_BIG
  • DH_ERR_INTERNAL_ERROR

◆ dh_writer_delete_instance()

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.

Parameters
writerThe writer (must not be NULL)
instance_keysKey-value pairs identifying the instance to delete (must not be NULL)
errorOutput parameter for error details on failure (can be NULL to ignore)
Returns
true on success, false on failure

Possible error codes:

  • DH_ERR_INVALID_TOPIC
  • DH_ERR_INVALID_REQUEST
  • DH_ERR_AUTHORIZATION_FAILED
  • DH_ERR_INVALID_PARAMS
  • DH_ERR_INVALID_KEYS
  • DH_ERR_INSTANCES_NOT_SUPPORTED
  • DH_ERR_INVALID_INSTANCE
  • DH_ERR_NOT_CONNECTED
  • DH_ERROR_DATA_TOO_BIG
  • DH_ERR_INTERNAL_ERROR

◆ dh_writer_destroy()

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.

Parameters
writerThe writer to destroy (can be NULL)

◆ dh_writer_get_consumer_match_status()

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.

Parameters
writerThe writer (must not be NULL)
production_idThe production ID to check
statusOutput parameter for the consumer match status (must not be NULL)
errorOutput parameter for error details on failure (can be NULL to ignore)
Returns
true on success, false on failure

Possible error codes:

  • DH_ERR_INVALID_REQUEST
  • DH_ERR_INVALID_PRODUCTION

◆ dh_writer_get_name()

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.

Parameters
writerThe writer (must not be NULL)
Returns
The writer name, or NULL if invalid

◆ dh_writer_get_topic_name()

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.

Parameters
writerThe writer (must not be NULL)
Returns
The topic name, or NULL if invalid

◆ dh_writer_register_production()

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.

Parameters
writerThe writer (must not be NULL)
instance_keysKey-value pairs identifying the instance to register production for (can be NULL). If NULL, all instances will be considered as matching.
production_idOutput parameter for the production ID (must not be NULL)
errorOutput parameter for error details on failure (can be NULL to ignore)
Returns
true on success, false on failure

Possible error codes:

  • DH_ERR_INVALID_TOPIC
  • DH_ERR_INVALID_REQUEST
  • DH_ERR_NOT_CONNECTED
  • DH_ERR_MAX_PRODUCTIONS
  • DH_ERR_INVALID_PARAMS
  • DH_ERROR_DATA_TOO_BIG
  • DH_ERR_INTERNAL_ERROR

◆ dh_writer_set_consumer_match_update_callback()

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.

Parameters
writerThe writer (must not be NULL)
callbackCallback function (can be NULL to remove)
user_dataOpaque pointer passed to the callback on each invocation (can be NULL)

◆ dh_writer_unregister_production()

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.

Parameters
writerThe writer (must not be NULL)
production_idThe production ID to unregister
errorOutput parameter for error details on failure (can be NULL to ignore)
Returns
true on success, false on failure

Possible error codes:

  • DH_ERR_INVALID_TOPIC
  • DH_ERR_INVALID_REQUEST
  • DH_ERR_NOT_CONNECTED
  • DH_ERR_INVALID_PRODUCTION
  • DH_ERR_INTERNAL_ERROR

◆ dh_writer_write_data()

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.

Parameters
writerThe writer (must not be NULL)
instance_keysThe instance keys identifying the target instance (can be NULL for topics without instances)
topic_dataThe data to write (must not be NULL)
timestampOptional source timestamp (can be NULL for automatic timestamp)
errorOutput parameter for error details on failure (can be NULL to ignore)
Returns
true on success, false on failure

Possible error codes:

  • DH_ERR_INVALID_TOPIC
  • DH_ERR_INVALID_REQUEST
  • DH_ERR_NOT_CONNECTED
  • DH_ERR_INVALID_INSTANCE
  • DH_ERR_AUTHORIZATION_FAILED
  • DH_ERR_INVALID_DATA
  • DH_ERROR_DATA_TOO_BIG
  • DH_ERR_INTERNAL_ERROR