kill the eventbus, it was never used

This commit is contained in:
Enno Rehling 2012-06-17 18:52:51 -07:00
parent 1298684fd9
commit e579210fec
5 changed files with 0 additions and 139 deletions

View File

@ -46,18 +46,6 @@ function setup()
eressea.settings.set("rules.economy.food", "4") eressea.settings.set("rules.economy.food", "4")
end 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() function test_fleeing_units_can_be_transported()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local r1 = region.create(1, 0, "plain") local r1 = region.create(1, 0, "plain")

View File

@ -181,7 +181,6 @@ set (LIB_SRC
util/console.c util/console.c
util/crmessage.c util/crmessage.c
util/dice.c util/dice.c
util/eventbus.c
util/event.c util/event.c
util/filereader.c util/filereader.c
util/functions.c util/functions.c

View File

@ -62,7 +62,6 @@ without prior permission by the authors of Eressea.
#include <util/attrib.h> #include <util/attrib.h>
#include <util/base36.h> #include <util/base36.h>
#include <util/console.h> #include <util/console.h>
#include <util/eventbus.h>
#include <util/language.h> #include <util/language.h>
#include <util/lists.h> #include <util/lists.h>
#include <util/log.h> #include <util/log.h>
@ -1031,39 +1030,6 @@ static void event_cb(void *sender, const char *event, void *udata)
lua_pcall(L, nargs, 0, 0); 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) static int tolua_report_unit(lua_State * L)
{ {
char buffer[512]; char buffer[512];
@ -1145,12 +1111,6 @@ int tolua_bindings_open(lua_State * L)
#endif #endif
tolua_variable(L, TOLUA_CAST "text", tolua_get_spell_text, 0); tolua_variable(L, TOLUA_CAST "text", tolua_get_spell_text, 0);
} tolua_endmodule(L); } 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_module(L, TOLUA_CAST "report", 1);
tolua_beginmodule(L, TOLUA_CAST "report"); tolua_beginmodule(L, TOLUA_CAST "report");
{ {

View File

@ -1,57 +0,0 @@
#include <platform.h>
#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;
}

View File

@ -1,29 +0,0 @@
/* vi: set ts=2:
+-------------------+
| | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
| (c) 1998 - 2010 | Christian Schlittchen <corwin@amber.kn-bremen.de>
| |
+-------------------+
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