Helper Reference Manual  1.7.1
ODPH CLI

API Description

Command line interface.

This API allows control of ODP CLI server, which may be connected to using a telnet client. CLI commands may be used to get information from an ODP instance, for debugging purposes.

Data Structures

struct  odph_cli_param_t
 ODP CLI server parameters. More...
 

Typedefs

typedef void(* odph_cli_user_cmd_func_t) (int argc, char *argv[])
 User defined command function type. More...
 

Functions

void odph_cli_param_init (odph_cli_param_t *param)
 Initialize CLI server params. More...
 
int odph_cli_init (const odph_cli_param_t *param)
 Initialize CLI helper. More...
 
int odph_cli_register_command (const char *name, odph_cli_user_cmd_func_t func, const char *help)
 Register a user defined command. More...
 
int odph_cli_run (void)
 Run CLI server. More...
 
int odph_cli_stop (void)
 Stop CLI server. More...
 
int odph_cli_log (const char *fmt,...)
 Print to CLI. More...
 
int odph_cli_log_va (const char *fmt, va_list in_args)
 Print to CLI. More...
 
int odph_cli_term (void)
 Terminate CLI helper. More...
 

Typedef Documentation

◆ odph_cli_user_cmd_func_t

typedef void(* odph_cli_user_cmd_func_t) (int argc, char *argv[])

User defined command function type.

See odph_cli_register_command().

The arguments (argv) are the arguments to the command given in the CLI client. For example, having registered a command with the name "my_command", and given the command "my_command one two" in the CLI client, the user command function would be called with argc = 2, argv[0] = "one" and argv[1] = "two".

Definition at line 42 of file cli.h.

Function Documentation

◆ odph_cli_param_init()

void odph_cli_param_init ( odph_cli_param_t param)

Initialize CLI server params.

Initialize an odph_cli_param_t to its default values for all fields.

Parameters
[out]paramPointer to parameter structure

◆ odph_cli_init()

int odph_cli_init ( const odph_cli_param_t param)

Initialize CLI helper.

This function initializes the CLI helper. It must be called before odph_cli_register_command() and odph_cli_run().

In process mode (ODPH_PROC_MODE), this function must be called before creating the thread which calls odph_cli_run().

Parameters
paramCLI server parameters to use
Return values
0Success
<0Failure

◆ odph_cli_register_command()

int odph_cli_register_command ( const char *  name,
odph_cli_user_cmd_func_t  func,
const char *  help 
)

Register a user defined command.

Register a command with a name, function, and an optional help text. The registered command is displayed in the output of the "help" command. When the command is invoked by the CLI client, the registered function is called with the parameters entered by the CLI client user.

Command names are case-insensitive. In the CLI client, they are displayed in the case they were registered in, but they may be invoked using any case.

This function should be called after odph_cli_init() and before odph_cli_run().

Parameters
nameCommand name (case-insensitive)
funcCommand function
helpHelp or description for the command. This appears in the output of the "help" command. May be NULL.
Return values
0Success
<0Failure

◆ odph_cli_run()

int odph_cli_run ( void  )

Run CLI server.

When executing this function, the CLI is accepting client connections and running commands from a client, if one is connected.

This function should be called after odph_cli_init() and after any odph_cli_register_command() calls. After calling this function, odph_cli_stop() must be called before calling this function again.

Returns only on a fatal error, or after odph_cli_stop() is called.

Return values
0Success
<0Failure

◆ odph_cli_stop()

int odph_cli_stop ( void  )

Stop CLI server.

Stop accepting new client connections and disconnect any connected client.

Return values
0Success
<0Failure

◆ odph_cli_log()

int odph_cli_log ( const char *  fmt,
  ... 
)

Print to CLI.

A user defined command may call this function to print to the CLI client. This function should only be called in a user defined command (see odph_cli_register_command()). If called anywhere else, the behavior is undefined.

Parameters
fmtprintf-style message format
Returns
On success, the number of characters printed or buffered, without accounting for any line feed conversions. If an error is encountered, a negative value is returned.

◆ odph_cli_log_va()

int odph_cli_log_va ( const char *  fmt,
va_list  in_args 
)

Print to CLI.

Similar to odph_cli_log(), except that this one takes its arguments as a va_list.

Parameters
fmtprintf-style message format
in_argsvariadic arguments
Returns
On success, the number of characters printed or buffered, without accounting for any line feed conversions. If an error is encountered, a negative value is returned.

◆ odph_cli_term()

int odph_cli_term ( void  )

Terminate CLI helper.

Free any resources allocated by the CLI helper.

Return values
0Success
<0Failure