Skip to content

Commit

Permalink
Wrote some stub functions in the module-api.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikhil Samith Bysani committed Jan 12, 2009
1 parent 58eedcd commit 707f6cf
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 15 deletions.
19 changes: 18 additions & 1 deletion src/base/bang-module-api.c
Expand Up @@ -9,7 +9,7 @@
#include<stdio.h>
#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);
}
Expand All @@ -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);
}
4 changes: 2 additions & 2 deletions src/base/bang-module-api.h
Expand Up @@ -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.
Expand All @@ -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
43 changes: 31 additions & 12 deletions src/base/bang-module.c
Expand Up @@ -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;

Expand All @@ -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) {}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 707f6cf

Please sign in to comment.