Skip to content

Commit

Permalink
More documentation and more clarifying.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikhil Samith Bysani committed Jan 17, 2009
1 parent d3630f3 commit 7d78a5b
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 38 deletions.
2 changes: 2 additions & 0 deletions Makefile
Expand Up @@ -20,6 +20,7 @@ LOBJS=bang-com$(OBJEXT) \
bang-module-api$(OBJEXT) \
bang-core$(OBJEXT) \
bang-utils$(OBJEXT) \
bang-routing$(OBJEXT)

LSRC=src/base/bang-com$(SRCEXT) \
src/base/bang-net$(SRCEXT) \
Expand All @@ -28,6 +29,7 @@ LSRC=src/base/bang-com$(SRCEXT) \
src/base/bang-module-api$(SRCEXT) \
src/base/bang-core$(SRCEXT) \
src/base/bang-utils$(SRCEXT) \
src/base/bang-routing$(SRCEXT)

AOBJS=server-preferences$(OBJEXT) \
main$(OBJEXT)
Expand Down
5 changes: 0 additions & 5 deletions src/base/bang-com.c
Expand Up @@ -198,7 +198,6 @@ static void free_peer(peer *p) {
#ifdef BDEBUG_1
fprintf(stderr,"Freeing a peer with peer_id %d.\n",p->peer_id);
#endif
int i;
pthread_cancel(p->receive_thread);

/* We need to close the receive thread in a more roundabout way, since it may be waiting
Expand Down Expand Up @@ -644,10 +643,6 @@ static peer* new_peer() {
peer *new;
new = (peer*) calloc(1,sizeof(peer));
new->requests = new_BANG_requests();
new->my_modules_len = 0;
new->remote_modules_len = 0;
pthread_mutex_init(&(new->remote_modules_lock),NULL);
pthread_mutex_init(&(new->my_modules_lock),NULL);
return new;
}

Expand Down
13 changes: 0 additions & 13 deletions src/base/bang-module-api.c
Expand Up @@ -13,22 +13,9 @@

/* TODO: Implement this. Well, this is basically what are our app is all about. */
void BANG_debug_on_all_peers(BANG_module_info *info, char *message) {
/* Might as well print it out ourself */
fprintf(stderr,message);

BANG_request request;
request.type = BANG_DEBUG_REQUEST;
request.request = message;
request.length = strlen(message) + 1;

int i = 0;
for (i = 0; i < info->peer_number; ++i) {
BANG_request_peer_id(info->peers[i],request);
}
}

void BANG_get_me_peers(BANG_module_info *info) {
BANG_request request;
}

int BANG_number_of_active_peers(BANG_module_info *info) {
Expand Down
3 changes: 2 additions & 1 deletion src/base/bang-module-api.h
Expand Up @@ -11,6 +11,7 @@
#define __BANG_MODULE_API_H

#include"bang-module-api.h"
#include<uuid/uuid.h>

/**
* Information about a module's peers. A module needs
Expand All @@ -24,7 +25,7 @@ typedef struct {
* module as their index + 1. The actual contents
* of the int is a peer_id
*/
int *peers;
uuid_t *uuids;
/**
* The number of peers that this module has.
*/
Expand Down
31 changes: 17 additions & 14 deletions src/base/bang-module.c
Expand Up @@ -7,6 +7,7 @@
*/
#include"bang-module.h"
#include"bang-com.h"
#include"bang-routing.h"
#include"bang-signals.h"
#include"bang-types.h"
#include<dlfcn.h>
Expand Down Expand Up @@ -86,15 +87,15 @@ static BANG_api* get_BANG_api() {
* the amount of memory leaked is constant and small */
api = calloc(1,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_assert_authority_to_peer = &BANG_assert_authority_to_peer;
api.BANG_request_job = &BANG_request_job;
api.BANG_finished_request = &BANG_finished_request;
api.BANG_send_job = &BANG_send_job;
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_assert_authority_to_peer = &BANG_assert_authority_to_peer;
api->BANG_request_job = &BANG_request_job;
api->BANG_finished_request = &BANG_finished_request;
api->BANG_send_job = &BANG_send_job;
}

return api;
Expand All @@ -106,11 +107,10 @@ static BANG_api* get_BANG_api() {
*
* \brief Creates a BANG_module_info for use by a module.
*/
BANG_module_info* new_BANG_module_info(BANG_module *module) {
BANG_module_info* new_BANG_module_info() {
BANG_module_info *info = calloc(1,sizeof(BANG_module_info));

/* Currently id's are not global they are relative to each other. */
info->peer_number = 0;
info->peer_number = 1;
info->my_id = 0;

return info;
Expand Down Expand Up @@ -205,14 +205,16 @@ BANG_module* BANG_load_module(char *path) {
module->path = path;

module->callbacks = module->module_init(get_BANG_api());
module->info = new_BANG_module_info();

return module;
}

void BANG_unload_module(BANG_module *module) {
if (module != NULL) {
dlclose(module->handle);
free(module->module_info);
/* TODO: This wont free it */
free(module->info);
free(module->md);
free(module);
}
Expand All @@ -225,7 +227,8 @@ void BANG_run_module(BANG_module *module) {
args.args = module;
args.length = sizeof(BANG_module);
BANG_send_signal(BANG_RUNNING_MODULE,&args,1);
module->info = new_BANG_module_info(module);

BANG_register_module_route(module);
module->module_run(module->info);
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/base/bang-module.h
Expand Up @@ -11,8 +11,6 @@
#include"bang-module-api.h"
#include"bang-types.h"

BANG_module_info* new_BANG_module_info(BANG_module *module);

/**
* \param path File path to a module that can be loaded.
*
Expand Down
6 changes: 6 additions & 0 deletions src/base/bang-routing.c
@@ -1,3 +1,9 @@
#include"bang-routing.h"
#include<stdlib.h>
#include<uuid/uuid.h>


void BANG_register_module_route(BANG_module *module) {
module->info->uuids = calloc(1,sizeof(uuid_t));
uuid_generate(module->info->uuids[0]);
}
3 changes: 2 additions & 1 deletion src/base/bang-routing.h
Expand Up @@ -9,6 +9,7 @@
#ifndef __BANG_ROUTING_H
#define __BANG_ROUTING_H
#include<uuid/uuid.h>
#include"bang-module.h"

/**
* \param uuid The module-peer to route to.
Expand All @@ -33,7 +34,7 @@ void BANG_route_job_to_uuids(uuid_t *uuids, BANG_job *job);
* \brief Registers a module at a uuid and returns that
* uuid, inserts the uuid into the module.
*/
uuid_t BANG_register_module_route(BANG_module *module);
void BANG_register_module_route(BANG_module *module);

/**
* \param uuid The uuid that the remote end will register as.
Expand Down
5 changes: 3 additions & 2 deletions src/base/bang-types.h
Expand Up @@ -25,14 +25,15 @@ typedef struct {
* 3 is a magic number ~
*/
unsigned char *module_version;
BANG_module_info *info;
/**
* Callbacks to interact with the module.
*/
BANG_callbacks callbacks;
BANG_callbacks *callbacks;
/**
* The module initialize method.
*/
BANG_callbacks (*module_init)(BANG_api);
BANG_callbacks* (*module_init)(BANG_api*);
/**
* The module run method.
*/
Expand Down

0 comments on commit 7d78a5b

Please sign in to comment.