aboutsummaryrefslogtreecommitdiff
path: root/client/libacron/include/requests.h
blob: 40742e0f687fbf6fd407c5fd01d49d5dd62035a0 (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
/*
 * Created by yuuta on 7/13/22.
 */

#ifndef LIBAC_REQUESTS_H
#define LIBAC_REQUESTS_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;

int ac_request(void *connection, const ac_request_t *request);

#endif /* LIBAC_REQUESTS_H */