From 707f6cfecb39bac6f88ec77cf6854cfc0624dd49 Mon Sep 17 00:00:00 2001 From: Nikhil Samith Bysani Date: Mon, 12 Jan 2009 13:32:14 -0500 Subject: [PATCH] Wrote some stub functions in the module-api. --- src/base/bang-module-api.c | 19 ++++++++++++++++- src/base/bang-module-api.h | 4 ++-- src/base/bang-module.c | 43 +++++++++++++++++++++++++++----------- 3 files changed, 51 insertions(+), 15 deletions(-) diff --git a/src/base/bang-module-api.c b/src/base/bang-module-api.c index 320f1c0..eb77b4b 100644 --- a/src/base/bang-module-api.c +++ b/src/base/bang-module-api.c @@ -9,7 +9,7 @@ #include #include"bang-module-api.h" -///TODO: Implement this. Well, this is basically what are our app is all about. +/* TODO: Implement this. Well, this is basically what are our app is all about. */ void BANG_debug_on_all_peers(char *message) { fprintf(stderr,message); } @@ -24,3 +24,20 @@ int BANG_number_of_active_peers() { int BANG_get_my_id() { return -1; } + +void BANG_assert_authority(int id) { + fprintf(stderr,"%d is asserting authority!\n",id); +} + +BANG_job* BANG_request_job(int id, char blocking) { + fprintf(stderr,"Requesting a job from authority %d with blocking at %d!\n",id,blocking); + return NULL; +} + +void BANG_finished_request(BANG_job job) { + fprintf(stderr,"Finished job for authority %d!\n",job.authority); +} + +void BANG_send_job(int id, BANG_job job) { + fprintf(stderr,"Sending job to %d by authority %d!\n",id,job.authority); +} diff --git a/src/base/bang-module-api.h b/src/base/bang-module-api.h index 8d156d2..706d364 100644 --- a/src/base/bang-module-api.h +++ b/src/base/bang-module-api.h @@ -81,7 +81,7 @@ BANG_job* BANG_request_job(int id, char blocking); * \brief Sends the job to the peer. If the peer is you, * it will send it to your callback method. */ -int BANG_finished_request(BANG_job job); +void BANG_finished_request(BANG_job job); /** * \param The peer to send your the job to. @@ -103,7 +103,7 @@ typedef struct { int (*BANG_get_my_id) (); void (*BANG_assert_authority) (int id); BANG_job* (*BANG_request_job) (int id, char blocking); - int (*BANG_finished_request) (BANG_job job); + void (*BANG_finished_request) (BANG_job job); void (*BANG_send_job) (int id, BANG_job job); } BANG_api; #endif diff --git a/src/base/bang-module.c b/src/base/bang-module.c index 0e64ace..cbd60ce 100644 --- a/src/base/bang-module.c +++ b/src/base/bang-module.c @@ -41,10 +41,7 @@ static unsigned char* module_hash(char *path) { int read = UPDATE_SIZE; unsigned char *md = (unsigned char*) calloc(SHA_DIGEST_LENGTH,sizeof(unsigned char)); - /* - * This ctx creation should be done in an init - * function as it takes some time. - */ + static EVP_MD_CTX *ctx = NULL; ctx = (ctx == NULL) ? EVP_MD_CTX_create() : ctx; @@ -68,6 +65,35 @@ static unsigned char* module_hash(char *path) { return md; } +/** + * \return An api. + */ +static BANG_api get_BANG_api() { + static int completed = 0; + + static BANG_api api; + + if (!completed) { + /*If we forget to do something in this function, this will force + * the program to segfault when a module calls a function + * we were susposed to give them. */ + memset(&api,0,sizeof(BANG_api)); + + api.BANG_debug_on_all_peers = &BANG_debug_on_all_peers; + api.BANG_get_me_peers = &BANG_get_me_peers; + api.BANG_number_of_active_peers = &BANG_number_of_active_peers; + api.BANG_get_my_id = &BANG_get_my_id; + api.BANG_assert_authority = &BANG_assert_authority; + api.BANG_request_job = &BANG_request_job; + api.BANG_finished_request = &BANG_finished_request; + api.BANG_send_job = &BANG_send_job; + } + + completed = 1; + + return api; +} + BANG_module* BANG_load_module(char *path) { /* Get rid of any lingering errors. */ /* while (dlerror() != NULL) {} @@ -161,14 +187,7 @@ BANG_module* BANG_load_module(char *path) { module->handle = handle; module->path = path; - BANG_api api; - memset(&api,0,sizeof(BANG_api)); - api.BANG_debug_on_all_peers = &BANG_debug_on_all_peers; - api.BANG_get_me_peers = &BANG_get_me_peers; - api.BANG_number_of_active_peers = &BANG_number_of_active_peers; - api.BANG_get_my_id = &BANG_get_my_id; - - module->module_init(api); + module->module_init(get_BANG_api()); return module; }