eliminate unused callback module.

what was I thinking when I wrote this?
This commit is contained in:
Enno Rehling 2016-11-17 10:32:20 +01:00
parent 42eff95ec2
commit f371a0c5f3
5 changed files with 0 additions and 131 deletions

View File

@ -99,7 +99,6 @@ set (ERESSEA_SRC
prefix.c
donations.c
eressea.c
callback.c
direction.c
keyword.c
skill.c
@ -205,7 +204,6 @@ set(TESTS_SRC
report.test.c
summary.test.c
travelthru.test.c
callback.test.c
direction.test.c
economy.test.c
json.test.c

View File

@ -1,61 +0,0 @@
#include <platform.h>
#include "callback.h"
#include <stdlib.h>
#include <string.h>
static struct reg {
struct reg * next;
HCALLBACK cb;
char *name;
} *registry;
HCALLBACK create_callback(void(*cbv)(va_list va)) {
HCALLBACK cb;
cb.cbv = cbv;
return cb;
}
void reset_callbacks(void) {
while (registry) {
struct reg *r = registry;
registry = r->next;
free(r->name);
free(r);
}
registry = 0;
}
HCALLBACK register_callback(const char *name, void(*cbv)(va_list va))
{
struct reg * r = (struct reg *)malloc(sizeof(struct reg));
r->next = registry;
r->name = _strdup(name);
r->cb.cbv = cbv;
registry = r;
return r->cb;
}
int find_callback(const char *name, HCALLBACK *result) {
if (result && name) {
struct reg *r;
for (r = registry; r; r = r->next) {
if (strcmp(r->name, name) == 0) {
*result = r->cb;
return 0;
}
}
}
return -1;
}
int call_callback(HCALLBACK cb, const char *name, ...) {
va_list ap;
if (name) {
int err = find_callback(name, &cb);
if (err) return err;
}
va_start(ap, name);
cb.cbv(ap);
va_end(ap);
return 0;
}

View File

@ -1,16 +0,0 @@
#ifndef H_CALLBACK_H
#define H_CALLBACK_H
#include <stdarg.h>
typedef struct {
void(*cbv)(va_list va);
} HCALLBACK;
HCALLBACK register_callback(const char *name, void(*cbv)(va_list va));
HCALLBACK create_callback(void(*cbv)(va_list va));
int find_callback(const char *name, HCALLBACK *result);
int call_callback(HCALLBACK cb, const char *name, ...);
void reset_callbacks(void);
#endif

View File

@ -1,51 +0,0 @@
#include "callback.h"
#include <stdlib.h>
#include <CuTest.h>
void callback(va_list ap) {
int i = (int)va_arg(ap, int);
int *p = va_arg(ap, int *);
*p += i;
}
static void test_find_callback(CuTest *tc) {
HCALLBACK cb;
reset_callbacks();
CuAssertIntEquals(tc, -1, find_callback("test", &cb));
cb = register_callback("test", callback);
CuAssertIntEquals(tc, 0, find_callback("test", &cb));
reset_callbacks();
}
static void test_call_by_handle(CuTest *tc) {
HCALLBACK cb;
int x = 0;
reset_callbacks();
cb = create_callback(callback);
CuAssertIntEquals(tc, 0, call_callback(cb, 0, 42, &x));
CuAssertIntEquals(tc, 42, x);
reset_callbacks();
}
static void test_call_by_name(CuTest *tc) {
HCALLBACK cb = { 0 };
HCALLBACK ca = { 0 };
int x = 0;
reset_callbacks();
CuAssertIntEquals(tc, -1, call_callback(cb, "test", 42, &x));
cb = register_callback("test", callback);
CuAssertIntEquals(tc, 0, call_callback(cb, "test", 42, &x));
CuAssertIntEquals(tc, 42, x);
CuAssertIntEquals(tc, 0, call_callback(ca, "test", 42, &x));
CuAssertIntEquals(tc, 84, x);
reset_callbacks();
}
CuSuite *get_callback_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_find_callback);
SUITE_ADD_TEST(suite, test_call_by_name);
SUITE_ADD_TEST(suite, test_call_by_handle);
return suite;
}

View File

@ -60,7 +60,6 @@ int RunAllTests(int argc, char *argv[])
{
/* self-test */
ADD_SUITE(tests);
ADD_SUITE(callback);
ADD_SUITE(json);
ADD_SUITE(jsonconf);
ADD_SUITE(direction);