libx52  0.3.2
Saitek X52/X52Pro drivers for Linux/Unix
Typedefs | Functions
Daemon communication

Typedefs

typedef int(* x52d_notify_callback_fn) (int argc, char **argv)
 Notification callback function type.
 

Functions

int x52d_dial_command (const char *sock_path)
 Open a connection to the daemon command socket. More...
 
int x52d_dial_notify (const char *sock_path)
 Open a connection to the daemon notify socket. More...
 
int x52d_format_command (int argc, const char **argv, char *buffer, size_t buflen)
 Format a series of command strings into a buffer. More...
 
int x52d_send_command (int sock_fd, char *buffer, size_t bufin, size_t bufout)
 Send a command to the daemon and retrieve the response. More...
 
int x52d_recv_notification (int sock_fd, x52d_notify_callback_fn callback)
 Receive a notification from the daemon. More...
 

Detailed Description

These functions are used to communicate with the X52 daemon.

Function Documentation

◆ x52d_dial_command()

int x52d_dial_command ( const char *  sock_path)

Open a connection to the daemon command socket.

This method opens a socket connection to the daemon command socket. This socket allows the client to issue commands and retrieve data. The sock_path parameter may be NULL, in which case, it will use the default socket path.

The client will need to use the returned descriptor to communicate with the daemon using x52d_send_command. Once finished, the client may use the close(2) method to close the file descriptor.

Parameters
[in]sock_pathPath to the daemon command socket.
Returns
Non-negative socket file descriptor on success.
-1 on failure, and set errno accordingly.
Exceptions
E2BIGreturned if the passed socket path is too big

◆ x52d_dial_notify()

int x52d_dial_notify ( const char *  sock_path)

Open a connection to the daemon notify socket.

This method opens a socket connection to the daemon notify socket. This socket allows the client to receive notifications from the daemon. Thej sock_path parameter may be NULL, in which case, it will use the default socket path.

The client will need to use the returned descriptor to communicate with the daemon using x52d_recv_notification. Once finished, the client may use the close(2) method to close the file descriptor.

Parameters
[in]sock_pathPath to the daemon command socket.
Returns
Non-negative socket file descriptor on success.
-1 on failure, and set errno accordingly.
Exceptions
E2BIGreturned if the passed socket path is too big

◆ x52d_format_command()

int x52d_format_command ( int  argc,
const char **  argv,
char *  buffer,
size_t  buflen 
)

Format a series of command strings into a buffer.

The client sends the command and parameters as a series of NUL terminated strings. This function concatenates the commands into a single buffer that can be passed to x52d_send_command.

buffer should be at least 1024 bytes long.

Parameters
[in]argcNumber of arguments to fit in the buffer
[in]argvPointer to an array of arguments.
[out]bufferBuffer to store the formatted command
[in]buflenLength of the buffer
Returns
number of bytes in the formatted command
-1 on an error condition, and errno is set accordingly.

◆ x52d_recv_notification()

int x52d_recv_notification ( int  sock_fd,
x52d_notify_callback_fn  callback 
)

Receive a notification from the daemon.

This function blocks until it receives a notification from the daemon. Once it receives a notification successfully, it will call the callback function with the arguments as string pointers. It will return the return value of the callback function, if it was called.

This is a blocking function and will not return until either a notification is received from the server, or an exception condition occurs.

Parameters
[in]sock_fdSocket descriptor returned from x52d_dial_notify
[in]callbackPointer to the callback function
Returns
return code of the callback function on success
-1 on an error condition, and errno is set accordingly.

◆ x52d_send_command()

int x52d_send_command ( int  sock_fd,
char *  buffer,
size_t  bufin,
size_t  bufout 
)

Send a command to the daemon and retrieve the response.

The client sends the command and parameters as a series of NUL terminated strings, and retrieves the response in the same manner. Depending on the result, the return status is either a positive integer or -1, and errno is set accordingly.

buffer should contain sufficient space to accomodate the returned response string.

This is a blocking function and will not return until either a response is received from the server, or an exception condition occurs.

Parameters
[in]sock_fdSocket descriptor returned from x52d_dial_command
[in,out]bufferPointer to the string containing the command and parameters. This is also used to save the returned response.
[in]bufinLength of the command in the input buffer
[in]bufoutMaximum length of the response
Returns
number of bytes returned from the server
-1 on an error condition, and errno is set accordingly.