Crinit -- Configurable Rootfs Init
rtimcmd.h File Reference

(2023-08-02, commit: 9434b31)

Header related to handling of runtime commands received via the notification/service interface. More...

#include "rtimopmap.h"
#include "taskdb.h"
Include dependency graph for rtimcmd.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  crinitRtimCmd_t
 

Macros

#define CRINIT_RTIMCMD_SHDN_THREAD_STACK_SIZE   (PTHREAD_STACK_MIN + 112 * 1024)
 
#define CRINIT_RTIMCMD_RES_OK   "RES_OK"
 Value of first argument in a positive (successful) response message. More...
 
#define CRINIT_RTIMCMD_RES_ERR   "RES_ERR"
 Value of first argument in a negative (unsuccessful) response message. More...
 

Typedefs

typedef struct crinitRtimCmd_t crinitRtimCmd_t
 

Functions

int crinitBuildRtimCmd (crinitRtimCmd_t *c, crinitRtimOp_t op, size_t argc,...)
 
int crinitDestroyRtimCmd (crinitRtimCmd_t *c)
 
int crinitParseRtimCmd (crinitRtimCmd_t *out, const char *cmdStr)
 
int crinitRtimCmdToMsgStr (char **out, size_t *outLen, const crinitRtimCmd_t *cmd)
 
int crinitExecRtimCmd (crinitTaskDB_t *ctx, crinitRtimCmd_t *res, const crinitRtimCmd_t *cmd)
 

Detailed Description

Header related to handling of runtime commands received via the notification/service interface.

Macro Definition Documentation

◆ CRINIT_RTIMCMD_RES_ERR

#define CRINIT_RTIMCMD_RES_ERR   "RES_ERR"

Value of first argument in a negative (unsuccessful) response message.

◆ CRINIT_RTIMCMD_RES_OK

#define CRINIT_RTIMCMD_RES_OK   "RES_OK"

Value of first argument in a positive (successful) response message.

◆ CRINIT_RTIMCMD_SHDN_THREAD_STACK_SIZE

#define CRINIT_RTIMCMD_SHDN_THREAD_STACK_SIZE   (PTHREAD_STACK_MIN + 112 * 1024)

Stack size for the shutdown/reboot handling thread.

Typedef Documentation

◆ crinitRtimCmd_t

Structure holding a command or response message with its crinitRtimOp_t opcode and arguments array.

Function Documentation

◆ crinitBuildRtimCmd()

int crinitBuildRtimCmd ( crinitRtimCmd_t c,
crinitRtimOp_t  op,
size_t  argc,
  ... 
)

Create an crinitRtimCmd_t from an opcode and an argument list.

Will allocate memory for the argument string array which should be freed using crinitDestroyRtimCmd() when no longer needed.

Parameters
cThe crinitRtimCmd_t to build.
opThe opcode of the command or response.
argcThe number of arguments to the command/response.
...List of argc arguments of type const char*.
Returns
0 on success, -1 otherwise

◆ crinitDestroyRtimCmd()

int crinitDestroyRtimCmd ( crinitRtimCmd_t c)

Free memory in an crinitRtimCmd_t allocated by crinitBuildRtimCmd() or crinitParseRtimCmd().

Will free the memory for the argument array in the structure.

Parameters
cThe crinitRtimCmd_t from which the memory should be freed.
Returns
0 on success, -1 otherwise

◆ crinitExecRtimCmd()

int crinitExecRtimCmd ( crinitTaskDB_t ctx,
crinitRtimCmd_t res,
const crinitRtimCmd_t cmd 
)

Executes an crinitRtimCmd_t if it contains a valid command.

For the implementations of the different possible commands see rtimcmd.c.

Parameters
ctxPointer to the crinitTaskDB_t the command shall be executed on.
resResult/response output.
cmdThe command to execute.
Returns
0 on success, -1 otherwise

◆ crinitParseRtimCmd()

int crinitParseRtimCmd ( crinitRtimCmd_t out,
const char *  cmdStr 
)

Parses a string into an crinitRtimCmd_t.

The string must be of the form <OPCODE_STRING>\nARG1\n...\nARGn. The mapping of an opcode to a string representation is done in rtimopmap.h. crinitRtimCmdToMsgStr() can be used to obtain such a string from an crinitRtimCmd_t.

Will allocate memory for the argument array inside the output command which should be freed using crinitDestroyRtimCmd().

Parameters
outThe crinitRtimCmd_t to create.
cmdStrThe string to parse.
Returns
0 on success, -1 otherwise

◆ crinitRtimCmdToMsgStr()

int crinitRtimCmdToMsgStr ( char **  out,
size_t *  outLen,
const crinitRtimCmd_t cmd 
)

Generates a string representation of an crinitRtimCmd_t.

The generated string will be in a format parse-able by crinitParseRtimCmd(). Memory for the string will be allocated using malloc() and should be freed using free() once no longer used.

Parameters
outPointer to the output string.
outLenSize of the output string including the terminating zero.
cmdThe crinitRtimCmd_t to generate the string from.
Returns
0 on success, -1 otherwise