|
From: <cli...@li...> - 2007-05-22 21:12:10
|
Revision: 64
http://cligg.svn.sourceforge.net/cligg/?rev=64&view=rev
Author: sithhell
Date: 2007-05-22 14:12:07 -0700 (Tue, 22 May 2007)
Log Message:
-----------
modulehandler is finally nearly complete, though there are some small FIXMEs in the code
Modified Paths:
--------------
src/bin/CMakeLists.txt
src/bin/cligg.c
src/bin/cligg_mainloop.c
src/bin/cligg_mainloop.h
src/bin/cligg_modulehandler.c
src/lib/cligg_list.c
src/lib/cligg_module.c
src/modules/print/print.c
src/modules/read/read.c
Modified: src/bin/CMakeLists.txt
===================================================================
--- src/bin/CMakeLists.txt 2007-05-22 16:44:16 UTC (rev 63)
+++ src/bin/CMakeLists.txt 2007-05-22 21:12:07 UTC (rev 64)
@@ -5,3 +5,4 @@
target_link_libraries(cligg cligglib cligg_mainloop cligg_eventhandler cligg_modulehandler pthread dl)
add_executable(tree_test test.c)
target_link_libraries(tree_test cligglib)
+set_target_properties(cligg cligg_modulehandler PROPERTIES LINK_FLAGS -rdynamic)
Modified: src/bin/cligg.c
===================================================================
--- src/bin/cligg.c 2007-05-22 16:44:16 UTC (rev 63)
+++ src/bin/cligg.c 2007-05-22 21:12:07 UTC (rev 64)
@@ -51,7 +51,7 @@
/* TODO register basic events */
/* event for quitting softly */
- cligg_register_event("quit_cligg", quit_cligg);
+ /*cligg_register_event("quit_cligg", quit_cligg);*/
/* init module system */
ret = cligg_init_modulehandler();
@@ -60,9 +60,10 @@
fprintf(stderr, "Error loading module\n");*/
/*cligg_trigger_event("load_module", "test");*/
- /*cligg_trigger_event("load_module", "/home/heller/projekte/cligg/src/modules/dummy/dummy.so");*/
+ cligg_trigger_event("load_module", "/home/heller/projekte/cligg/src/modules/dummy/dummy.so");
cligg_trigger_event("load_module", "/home/heller/projekte/cligg/src/modules/print/print.so");
cligg_trigger_event("load_module", "/home/heller/projekte/cligg/src/modules/read/read.so");
+ cligg_trigger_event("load_module", "/home/heller/projekte/cligg/src/modules/read/read.so");
cligg_trigger_event("read", NULL);
/*cligg_trigger_event("quit_cligg", NULL);*/
@@ -72,11 +73,13 @@
/* TODO process the config */
/* TODO define own signal handlers */
+ /* exit handlers ... */
/* starting the event loop */
cligg_main_begin();
/* MAGIC!! */
cligg_main_end();
+ quit_cligg(NULL);
return EXIT_SUCCESS;
}
@@ -88,5 +91,5 @@
fprintf(stderr, "Good Bye!\n");
- exit(EXIT_SUCCESS);
+ return EXIT_SUCCESS;
}
Modified: src/bin/cligg_mainloop.c
===================================================================
--- src/bin/cligg_mainloop.c 2007-05-22 16:44:16 UTC (rev 63)
+++ src/bin/cligg_mainloop.c 2007-05-22 21:12:07 UTC (rev 64)
@@ -52,6 +52,13 @@
new = cligg_waiton_event();
if(new == NULL)
return (void *)EXIT_FAILURE;
+
+ if(strcmp(new->name, "quit_cligg") == 0) {
+ free(new->name);
+ free(new);
+ break;
+ }
+
cb = cligg_lookup_event(new->name);
free(new->name);
@@ -61,10 +68,22 @@
else {
if(!cb(new->data))
fprintf(stderr, "Event callback failed!\n");
+ /*else {
+ if(strcmp(new->name, "quit_cligg") == 0) {
+ free(new->name);
+ free(new);
+ }
+ }*/
}
- /*if(strcmp(new->name, "quit_cligg") == 0) break;*/
+ /*if(strcmp(new->name, "quit_cligg") == 0){
+ free(new->name);
+ free(new);
+ break;
+ }
+ free(new->name);*/
free(new);
}
- pthread_exit((void *)EXIT_SUCCESS);
+ /*pthread_exit((void *)EXIT_SUCCESS);*/
+ return (void *)EXIT_SUCCESS;
}
Modified: src/bin/cligg_mainloop.h
===================================================================
--- src/bin/cligg_mainloop.h 2007-05-22 16:44:16 UTC (rev 63)
+++ src/bin/cligg_mainloop.h 2007-05-22 21:12:07 UTC (rev 64)
@@ -10,4 +10,5 @@
void *
cligg_loop(void *);
+
#endif
Modified: src/bin/cligg_modulehandler.c
===================================================================
--- src/bin/cligg_modulehandler.c 2007-05-22 16:44:16 UTC (rev 63)
+++ src/bin/cligg_modulehandler.c 2007-05-22 21:12:07 UTC (rev 64)
@@ -39,6 +39,7 @@
int
cligg_del_modulehandler(void)
{
+ /* FIXME this leads to a leak of 20 bytes at the end, don't know why */
cligg_module *tmp;
while((tmp = cligg_list_element_get_first(module_list))) {
cligg_unregister_module(tmp);
@@ -51,36 +52,58 @@
int cligg_register_module(char *path)
{
int ret = TRUE;
+ void *test;
cligg_module *new = cligg_module_new(path);
if(new == NULL) {
perror("Error loading module");
+ dlerror();
return FALSE;
}
+ if(cligg_list_element_find(module_list, cmp, new) > 0) {
+ fprintf(stderr, "Couldn't add module %s: already there\n", new->path);
+ cligg_module_del(new);
+ dlerror();
+ return FALSE;
+ }
+ /* FIXME this is better, perhaps, but creates some memory leaks */
+ /*if((test = dlopen(path, RTLD_LAZY | RTLD_NOLOAD)) != NULL) {
+ dlclose(test);
+ fprintf(stderr, "Couldn't add module %s", dlerror());
+ cligg_module_del(new);
+ dlerror();
+ return FALSE;
+ }*/
+
new->handle = dlopen(path, RTLD_LAZY);
if(!new->handle) {
fprintf(stderr, "Error loading module: %s\n", dlerror());
cligg_module_del(new);
+ dlerror();
return FALSE;
}
if(pthread_mutex_lock(&module_lock) != 0) {
fprintf(stderr, "Couldn't obtain module lock!\n");
+ dlclose(new->handle);
+ dlerror();
cligg_module_del(new);
return FALSE;
}
if(!cligg_list_element_append(module_list, new)) {
perror("Error loading module");
+ dlerror();
ret = FALSE;
}
if(pthread_mutex_unlock(&module_lock) != 0) {
fprintf(stderr, "Couldn't unlock module lock!\n");
+ dlclose(new->handle);
cligg_module_del(new);
+ dlerror();
return FALSE;
}
-
dlerror(); /* clear any existing errors */
return ret;
}
@@ -89,21 +112,27 @@
{
cligg_module *tmp;
int ret = TRUE;
+ dlerror();
if(pthread_mutex_lock(&module_lock) != 0) {
fprintf(stderr, "Couldn't obtain module lock!\n");
cligg_module_del(tmp);
+ dlerror();
return FALSE;
}
if(cligg_list_element_find(module_list, cmp, module) == -1) {
fprintf(stderr, "Couldn't delete module: Not found!\n");
+ dlerror();
ret = FALSE;
}
else {
tmp = (cligg_module *)module_list->current->data;
- dlclose(tmp->handle);
+ if(dlclose(tmp->handle) != 0)
+ fprintf(stderr, "Error unloading module: %s\n", dlerror());
+ tmp->handle = NULL;
+ module->handle = NULL;
cligg_list_element_del_current(module_list);
}
@@ -111,8 +140,10 @@
if(pthread_mutex_unlock(&module_lock) != 0) {
fprintf(stderr, "Couldn't unlock module lock!\n");
cligg_module_del(tmp);
+ dlerror();
return FALSE;
}
+ dlerror();
return ret;
}
@@ -128,5 +159,6 @@
static int module_unreg_event_cb(void *data)
{
+ printf("unregister\n");
return cligg_unregister_module((cligg_module *)data);
}
Modified: src/lib/cligg_list.c
===================================================================
--- src/lib/cligg_list.c 2007-05-22 16:44:16 UTC (rev 63)
+++ src/lib/cligg_list.c 2007-05-22 21:12:07 UTC (rev 64)
@@ -357,7 +357,7 @@
if(compare_func(list->last->data, data) == 0) {
list->current = list->last;
- return list->size-1;
+ return list->size;
}
if(compare_func(list->first->data, data) == 0) {
list->current = list->first;
Modified: src/lib/cligg_module.c
===================================================================
--- src/lib/cligg_module.c 2007-05-22 16:44:16 UTC (rev 63)
+++ src/lib/cligg_module.c 2007-05-22 21:12:07 UTC (rev 64)
@@ -24,7 +24,7 @@
void cligg_module_del(void *module)
{
cligg_module *old = (cligg_module *)module;
-
+ old->handle = NULL;
free(old->path);
free(old);
}
Modified: src/modules/print/print.c
===================================================================
--- src/modules/print/print.c 2007-05-22 16:44:16 UTC (rev 63)
+++ src/modules/print/print.c 2007-05-22 21:12:07 UTC (rev 64)
@@ -7,13 +7,13 @@
cligg_module_init print_init(void)
{
fprintf(stderr, "Print Module is loaded!\n");
- cligg_register_event("print",print);
+ cligg_register_event("print",print);
}
static int print(void *data)
{
printf("output: %s",(char *)data);
- cligg_trigger_event("read", NULL);
+ /*cligg_trigger_event("read", NULL);*/
return TRUE;
}
Modified: src/modules/read/read.c
===================================================================
--- src/modules/read/read.c 2007-05-22 16:44:16 UTC (rev 63)
+++ src/modules/read/read.c 2007-05-22 21:12:07 UTC (rev 64)
@@ -5,7 +5,7 @@
#include <cligg_eventhandler.h>
static int read(void *data);
-static char inp[101];
+static char inp[1025];
cligg_module_init print_init(void)
{
@@ -15,13 +15,14 @@
static int read(void *data)
{
- /*char *inp = malloc(101 * sizeof(char));*/
printf("input: ");
fgets(inp, 100, stdin);
printf("\n");
if(strcmp("quit\n", inp) == 0) cligg_trigger_event("quit_cligg", NULL);
- else cligg_trigger_event("print", inp);
- /*cligg_trigger_event("read", NULL);*/
+ else {
+ cligg_trigger_event("print", inp);
+ cligg_trigger_event("read", NULL);
+ }
return TRUE;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|