blob: 54c414bab7754ff1816c7f80569b70b4224b00b6 (
plain)
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
|
/*
* Created by yuuta on 7/13/22.
*/
#ifndef LIBAC_REQUESTS_H
#define LIBAC_REQUESTS_H
#include "incl.h"
#include "common.h"
#include "ids.h"
#include <stdbool.h>
/* Responses */
typedef struct ac_response {
uint8_t type;
int id;
} ac_response_t;
#define AC_RESPONSE_ERROR AC_ID(AC_TYPE_RESPONSE, 1 /* 0b00000001 */) /* 0b10000001 */
typedef struct ac_response_error {
uint8_t type;
int id;
int code;
char *message;
} ac_response_error_t;
#define AC_RESPONSE_OK AC_ID(AC_TYPE_RESPONSE, 2 /* 0b00000010 */) /* 0b10000010 */
typedef struct ac_response_ok {
uint8_t type;
int id;
} ac_response_ok_t;
#define AC_RESPONSE_CMD_OUT AC_ID(AC_TYPE_RESPONSE, 3 /* 0b00000011 */) /* 0b10000011 */
typedef struct ac_response_cmd_out {
uint8_t type;
int id;
char *sender;
char *out;
} ac_response_cmd_out_t;
#define AC_RESPONSE_CMD_RESULT AC_ID(AC_TYPE_RESPONSE, 4 /* 0b00000100 */) /* 0b10000100 */
typedef struct ac_response_cmd_result {
uint8_t type;
int id;
int result;
bool success;
} ac_response_cmd_result_t;
/* Requests */
typedef struct ac_request {
uint8_t type;
int id;
} ac_request_t;
#define AC_REQUEST_CMD AC_ID(AC_TYPE_REQUEST, 1 /* 0b00000001 */) /* 0b01000001 */
typedef struct ac_request_cmd {
uint8_t type;
int id;
ac_config_t *config;
char *cmd;
} ac_request_cmd_t;
#define AC_REQUEST_SET_CONFIG AC_ID(AC_TYPE_REQUEST, 2 /* 0b00000010 */) /* 0b01000010 */
typedef struct ac_request_set_config {
uint8_t type;
int id;
ac_config_t config;
} ac_request_set_config_t;
/**
* Send a request to the connection. If this function succeeds, ac_receive() will return a response
* with the same ID later.
* @param connection Must be a non-NULL and connected connection, or it will return AC_E_INVALID_REQUEST.
* @param request A valid ac_request_t. It will left untouched.
* @return AC_E_OK or an error code.
* MT-Unsafe: Must be called on the same thread calling ac_receive().
*/
LIBAC_EXPORT int ac_request(void *connection, const ac_request_t *request);
#endif /* LIBAC_REQUESTS_H */
|