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

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

#include <stdbool.h>
#include "common.h"
#include "writer.h"
#include "subscriber.h"
Include dependency graph for client.h:

Go to the source code of this file.

Macros

#define DH_CONN_DISCONNECTED    ((DHConnectionState)0)
 Client is disconnected from the Device Data Hub.
 
#define DH_CONN_CONNECTED   ((DHConnectionState)1)
 Client is connected to the Device Data Hub.
 
#define DH_LOG_OFF   ((DHLogLevel)0)
 No logging output.
 
#define DH_LOG_CRITICAL   ((DHLogLevel)1)
 Critical errors that may cause application failure.
 
#define DH_LOG_ERROR    ((DHLogLevel)2)
 Error conditions that indicate a failure in a specific operation.
 
#define DH_LOG_WARNING   ((DHLogLevel)3)
 Warning messages for potentially problematic situations.
 
#define DH_LOG_INFO   ((DHLogLevel)4)
 Informational messages about normal operation.
 
#define DH_LOG_DEBUG   ((DHLogLevel)5)
 Debug information useful for troubleshooting.
 
#define DH_LOG_TRACE   ((DHLogLevel)6)
 Detailed trace information for comprehensive debugging.
 
#define DH_LOG_TARGET_CONSOLE   ((DHLogTarget)0)
 Output log messages to console/stdout.
 
#define DH_LOG_TARGET_SYSLOG   ((DHLogTarget)1)
 Output log messages to the system logger.
 

Typedefs

typedef uint32_t DHConnectionState
 Enumeration of connection states for the Device Data Hub client. More...
 
typedef uint32_t DHLogLevel
 Enumeration of available log levels for the Device Data Hub client. More...
 
typedef uint32_t DHLogTarget
 Enumeration of available log output targets. More...
 
typedef void(* DHOnConnectionUpdateCallback) (DHConnectionState update, void *user_data)
 Connection state update callback function type. More...
 
typedef struct DHClient_t DHClient
 Opaque client handle.
 

Functions

DHClient * dh_client_create (const char *name, DHError **error)
 Creates a new client instance. More...
 
const char * dh_client_get_name (const DHClient *client)
 Gets the name of the client. More...
 
bool dh_client_set_connection_update_callback (DHClient *client, DHOnConnectionUpdateCallback callback, void *user_data, DHError **error)
 Sets the connection state update callback. More...
 
bool dh_client_connect (DHClient *client, DHError **error)
 Connects the client synchronously to the Device Data Hub. More...
 
bool dh_client_disconnect (DHClient *client, DHError **error)
 Disconnects the client from the Device Data Hub. More...
 
void dh_client_destroy (DHClient *client)
 Destroys a client instance. More...
 
DHConnectionState dh_client_get_connection_state (const DHClient *client)
 Gets the current connection state. More...
 
DHTopic * dh_client_create_topic_from_file (DHClient *client, const char *file_path, DHError **error)
 Creates a new topic from the definition. More...
 
DHTopic * dh_client_create_topic (DHClient *client, const char *topic_def, DHError **error)
 Creates a new topic from the definition. More...
 
bool dh_client_delete_topic (DHClient *client, const char *topic_name, DHError **error)
 Deletes a topic from the Device Data Hub. More...
 
DHTopicList * dh_client_get_topic_list (DHClient *client, DHError **error)
 Gets a list of available topics. More...
 
DHTopic * dh_client_get_topic (DHClient *client, const char *topic_name, DHError **error)
 Gets a topic by name. More...
 
DHTopicInstanceList * dh_client_get_topic_instances (DHClient *client, const char *topic_name, DHError **error)
 Gets topic instances for a topic. More...
 
DHWriter * dh_client_create_writer (DHClient *client, const char *writer_name, const char *topic_name, DHError **error)
 Creates a writer for a specific topic. More...
 
DHSubscriber * dh_client_create_subscriber (DHClient *client, const char *subscriber_name, DHError **error)
 Creates a topic data subscriber. More...
 
bool dh_client_set_logging (DHClient *client, DHLogLevel level, DHLogTarget target, DHError **error)
 Configures logging for the Device Data Hub client. More...
 

Detailed Description

Client interface for Device Data Hub API.

This file provides the primary client interface for connecting to and interacting with the Device Data Hub service. It manages the client lifecycle, connection handling, and creation of writers and subscribers.

Typedef Documentation

◆ DHConnectionState

typedef uint32_t DHConnectionState

Enumeration of connection states for the Device Data Hub client.

Represents the various states that the client's connection to the Device Data Hub can be in, such as disconnected, connected, or in the process of connecting.

◆ DHLogLevel

typedef uint32_t DHLogLevel

Enumeration of available log levels for the Device Data Hub client.

Defines the severity levels for logging messages, ordered from least verbose (OFF) to most verbose (DH_LOG_TRACE). Each level includes all messages from less verbose levels.

◆ DHLogTarget

typedef uint32_t DHLogTarget

Enumeration of available log output targets.

Specifies where log messages should be directed.

