-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathm3_cli.h
39 lines (32 loc) · 1.93 KB
/
m3_cli.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
#pragma once
#include <stdbool.h>
struct s_m3_cli {
char *socket_path; /* socket path (gets allocated and copied on initialisation) */
int fd; /* file descriptor */
char *prompt; /* prompt that got read */
int waittime_ms; /* default waittime for send commands to retrieve the new prompt */
};
/* send a command to the cli without caring about the answer
if the socket is not open, it will be initialised
if the send or read fails, the socket will be closed, so it can be opened by the next call
on error, false is returned and errno set approriately */
bool m3_cli_send(struct s_m3_cli *cli, char *command);
/* send a command to the cli and retrieve the answer
if the socket is not open, it will be initialised
if the send or read fails, the socket will be closed, so it can be opened by the next call
on error, false is returned and errno set approriately */
bool m3_cli_query(struct s_m3_cli *cli, char *command, char **answer, int waittime_ms);
/* send a command to the cli and retrieve the answer
but if the answer is an empty string of containers "is unknown" return EINVAL
if the socket is not open, it will be initialised
if the send or read fails, the socket will be closed, so it can be opened by the next call
on error, false is returned and errno set approriately */
bool m3_cli_query_verified(struct s_m3_cli *cli, char *command, char **answer, int waittime_ms);
/* initialises a cli struct container socket, fd and prompt
this struct is used to automatically reopen a broken socket in the query or send functions
open the cli socket and get the prompt
returns a struct containing all cli information
on error, NULL is returned and errno set appropriately */
struct s_m3_cli *m3_cli_initialise(const char *socket_path, int default_waittime_ms);
/* close the socket and free the struct */
void m3_cli_shutdown(struct s_m3_cli **cli);