Event core definition add

This commit is contained in:
Quentin Dufour 2019-02-11 19:14:07 +01:00
parent 30c1c1b9c8
commit a9428e932f

View file

@ -11,6 +11,8 @@ void free_char(void* c) {
void free_cat(void* vcat) {
struct evt_core_cat* cat = (struct evt_core_cat*) vcat;
cat->free_app_ctx(cat->app_ctx);
free(cat->name);
free(cat);
}
void evt_core_init(struct evt_core_ctx* ctx) {
@ -24,11 +26,11 @@ void evt_core_init(struct evt_core_ctx* ctx) {
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) {
void evt_core_add_cat(struct evt_core_ctx* ctx, 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");
fprintf(stderr, "Failed to alloc memory\n");
exit(EXIT_FAILURE);
}
dyn->app_ctx = cat->app_ctx;
@ -42,5 +44,31 @@ void evt_core_add_cat(struct evt_core_cat* cat) {
exit(EXIT_FAILURE);
}
char* key = NULL;
key = strdup(cat->name);
if (key == NULL) {
perror("Unable to allocate memory for key via strdup");
exit(EXIT_FAILURE);
}
g_hash_table_insert (ctx->catlist, key, dyn);
}
void evt_core_add_fd(struct evt_core_ctx* ctx, int fd, char* name) {
int* key = NULL;
key = malloc(sizeof(int));
if (key == NULL) {
perror("Unable to allocate memory for key via malloc");
exit(EXIT_FAILURE);
}
memcpy(key, &fd, sizeof(int));
struct evt_core_cat* cat = g_hash_table_lookup(ctx->catlist, name);
if (cat == NULL) {
fprintf(stderr, "Category %s should be defined before inserting a file descriptor in it.\n", name);
exit(EXIT_FAILURE);
}
g_hash_table_insert(ctx->socklist, key, cat);
}