◆ DHOnConnectionUpdateCallback

typedef void(* DHOnConnectionUpdateCallback) (DHConnectionState update, void *user_data)

Connection state update callback function type.

Callback function called when the connection state changes.

Parameters
updateThe new connection state
user_dataUser-provided data passed to dh_client_set_connection_update_callback()

Function Documentation

◆ dh_client_connect()

bool dh_client_connect ( DHClient *  client,
DHError **  error 
)

Connects the client synchronously to the Device Data Hub.

This function attempts to establish a connection between the client and the Device Data Hub. The client must have the required access rights to connect. Once connected, the client can perform operations such as publishing data to and subscribing to topics on the Device Data Hub.

Parameters
clientThe client (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_ALREADY_CONNECTED
  • DH_ERR_CREDENTIAL_ERROR
  • DH_ERR_AUTHENTICATION_FAILED
  • DH_ERR_MAX_CLIENTS
  • DH_ERR_MAX_CONNECTIONS
  • DH_ERR_INTERNAL_ERROR

◆ dh_client_create()

DHClient* dh_client_create ( const char *  name,
DHError **  error 
)

Creates a new client instance.

Creates a new Device Data Hub client with the specified name.

Parameters
nameThe name of the client (must not be NULL)
errorOutput parameter for error details on failure (can be NULL to ignore)
Returns
Pointer to the newly created client, or NULL on failure

◆ dh_client_create_subscriber()

DHSubscriber* dh_client_create_subscriber ( DHClient *  client,
const char *  subscriber_name,
DHError **  error 
)

Creates a topic data subscriber.

Creates a new data subscriber that can receive data from multiple topics.

Parameters
clientThe client (must not be NULL)
subscriber_nameThe name of the topic subscriber (must not be NULL)
errorOutput parameter for error details on failure (can be NULL to ignore)
Returns
Pointer to the created topic subscriber (caller must free with dh_subscriber_destroy()), or NULL on failure

Possible error codes:

  • DH_ERR_INVALID_PARAMS
  • DH_ERR_INTERNAL_ERROR

◆ dh_client_create_topic()

DHTopic* dh_client_create_topic ( DHClient *  client,
const char *  topic_def,
DHError **  error 
)

Creates a new topic from the definition.

Creates a new topic on the Device Data Hub using a topic definition string. The format of the definition follows the JSON schema described in the main documentation.

Parameters
clientThe client (must not be NULL)
topic_defTopic definition in json string (must not be NULL)
errorOutput parameter for error details on failure (can be NULL to ignore)
Returns
Pointer to the created topic (caller must free with dh_topic_destroy()), or NULL on failure

Possible error codes:

  • DH_ERR_INVALID_PARAMS
  • DH_ERR_TOPIC_EXISTS
  • DH_ERR_NOT_CONNECTED
  • DH_ERR_AUTHORIZATION_FAILED
  • DH_ERR_MAX_TOPIC
  • DH_ERROR_DATA_TOO_BIG
  • DH_ERR_INTERNAL_ERROR

◆ dh_client_create_topic_from_file()

DHTopic* dh_client_create_topic_from_file ( DHClient *  client,
const char *  file_path,
DHError **  error 
)

Creates a new topic from the definition.

Creates a new topic on the Device Data Hub using a topic definition string. The format of the definition follows the JSON schema described in the main documentation.

Parameters
clientThe client (must not be NULL)
file_pathPath to a JSON file containing the topic definition (must not be NULL)
errorOutput parameter for error details on failure (can be NULL to ignore)
Returns
Pointer to the created topic (caller must free with dh_topic_destroy()), or NULL on failure

Possible error codes:

  • DH_ERR_INVALID_PARAMS
  • DH_ERR_TOPIC_EXISTS
  • DH_ERR_NOT_CONNECTED
  • DH_ERR_AUTHORIZATION_FAILED
  • DH_ERR_MAX_TOPIC
  • DH_ERROR_DATA_TOO_BIG
  • DH_ERR_INTERNAL_ERROR

◆ dh_client_create_writer()

DHWriter* dh_client_create_writer ( DHClient *  client,
const char *  writer_name,
const char *  topic_name,
DHError **  error 
)

Creates a writer for a specific topic.

Creates a new writer and initializes it for the specified topic. The topic must already exist on the Device Data Hub.

Parameters
clientThe client (must not be NULL)
writer_nameThe name of the writer (must not be NULL)
topic_nameThe name of the topic to write to (must not be NULL)
errorOutput parameter for error details on failure (can be NULL to ignore)
Returns
Pointer to the created writer (caller must free with dh_writer_destroy()), or NULL on failure

Possible error codes:

  • DH_ERR_INVALID_PARAMS
  • DH_ERR_INVALID_TOPIC
  • DH_ERR_NOT_CONNECTED
  • DH_ERR_INTERNAL_ERROR

◆ dh_client_delete_topic()

bool dh_client_delete_topic ( DHClient *  client,
const char *  topic_name,
DHError **  error 
)

Deletes a topic from the Device Data Hub.

Permanently removes a topic and all its data from the Device Data Hub.

Parameters
clientThe client (must not be NULL)
topic_nameThe name of the topic 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_PARAMS
  • DH_ERR_INVALID_TOPIC
  • DH_ERR_NOT_CONNECTED
  • DH_ERR_AUTHORIZATION_FAILED
  • DH_ERROR_DATA_TOO_BIG
  • DH_ERR_INTERNAL_ERROR

◆ dh_client_destroy()

void dh_client_destroy ( DHClient *  client)

Destroys a client instance.

Frees all resources associated with the client. The client will be automatically disconnected if still connected. This function will block until all ongoing callbacks have completed and no further callbacks will be invoked after it returns.

Parameters
clientThe client to destroy (can be NULL)

◆ dh_client_disconnect()

bool dh_client_disconnect ( DHClient *  client,
DHError **  error 
)

Disconnects the client from the Device Data Hub.

This method terminates the connection between the client and the Device Data Hub. All created writers/subscriptions will be invalidated and won't operate.

Parameters
clientThe client (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_NOT_CONNECTED
  • DH_ERR_INTERNAL_ERROR

◆ dh_client_get_connection_state()

DHConnectionState dh_client_get_connection_state ( const DHClient *  client)

Gets the current connection state.

Returns the detailed connection state of the client.

Parameters
clientThe client (must not be NULL)
Returns
The current connection state

◆ dh_client_get_name()

const char* dh_client_get_name ( const DHClient *  client)

Gets the name of the client.

Returns the name that was specified when the client was created.

Parameters
clientThe client (must not be NULL)
Returns
The client name as a string, or NULL if client is invalid

◆ dh_client_get_topic()

DHTopic* dh_client_get_topic ( DHClient *  client,
const char *  topic_name,
DHError **  error 
)

Gets a topic by name.

Retrieves a topic for an existing topic on the Device Data Hub.

Parameters
clientThe client (must not be NULL)
topic_nameThe name of the topic to retrieve (must not be NULL)
errorOutput parameter for error details on failure (can be NULL to ignore)
Returns
Pointer to the topic (caller must free with dh_topic_destroy()), or NULL on failure

Possible error codes:

  • DH_ERR_INVALID_PARAMS
  • DH_ERR_INVALID_TOPIC
  • DH_ERR_NOT_CONNECTED
  • DH_ERROR_DATA_TOO_BIG
  • DH_ERR_INTERNAL_ERROR

◆ dh_client_get_topic_instances()

DHTopicInstanceList* dh_client_get_topic_instances ( DHClient *  client,
const char *  topic_name,
DHError **  error 
)

Gets topic instances for a topic.

Retrieves a list of all instances for the specified topic. The returned list must be freed using dh_topic_instance_list_destroy().

Parameters
clientThe client (must not be NULL)
topic_nameThe name of the topic (must not be NULL)
errorOutput parameter for error details on failure (can be NULL to ignore)
Returns
Pointer to the instance list (caller must free with dh_topic_instance_list_destroy()), or NULL on failure

Possible error codes:

  • DH_ERR_INVALID_PARAMS
  • DH_ERR_INVALID_TOPIC
  • DH_ERR_NOT_CONNECTED
  • DH_ERROR_DATA_TOO_BIG
  • DH_ERR_INTERNAL_ERROR

◆ dh_client_get_topic_list()

DHTopicList* dh_client_get_topic_list ( DHClient *  client,
DHError **  error 
)

Gets a list of available topics.

Retrieves a list of all topic names available on the Device Data Hub. The returned list must be freed using dh_topic_list_destroy().

Parameters
clientThe client (must not be NULL)
errorOutput parameter for error details on failure (can be NULL to ignore)
Returns
Pointer to the topic list (caller must free with dh_topic_list_destroy()), or NULL on failure

Possible error codes:

  • DH_ERR_NOT_CONNECTED
  • DH_ERR_INTERNAL_ERROR

◆ dh_client_set_connection_update_callback()

bool dh_client_set_connection_update_callback ( DHClient *  client,
DHOnConnectionUpdateCallback  callback,
void *  user_data,
DHError **  error 
)

Sets the connection state update callback.

Registers a callback to receive connection state change notifications.

Parameters
clientThe client (must not be NULL)
callbackCallback function for connection state changes (can be NULL to remove)
user_dataUser-provided data passed to the callback (can be NULL)
errorOutput parameter for error details on failure (can be NULL to ignore)
Returns
true on success, false on failure

◆ dh_client_set_logging()

bool dh_client_set_logging ( DHClient *  client,
DHLogLevel  level,
DHLogTarget  target,
DHError **  error 
)

Configures logging for the Device Data Hub client.

This method allows dynamic configuration of the logging settings for the Device Data Hub client at runtime.

Parameters
clientThe client (must not be NULL)
levelThe log level to set
targetThe log output target to set
errorOutput parameter for error details on failure (can be NULL to ignore)
Returns
true on success, false on failure