generic msg system - really intended mostly to go hand-in-hand width the

datastore stuff as a way of moduels beoing able to talk TO eachother
indirectly by sending messages, and advertising public data.


SVN revision: 15050
This commit is contained in:
Carsten Haitzler 2005-06-02 07:40:04 +00:00
parent a0d654aa60
commit 4fa5c6343c
6 changed files with 168 additions and 1 deletions

2
TODO
View File

@ -55,6 +55,8 @@ Also look at all the .c files - they have their own localized TODO lists
These are in no particular order:
* add locale and encoding fields to eapp files (to launch eapp in that locale+encoding)
* add input method selector stuff to eapp - same as locale
* libechack needs to come back - and execute all things with libehack preloads active
* get all libehack properties if they exist
* titlebar/border expansion/gadget panel for moduels to put window widgets in

View File

@ -56,7 +56,8 @@ e_actions.h \
e_popup.h \
e_ipc_codec.h \
e_prefix.h \
e_datastore.h
e_datastore.h \
e_msg.h
enlightenment_SOURCES = \
e_main.c \
@ -104,6 +105,7 @@ e_popup.c \
e_ipc_codec.c \
e_prefix.c \
e_datastore.c \
e_msg.c \
$(ENLIGHTENMENTHEADERS)
enlightenment_LDFLAGS = -export-dynamic @e_libs@ @dlopen_libs@

View File

@ -44,3 +44,5 @@
#include "e_ipc_codec.h"
#include "e_test.h"
#include "e_prefix.h"
#include "e_datastore.h"
#include "e_msg.h"

View File

@ -389,6 +389,13 @@ main(int argc, char **argv)
else
_e_main_shutdown_push(_e_main_ipc_shutdown);
/* setup module loading etc */
if (!e_msg_init())
{
e_error_message_show(_("Enlightenment cannot set up its msg system."));
_e_main_shutdown(-1);
}
_e_main_shutdown_push(e_msg_shutdown);
/* setup module loading etc */
if (!e_module_init())
{

134
src/bin/e_msg.c Normal file
View File

@ -0,0 +1,134 @@
/*
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
*/
#include "e.h"
typedef struct _E_Msg_Event E_Msg_Event;
struct _E_Msg_Handler
{
void (*func) (void *data, char *name, char *info, int val, E_Object *obj);
void *data;
unsigned char delete_me : 1;
};
struct _E_Msg_Event
{
char *name;
char *info;
int val;
E_Object *obj;
};
/* local subsystem functions */
static int _e_msg_event_cb(void *data, int ev_type, void *ev);
static void _e_msg_event_free(void *data, void *ev);
/* local subsystem globals */
static Evas_List *handlers = NULL;
static Evas_List *del_handlers = NULL;
static int processing_handlers = 0;
static int E_EVENT_MSG = 0;
static Ecore_Event_Handler *hand = NULL;
/* externally accessible functions */
int
e_msg_init(void)
{
E_EVENT_MSG = ecore_event_type_new();
hand = ecore_event_handler_add(E_EVENT_MSG, _e_msg_event_cb, NULL);
return 1;
}
int
e_msg_shutdown(void)
{
while (handlers) e_msg_handler_del(handlers->data);
E_EVENT_MSG = 0;
if (hand) ecore_event_handler_del(hand);
hand = NULL;
return 1;
}
void
e_msg_send(char *name, char *info, int val, E_Object *obj)
{
E_Msg_Event *ev;
ev = calloc(1, sizeof(E_Msg_Event));
if (name) ev->name = strdup(name);
if (info) ev->info = strdup(info);
ev->val = val;
ev->obj = obj;
if (ev->obj) e_object_ref(ev->obj);
ecore_event_add(E_EVENT_MSG, ev, _e_msg_event_free, NULL);
}
E_Msg_Handler *
e_msg_handler_add(void (*func) (void *data, char *name, char *info, int val, E_Object *obj), void *data)
{
E_Msg_Handler *emsgh;
emsgh = calloc(1, sizeof(E_Msg_Handler));
if (!emsgh) return NULL;
emsgh->func = func;
emsgh->data = data;
handlers = evas_list_append(handlers, emsgh);
return emsgh;
}
void
e_msg_handler_del(E_Msg_Handler *emsgh)
{
if (processing_handlers > 0)
{
emsgh->delete_me = 1;
del_handlers = evas_list_append(del_handlers, emsgh);
}
else
{
handlers = evas_list_remove(handlers, emsgh);
free(emsgh);
}
}
/* local subsystem functions */
static int
_e_msg_event_cb(void *data, int ev_type, void *ev)
{
E_Msg_Event *e;
Evas_List *l;
processing_handlers++;
e = ev;
for (l = handlers; l; l = l->next)
{
E_Msg_Handler *emsgh;
emsgh = l->data;
if (!emsgh->delete_me)
emsgh->func(emsgh->data, e->name, e->info, e->val, e->obj);
}
processing_handlers--;
if ((processing_handlers == 0) && (del_handlers))
{
while (del_handlers)
{
e_msg_handler_del(del_handlers->data);
del_handlers = evas_list_remove_list(del_handlers, del_handlers);
}
}
return 1;
}
static void
_e_msg_event_free(void *data, void *ev)
{
E_Msg_Event *e;
e = ev;
if (e->name) free(e->name);
if (e->info) free(e->info);
if (e->obj) e_object_unref(e->obj);
}

20
src/bin/e_msg.h Normal file
View File

@ -0,0 +1,20 @@
/*
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
*/
#ifdef E_TYPEDEFS
typedef struct _E_Msg_Handler E_Msg_Handler;
#else
#ifndef E_MSG_H
#define E_MSG_H
EAPI int e_msg_init(void);
EAPI int e_msg_shutdown(void);
EAPI void e_msg_send(char *name, char *info, int val, E_Object *obj);
EAPI E_Msg_Handler *e_msg_handler_add(void (*func) (void *data, char *name, char *info, int val, E_Object *obj), void *data);
EAPI void e_msg_handler_del(E_Msg_Handler *emsgh);
#endif
#endif