-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibdio.h
More file actions
66 lines (51 loc) · 1.8 KB
/
libdio.h
File metadata and controls
66 lines (51 loc) · 1.8 KB
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
#ifndef LIBDIO_H
#define LIBDIO_H
#include <stdint.h>
#include <stddef.h>
#include <sys/types.h>
#include "debug.h"
typedef struct {
uint16_t len;
uint16_t code;
} __attribute__((packed)) libdio_msg_hdr_t;
typedef struct {
libdio_msg_hdr_t hdr;
uint8_t status;
} __attribute__((packed)) libdio_msg_response_hdr_t;
typedef struct {
libdio_msg_hdr_t hdr;
char cmd[1];
} __attribute__((packed)) libdio_msg_str_cmd_t;
typedef struct {
libdio_msg_response_hdr_t rhdr;
char response[1];
} __attribute__((packed)) libdio_msg_str_cmd_r_t;
typedef int (*libdio_str_cmd_handler_t)(int, char **, void *);
typedef struct {
char *cmd;
libdio_str_cmd_handler_t handler;
} libdio_str_cmd_tbl_t;
/* IO */
void libdio_setlog(dbg_desc_t *dbg);
int libdio_waitfd(int fd, uint16_t timer, char mode);
int libdio_read_message(int fd, uint8_t *buf);
int libdio_write_message(int fd, uint8_t *buf);
int libdio_process_str_cmd(void *rbuf, libdio_str_cmd_tbl_t *cmd_tbl,
uint16_t cmd_count, void *data);
int libdio_execute_cm(char *sockpath, void *buf, size_t bufsize, char *command);
int libdio_signal(int signum, void (*handler)(int));
int libdio_setnonblock(int fd, uint8_t en);
#define LIBDIO_MSG_RESPONSE 0x8000
#define LIBDIO_MSG_STR_CMD 0x0000
#define LIBDIO_MSG_JSON_CMD 0x0001
#define LIBDIO_FILLRESPONSE(rhdr, ln, cod, sts) \
rhdr->status = sts; \
rhdr->hdr.code = htons(cod | LIBDIO_MSG_RESPONSE); \
rhdr->hdr.len = htons(ln+1);
#define LIBDIO_FILLSTRRESPONSE(rshdr, str, sts) \
strcpy(rshdr->response, str); \
LIBDIO_FILLRESPONSE((&(rshdr->rhdr)), strlen(str)+1, LIBDIO_MSG_STR_CMD, sts);
#define LIBDIO_FILLJSONRESPONSE(rshdr, str, sts) \
strcpy(rshdr->response, str); \
LIBDIO_FILLRESPONSE((&(rshdr->rhdr)), strlen(str)+1, LIBDIO_MSG_JSON_CMD, sts);
#endif