howm
howm
ipc.c File Reference

Everything required to parse, interpret and respond to messages that are sent over IPC. More...

#include <sys/socket.h>
#include <sys/un.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "client.h"
#include "helper.h"
#include "howm.h"
#include "ipc.h"
#include "layout.h"
#include "monitor.h"
#include "op.h"
#include "scratchpad.h"
#include "types.h"
#include "workspace.h"

Macros

#define CALL_INT(func, arg, lower, upper)
 
#define CALL_WORKSPACE(func, arg, lower, upper)
 
#define SET_INT(opt, arg, lower, upper)
 
#define SET_BOOL(opt, arg)
 
#define SET_COLOUR(opt, arg)
 

Enumerations

enum  msg_type { MSG_FUNCTION = 1, MSG_CONFIG }
 

Functions

static char ** ipc_process_args (char *msg, int len, int *err)
 Accepts a char array and convert it into an array of strings. More...
 
static int ipc_arg_to_int (char *arg, int *err, int lower, int upper)
 Convert a numerical string into a decimal value, such as "12" becoming 12. More...
 
static int ipc_process_function (char **args)
 Receive a char array from a UNIX socket and subsequently call a function, passing the args from within msg. More...
 
static int ipc_process_config (char **args)
 Process a config message. If the config option isn't recognised, set err to IPC_ERR_NO_CONFIG. More...
 
static bool ipc_arg_to_bool (char *arg, int *err)
 Convert an argument to a boolean. More...
 
int ipc_init (void)
 Open a socket and return it. More...
 
void ipc_cleanup (void)
 Delete the UNIX socket file. More...
 
int ipc_process (char *msg, int len)
 Process a message depending on its type - a config message or a function call message. More...
 

Detailed Description

Everything required to parse, interpret and respond to messages that are sent over IPC.

Author
Harvey Hunt
Date
2015

Macro Definition Documentation

#define CALL_INT (   func,
  arg,
  lower,
  upper 
)
Value:
do { \
i = ipc_arg_to_int(arg, &err, lower, upper); \
if (err == IPC_ERR_NONE) \
func(i); \
} while (0)
Definition: ipc.h:14
static int ipc_arg_to_int(char *arg, int *err, int lower, int upper)
Convert a numerical string into a decimal value, such as "12" becoming 12.
Definition: ipc.c:280
#define CALL_WORKSPACE (   func,
  arg,
  lower,
  upper 
)
Value:
do { \
i = ipc_arg_to_int(arg, &err, lower, upper); \
if (err == IPC_ERR_NONE) { \
func(index_to_workspace(mon, i)); \
} \
} while (0)
Definition: ipc.h:14
monitor_t * mon
Definition: howm.c:84
workspace_t * index_to_workspace(const monitor_t *m, uint32_t index)
Convert a workspace&#39;s index in a workspace list to an index.
Definition: workspace.c:186
static int ipc_arg_to_int(char *arg, int *err, int lower, int upper)
Convert a numerical string into a decimal value, such as "12" becoming 12.
Definition: ipc.c:280
#define SET_BOOL (   opt,
  arg 
)
Value:
do { \
b = ipc_arg_to_bool(arg, &err); \
if (err == IPC_ERR_NONE) \
opt = b; \
} while (0)
static bool ipc_arg_to_bool(char *arg, int *err)
Convert an argument to a boolean.
Definition: ipc.c:462
Definition: ipc.h:14
#define SET_COLOUR (   opt,
  arg 
)
Value:
do { \
if (strlen(arg) > 7) \
else if (strlen(arg) < 7) \
opt = get_colour(arg); \
} while (0)
uint32_t get_colour(char *colour)
Converts a hexcode colour into an X11 colourmap pixel.
Definition: howm.c:278
Definition: ipc.h:16
Definition: ipc.h:16
#define SET_INT (   opt,
  arg,
  lower,
  upper 
)
Value:
do { \
i = ipc_arg_to_int(arg, &err, lower, upper); \
if (err == IPC_ERR_NONE) \
opt = i; \
} while (0)
Definition: ipc.h:14
static int ipc_arg_to_int(char *arg, int *err, int lower, int upper)
Convert a numerical string into a decimal value, such as "12" becoming 12.
Definition: ipc.c:280

Enumeration Type Documentation

enum msg_type
Enumerator
MSG_FUNCTION 
MSG_CONFIG 

Function Documentation

static bool ipc_arg_to_bool ( char *  arg,
int *  err 
)
static

Convert an argument to a boolean.

t and 1 are considered true, f and 0 are considered false.

Parameters
argA string containing the argument.
errWhere an error code should be stored.
Returns
A boolean, depending on whether the argument was true or false.
static int ipc_arg_to_int ( char *  arg,
int *  err,
int  lower,
int  upper 
)
static

Convert a numerical string into a decimal value, such as "12" becoming 12.

Minus signs are handled. It is assumed that a two digit number won't start with a zero. Args with more than two digits will not be accepted, nor will args that aren't numerical.

Parameters
argThe string to be converted.
errWhere errors are reported.
lowerThe lower bound for the returned value. Note: This is inclusive
upperThe upper bound for the returned value. Note: This is inclusive
Returns
The decimal representation of arg.
void ipc_cleanup ( void  )

Delete the UNIX socket file.

int ipc_init ( void  )

Open a socket and return it.

If a socket path is defined in the env variable defined as ENV_SOCK_VAR then use that - else use DEF_SOCK_PATH.

Returns
A socket file descriptor.
int ipc_process ( char *  msg,
int  len 
)

Process a message depending on its type - a config message or a function call message.

Parameters
msgA buffer containing the message sent by cottage.
lenThe length of the message.
Returns
An error code resulting from processing msg.
static char ** ipc_process_args ( char *  msg,
int  len,
int *  err 
)
static

Accepts a char array and convert it into an array of strings.

msg is split into strings (delimited by a null character) and placed in an array. err is set with a corresponding error (such as args too few args), or nothing.

XXX: args must be freed by the caller.

Parameters
msgA char array that is read from a UNIX socket.
lenThe length of data in msg.
errWhere any errors will be stored.
Returns
A pointer to an array of strings, each one representing an argument that has been passed over a UNIX socket.
static int ipc_process_config ( char **  args)
static

Process a config message. If the config option isn't recognised, set err to IPC_ERR_NO_CONFIG.

Parameters
argsAn array of strings representing the args.
Returns
err containing the error (or lack of) that has occurred.
static int ipc_process_function ( char **  args)
static

Receive a char array from a UNIX socket and subsequently call a function, passing the args from within msg.

Parameters
argsThe args (as strings).
Returns
The error code, as set by this function itself or those that it calls.