47 lines
1.1 KiB
C
47 lines
1.1 KiB
C
#include "evt_core.h"
|
|
|
|
void free_int(void* v) {
|
|
free(v);
|
|
}
|
|
|
|
void free_char(void* c) {
|
|
free(c);
|
|
}
|
|
|
|
void free_cat(void* vcat) {
|
|
struct evt_core_cat* cat = (struct evt_core_cat*) vcat;
|
|
cat->free_app_ctx(cat->app_ctx);
|
|
}
|
|
|
|
void evt_core_init(struct evt_core_ctx* ctx) {
|
|
ctx->epollfd = epoll_create1(0);
|
|
if (ctx->epollfd == -1) {
|
|
perror("Failed to create epoll file descriptor epoll_create1");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
ctx->catlist = g_hash_table_new_full(g_str_hash, g_str_equal,free_char,free_cat);
|
|
ctx->socklist = g_hash_table_new_full(g_int_hash, g_int_equal,free_int, NULL);
|
|
}
|
|
|
|
void evt_core_add_cat(struct evt_core_cat* cat) {
|
|
struct evt_core_cat* dyn = NULL;
|
|
dyn = malloc(sizeof(struct evt_core_cat));
|
|
if (dyn == NULL) {
|
|
fprintf(stderr, "Failed to alloc memory");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
dyn->app_ctx = cat->app_ctx;
|
|
dyn->free_app_ctx = cat->free_app_ctx;
|
|
dyn->cb = cat->cb;
|
|
dyn->name = strdup(cat->name);
|
|
dyn->flags = cat->flags;
|
|
|
|
if (dyn->name == NULL) {
|
|
perror("Unable to allocate memory for category name via strdup");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
|
|
}
|