-
Notifications
You must be signed in to change notification settings - Fork 1
/
cmd.h
95 lines (84 loc) · 2.48 KB
/
cmd.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* SPDX-License-Identifier: ISC
*
* Copyright (c) 2022 Codethink
*/
#ifndef CDT_CMD_H
#define CDT_CMD_H
/**
* \file
* \brief Command interface.
*
* `cdt` supports multiple subcommands. Each subcommand (cmd) is implemented
* as a callback table. These callbacks are called at key points through
* the program lifecycle.
*/
/** Common parameters. */
struct cmd_options {
const char *display;
const char *host;
int64_t port;
int64_t log_level;
int64_t log_target;
};
/**
* Print help text for the command.
*
* \param[in] argc Number of command line arguments.
* \param[in] argv String vector containing command line arguments.
* \param[in] cmd Command to get help for, or NULL to use argument.
*/
void cmd_help(int argc, const char **argv, const char *cmd);
/**
* Initialise the command.
*
* Detects which subcommand is requested, reads and CLI arguments it needs,
* and initialises the cmd-specific code.
*
* \param[in] argc Number of command line arguments.
* \param[in] argv String vector containing command line arguments.
* \param[in] options Common command options parsed from arguments.
* \param[out] pw_out Returns private cmd data to be passed to other calls.
* \return true on success, false otherwise.
*/
bool cmd_init(int argc, const char **argv,
struct cmd_options *options, void **pw_out);
/**
* Let the command handle a received message.
*
* \param[in] pw The command's private context.
* \param[in] id Id of message that this is a response to.
* \param[in] msg Received message.
* \param[in] len Length of msg in bytes.
*/
void cmd_msg(void *pw, int id, const char *msg, size_t len);
/**
* Let the command handle a received message.
*
* \param[in] pw The command's private context.
* \param[in] method The event method name.
* \param[in] method_len Length of method in bytes.
* \param[in] msg Received message.
* \param[in] len Length of msg in bytes.
*/
void cmd_evt(void *pw, const char *method, size_t method_len,
const char *msg, size_t len);
/**
* .Tick the command.
*
* \param[in] pw The command's private context.
* \return true if the mainloop should continue even when message queues are
* empty, or false to allow termination of the program.
*/
bool cmd_tick(void *pw);
/**
* .Finalise the command.
*
* \param[in] pw The command's private context.
*/
void cmd_fini(void *pw);
/**
* Print a list of available commands.
*/
void cmd_print_command_list(void);
#endif