Skip to content

Commit

Permalink
Debuging code..
Browse files Browse the repository at this point in the history
git-svn-id: https://subversion.cs.uiuc.edu/svn/bang/eoh2009@165 69d76c3e-0761-0410-948c-9895a8bb34fc
  • Loading branch information
nbysani2 committed Mar 13, 2009
1 parent 6b411f7 commit 1aac697
Show file tree
Hide file tree
Showing 12 changed files with 167 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -9,7 +9,7 @@ CC=gcc
OBJEXT=.o
SRCEXT=.c

COPTS=-Wall -Wextra -Werror -fPIC -g -D_REENTRANT -lpthread
COPTS=-Wall -Wextra -Werror -fPIC -rdynamic -g -D_REENTRANT -lpthread -DBDEBUG_1

GTKOPTS=`pkg-config --cflags --libs gtk+-2.0 --libs openssl --libs uuid --libs gthread-2.0`
LOBJS=bang-com$(OBJEXT) \
Expand Down
15 changes: 12 additions & 3 deletions src/app/file-menu.c
@@ -1,22 +1,31 @@
#include"bang-machine-utils.h"
#include"file-menu.h"
#include"../base/bang.h"
#include<gtk/gtk.h>
#include<stdlib.h>

static GtkWidget *notebook = NULL;

typedef void (*GUI_module_init)(GtkWidget**,GtkWidget**);

static void deal_with_module(gchar *filename) {
char *module_name;
unsigned char *module_version;
BANG_module* module;
GtkWidget *notebook;
GtkWidget *page;

BANG_new_module(filename, &module_name, &module_version);
module = BANG_get_module(module_name, module_version);

#ifdef BDEBUG_1
fprintf(stderr,"Running a module init.\n");
#endif

GUI_module_init gui_module_init = BANG_get_symbol(module,"GUI_init");
if (gui_module_init)
gui_module_init(&notebook,&page);


void* BANG_get_symbol(BANG_module *module, char *symbol);
BANG_run_module_in_registry(module_name, module_version);
}

