/* * 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 /* 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 */