libmygpio
libmygpio API documentation
Loading...
Searching...
No Matches
myGPIOd connection

This module provides functions for myGPIOd connection management. More...

Enumerations

enum  mygpio_conn_state { MYGPIO_STATE_OK , MYGPIO_STATE_ERROR , MYGPIO_STATE_FATAL }

Functions

struct t_mygpio_connectionmygpio_connection_new (const char *socket_path, int timeout_ms)
void mygpio_connection_free (struct t_mygpio_connection *connection)
const unsigned * mygpio_connection_get_version (struct t_mygpio_connection *connection)
int mygpio_connection_get_fd (struct t_mygpio_connection *connection)
enum mygpio_conn_state mygpio_connection_get_state (struct t_mygpio_connection *connection)
const char * mygpio_connection_get_error (struct t_mygpio_connection *connection)
bool mygpio_connection_clear_error (struct t_mygpio_connection *connection)

Detailed Description

This module provides functions for myGPIOd connection management.

Enumeration Type Documentation

◆ mygpio_conn_state

myGPIOd connections states

Enumerator
MYGPIO_STATE_OK 

OK state.

MYGPIO_STATE_ERROR 

Error state, read the error with mygpio_connection_get_error and clear it with mygpio_connection_clear_error.

MYGPIO_STATE_FATAL 

Fatal state, read the error with mygpio_connection_get_error. You must reconnect to recover.

Function Documentation

◆ mygpio_connection_clear_error()

bool mygpio_connection_clear_error ( struct t_mygpio_connection * connection)

Clears the current error message. MYGPIO_STATE_FATAL messages can not be cleared.

Parameters
connectionPointer to the connection struct returned by mygpio_connection_new.
Returns
true on success, else false

◆ mygpio_connection_free()

void mygpio_connection_free ( struct t_mygpio_connection * connection)

Closes the connection and frees the t_mygpio_connection struct

Parameters
connectionPointer to the connection struct returned by mygpio_connection_new.

◆ mygpio_connection_get_error()

const char * mygpio_connection_get_error ( struct t_mygpio_connection * connection)

Gets the current error message.

Parameters
connectionPointer to the connection struct returned by mygpio_connection_new.
Returns
Error message or NULL if no error is present

◆ mygpio_connection_get_fd()

int mygpio_connection_get_fd ( struct t_mygpio_connection * connection)

Returns the file descriptor of the underlying socket. You can use it to poll the file descriptor in an external event loop.

Parameters
connectionPointer to the connection struct returned by mygpio_connection_new.
Returns
File descriptor

◆ mygpio_connection_get_state()

enum mygpio_conn_state mygpio_connection_get_state ( struct t_mygpio_connection * connection)

Gets the current connection state. Use mygpio_connection_get_error to get the error message and mygpio_connection_clear_error to clear it.

Parameters
connectionPointer to the connection struct returned by mygpio_connection_new.
Returns
The connection state

◆ mygpio_connection_get_version()

const unsigned * mygpio_connection_get_version ( struct t_mygpio_connection * connection)

Gets the server version.

Parameters
connectionPointer to the connection struct returned by mygpio_connection_new.
Returns
Unsigned array consisting of major, minor and patch version.

◆ mygpio_connection_new()

struct t_mygpio_connection * mygpio_connection_new ( const char * socket_path,
int timeout_ms )

Creates a new connection to the myGPIOd socket and tries to connect. Check the state with mygpio_connection_get_state. It must be freed by the caller with mygpio_connection_free.

Parameters
socket_pathServer socket to connect to.
timeout_msThe read timeout in milliseconds
Returns
Returns the t_mygpio_connection struct on NULL in a out of memory condition.