From e579210fec9416caa37c471fde97ce7b7aae4d05 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 17 Jun 2012 18:52:51 -0700 Subject: [PATCH] kill the eventbus, it was never used --- scripts/tests/common.lua | 12 --------- src/CMakeLists.txt | 1 - src/bindings/bindings.c | 40 ---------------------------- src/util/eventbus.c | 57 ---------------------------------------- src/util/eventbus.h | 29 -------------------- 5 files changed, 139 deletions(-) delete mode 100644 src/util/eventbus.c delete mode 100644 src/util/eventbus.h diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index b1b69c211..3fe4a1ae8 100755 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -46,18 +46,6 @@ function setup() eressea.settings.set("rules.economy.food", "4") end -function DISABLE_test_eventbus_fire() - local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") - local u = unit.create(f, r) - - function compare_f(u, event, f) - assert_equal(u.faction, f) - end - eventbus.register(u, "weird", compare_f) - eventbus.fire(u, "weird", f) -end - function test_fleeing_units_can_be_transported() local r = region.create(0, 0, "plain") local r1 = region.create(1, 0, "plain") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c5166356c..1cc33a9b9 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -181,7 +181,6 @@ set (LIB_SRC util/console.c util/crmessage.c util/dice.c - util/eventbus.c util/event.c util/filereader.c util/functions.c diff --git a/src/bindings/bindings.c b/src/bindings/bindings.c index f4832a727..12480b8a5 100755 --- a/src/bindings/bindings.c +++ b/src/bindings/bindings.c @@ -62,7 +62,6 @@ without prior permission by the authors of Eressea. #include #include #include -#include #include #include #include @@ -1031,39 +1030,6 @@ static void event_cb(void *sender, const char *event, void *udata) lua_pcall(L, nargs, 0, 0); } -/* arguments: - * 1: sender (usertype) - * 2: event (string) - * 3: handler (function) - * 4: arguments (any, *optional*) -**/ -static int tolua_eventbus_register(lua_State * L) -{ - void *sender = tolua_tousertype(L, 1, 0); - const char *event = tolua_tostring(L, 2, 0); - event_args *args = (event_args *)malloc(sizeof(event_args)); - args->sendertype = sender ? tolua_typename(L, 1) : NULL; - lua_pushvalue(L, 3); - args->hfunction = luaL_ref(L, LUA_REGISTRYINDEX); - if (lua_type(L, 4) != LUA_TNONE) { - lua_pushvalue(L, 4); - args->hargs = luaL_ref(L, LUA_REGISTRYINDEX); - } else { - args->hargs = 0; - } - eventbus_register(sender, event, &event_cb, &args_free, args); - return 0; -} - -static int tolua_eventbus_fire(lua_State * L) -{ - void *sender = tolua_tousertype(L, 1, 0); - const char *event = tolua_tostring(L, 2, 0); - void *args = NULL; - eventbus_fire(sender, event, args); - return 0; -} - static int tolua_report_unit(lua_State * L) { char buffer[512]; @@ -1145,12 +1111,6 @@ int tolua_bindings_open(lua_State * L) #endif tolua_variable(L, TOLUA_CAST "text", tolua_get_spell_text, 0); } tolua_endmodule(L); - tolua_module(L, TOLUA_CAST "eventbus", 1); - tolua_beginmodule(L, TOLUA_CAST "eventbus"); - { - tolua_function(L, TOLUA_CAST "register", &tolua_eventbus_register); - tolua_function(L, TOLUA_CAST "fire", &tolua_eventbus_fire); - } tolua_endmodule(L); tolua_module(L, TOLUA_CAST "report", 1); tolua_beginmodule(L, TOLUA_CAST "report"); { diff --git a/src/util/eventbus.c b/src/util/eventbus.c deleted file mode 100644 index d4c7829fd..000000000 --- a/src/util/eventbus.c +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include "eventbus.h" - -/* -** first iteration. it is slow, and a proof of the concept - the simplest -** thing that would work, a.k.a. should be refectored when required. -*/ - -typedef struct listener { - struct listener *next; - event_handler callback; - event_arg_free destroy; - void *sender; - char *event; - void *arguments; -} listener; - -static listener *listeners; - -void eventbus_fire(void *sender, const char *event, void *args) -{ - listener *lst = listeners; - while (lst) { - int i = strcmp(lst->event, event); - if (i > 0) - break; - if (i == 0) { - if (!lst->sender || lst->sender == sender) { - lst->callback(sender, event, args); - } - } - lst = lst->next; - } -} - -void -eventbus_register(void *sender, const char *event, event_handler cb, - event_arg_free arg_free, void *args) -{ - listener *lst; - listener **lstp = &listeners; - while (*lstp) { - lst = *lstp; - if (strcmp(lst->event, event) >= 0) { - break; - } - lstp = &lst->next; - } - lst = malloc(sizeof(listener)); - lst->sender = sender; - lst->arguments = args; - lst->callback = cb; - lst->destroy = arg_free; - lst->event = strdup(event); - lst->next = *lstp; - *lstp = lst; -} diff --git a/src/util/eventbus.h b/src/util/eventbus.h deleted file mode 100644 index 6bd266e51..000000000 --- a/src/util/eventbus.h +++ /dev/null @@ -1,29 +0,0 @@ -/* vi: set ts=2: - +-------------------+ - | | Enno Rehling - | Eressea PBEM host | Katja Zedel - | (c) 1998 - 2010 | Christian Schlittchen - | | - +-------------------+ - - This program may not be used, modified or distributed - without prior permission by the authors of Eressea. -*/ - -#ifndef H_UTIL_EVTBUS -#define H_UTIL_EVTBUS - -#ifdef __cplusplus -extern "C" { -#endif - - typedef void (*event_handler) (void *, const char *, void *); - typedef void (*event_arg_free) (void *); - void eventbus_fire(void *sender, const char *event, void *args); - void eventbus_register(void *sender, const char *event, - event_handler callback, event_arg_free arg_free, void *args); - -#ifdef __cplusplus -} -#endif -#endif