void BMACHINE_open_module() {
Expand Down
2 changes: 2 additions & 0 deletions src/app/file-menu.h
Expand Up @@ -2,6 +2,8 @@
#define __FILE_MENU_H
#include<gtk/gtk.h>

typedef void (*GUI_module_init)(GtkWidget**,GtkWidget**);

void BMACHINE_open_module();

void BMACHINE_exit();
Expand Down
4 changes: 4 additions & 0 deletions src/base/bang-com.c
Expand Up @@ -123,6 +123,10 @@ void BANG_request_all(BANG_request *request) {
}

void BANG_com_init() {
#ifdef BDEBUG_1
fprintf(stderr,"BANG com starting.\n");
#endif

BANG_install_sighandler(BANG_PEER_CONNECTED,&catch_add_peer);
BANG_install_sighandler(BANG_PEER_DISCONNECTED,&catch_remove_peer);
BANG_install_sighandler(BANG_REQUEST_ALL,&catch_request_all);
Expand Down
55 changes: 43 additions & 12 deletions src/base/bang-module-registry.c
Expand Up @@ -2,6 +2,7 @@
#include"bang-module-api.h"
#include"bang-utils.h"
#include"string.h"
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
#include<uuid/uuid.h>
Expand Down Expand Up @@ -81,33 +82,55 @@ static int compare_module_wrapper_key_t(const void *d1, const void *d2) {
const module_wrapper_key_t *mk1 = d1;
const module_wrapper_key_t *mk2 = d2;

return BANG_version_cmp(mk1->version, mk2->version) +
int ret = BANG_version_cmp(mk1->version, mk2->version) +
strcmp(mk1->name, mk2->name);

#ifdef BDEBUG_1
fprintf(stderr,"Found that %s and %s matched at %d.\n",mk1->name, mk2->name, ret);
#endif

return ret;
}

void BANG_new_module(char *path, char **module_name, unsigned char **module_version) {
BANG_module* new_mod = BANG_load_module(path);
#ifdef BDEBUG_2
fprintf(stderr,"Putting a new module in the registry.\n");
#endif

if (module_name) {
*module_name = new_mod->info->module_name;
}
BANG_module *module = BANG_load_module(path);

if (module_version) {
*module_version = new_mod->info->module_version;
}
if (module) {
if (module_name) {
*module_name = module->info->module_name;
}

module_wrapper_t *module_wrapper = new_module_wrapper(new_mod);
module_wrapper_key_t module_key = create_key(new_mod->info->module_name, new_mod->info->module_version);
if (module_version) {
*module_version = module->info->module_version;
}

BANG_hashmap_set(modules,&module_key,module_wrapper);

module_wrapper_t *module_wrapper = new_module_wrapper(module);
module_wrapper_key_t module_key = create_key(module->info->module_name, module->info->module_version);

#ifdef BDEBUG_1
fprintf(stderr,"Trying to put the %s module into a hashmap.\n",module_wrapper->module->info->module_name);
#endif
BANG_hashmap_set(modules,&module_key,module_wrapper);
}
}

BANG_module* BANG_get_module(char *module_name, unsigned char *module_version) {
#ifdef BDEBUG_1
fprintf(stderr,"Trying to get the %s module.\n", module_name);
#endif
module_wrapper_key_t module_key = create_key(module_name, module_version);

module_wrapper_t *module_wrapper = BANG_hashmap_get(modules,&module_key);

return module_wrapper->module;
if (module_wrapper)
return module_wrapper->module;
else
return NULL;
}

int BANG_run_module_in_registry(char *module_name, unsigned char *module_version) {
Expand Down Expand Up @@ -143,9 +166,17 @@ void BANG_module_inform_new_peer(char *module_name, unsigned char *module_versio
}

void BANG_module_registry_init() {
#ifdef BDEBUG_1
fprintf(stderr,"BANG module registry starting.\n");
#endif

modules = new_BANG_hashmap(&hash_module_wrapper_key_t,&compare_module_wrapper_key_t);
}

void BANG_module_registry_close() {
#ifdef BDEBUG_1
fprintf(stderr,"BANG module registry closing.\n");
#endif

free_BANG_hashmap(modules);
}
24 changes: 22 additions & 2 deletions src/base/bang-module.c
Expand Up @@ -222,9 +222,20 @@ BANG_module* BANG_load_module(char *path) {
module->handle = handle;
module->path = path;

#ifdef BDEBUG_1
fprintf(stderr,"%s's init function has been called.\n",module_name);
#endif
module->callbacks = module->module_init(get_BANG_api());
#ifdef BDEBUG_1
fprintf(stderr,"%s's init function is over.\n",module_name);
#endif

module->info = new_BANG_module_info(module_name, module_version);

#ifdef BDEBUG_1
fprintf(stderr,"Created a new module, now returning it.\n");
#endif

return module;
}

Expand All @@ -242,6 +253,10 @@ void BANG_unload_module(BANG_module *module) {


void BANG_run_module(BANG_module *module) {
#ifdef BDEBUG_1
fprintf(stderr,"Running module %s.\n", module->info->module_name);
#endif

assert(module != NULL);

if (module != NULL) {
Expand All @@ -258,17 +273,22 @@ void BANG_run_module(BANG_module *module) {
void* BANG_get_symbol(BANG_module *module, char *symbol) {
assert(module != NULL);
assert(symbol != NULL);
char *error;

if (module != NULL) {
/* Get rid of any lingering errors. */
while (dlerror() != NULL) {}

void* sym_to_get = dlsym(module->handle,symbol);

if (dlerror() == NULL)
if ((error = dlerror()) == NULL)
return sym_to_get;
else
else {
#ifdef BDEBUG_1
fprintf(stderr,"Symbol %s returned with error %s.\n",symbol,error);
#endif
return NULL;
}
} else
return NULL;
}
Expand Down
4 changes: 4 additions & 0 deletions src/base/bang-net.c
Expand Up @@ -238,6 +238,10 @@ char BANG_is_server_running(){
}

void BANG_net_init(char *server_port ,char start_server) {
#ifdef BDEBUG_1
fprintf(stderr,"BANG net starting.\n");
#endif

if (server_port != NULL) {
port = server_port;
}
Expand Down
10 changes: 9 additions & 1 deletion src/base/bang-routing.c
Expand Up @@ -69,7 +69,7 @@ static void create_peer_to_uuids(int signal, int num_ps, void **peer_ids) {

if (signal == BANG_PEER_ADDED) {
for (i = 0; i < num_ps; ++i) {
peer_ids = peer_ids[i];
peer_id = peer_ids[i];

BANG_write_lock(routes_lock);

Expand Down Expand Up @@ -529,6 +529,10 @@ void BANG_deregister_route(uuid_t route) {
}

void BANG_route_init() {
#ifdef BDEBUG_1
fprintf(stderr,"BANG routing starting.\n");
#endif

routes_lock = new_BANG_rw_syncro();

BANG_write_lock(routes_lock);
Expand All @@ -543,6 +547,10 @@ void BANG_route_init() {
}

void BANG_route_close() {
#ifdef BDEBUG_1
fprintf(stderr,"BANG routing ending.\n");
#endif

BANG_write_lock(routes_lock);

free_BANG_hashmap(routes);
Expand Down
4 changes: 4 additions & 0 deletions src/base/bang-signals.c
Expand Up @@ -22,6 +22,10 @@
BANG_linked_list *(signal_handlers[BANG_NUM_SIGS]);

void BANG_sig_init() {
#ifdef BDEBUG_1
fprintf(stderr,"BANG sig starting.\n");
#endif

int i;

for (i = 0; i < BANG_NUM_SIGS; ++i) {
Expand Down

0 comments on commit 1aac697

Please sign in to comment.