jitterbug/server.h

59 lines
1.3 KiB
C
Raw Normal View History

#ifndef _JITTERBUG__SERVER_H
#define _JITTERBUG__SERVER_H
2022-12-29 20:10:36 +02:00
#include "match.h"
2023-01-10 14:57:16 +02:00
#include "wire.h"
#include <poll.h>
#include <stdint.h>
// TODO: dynamically size the arrays
2023-01-10 13:08:49 +02:00
#define BUS_MAX_CLIENTS 256
#define BUS_MAX_NAMES 512
#define BUS_MAX_MATCH 12
#define BUS_BACKLOG 12
enum {
2023-01-10 13:08:49 +02:00
BUS_CLIENT_STATE_NONE,
BUS_CLIENT_STATE_WAIT_AUTH,
BUS_CLIENT_STATE_WAIT_BEGIN,
BUS_CLIENT_STATE_READY
};
2023-01-10 13:08:49 +02:00
typedef struct bus_client {
int fd;
uint8_t state;
int16_t unique_name_index;
int16_t owned_name_index;
2022-12-31 17:55:32 +02:00
int8_t match_count;
2023-01-10 13:08:49 +02:00
match_rule_t *matches[BUS_MAX_MATCH];
} bus_client_t;
2023-01-10 13:08:49 +02:00
typedef struct bus_name {
char *name;
2022-12-29 20:10:36 +02:00
int32_t client_index;
2023-01-10 13:08:49 +02:00
} bus_name_t;
2022-12-29 20:10:36 +02:00
2023-01-10 13:08:49 +02:00
typedef struct bus {
int sock_fd;
int fd_num;
2022-12-26 18:05:12 +02:00
int names_count;
2022-12-31 17:55:32 +02:00
int clients_count;
2023-01-10 13:08:49 +02:00
bus_client_t clients[BUS_MAX_CLIENTS];
bus_name_t names[BUS_MAX_NAMES];
struct pollfd fds[BUS_MAX_CLIENTS + 1];
} bus_t;
2023-01-10 14:57:16 +02:00
typedef struct bus_method_handler {
const char *name;
int (*handler)(bus_t *bus, int client_index, wire_message_t *msg, wire_context_t *ctx, wire_context_t *reply_ctx);
} bus_method_handler_t;
2023-01-10 13:08:49 +02:00
int bus_client_add(bus_t *s, int fd);
void bus_client_remove(bus_t *s, int i);
void bus_free(bus_t *s);
bus_t *bus_create(const char *socket_path);
int bus_turn(bus_t *s);
#endif // _JITTERBUG__SERVER_H