Skip to content

Commit

Permalink
registry work under way
Browse files Browse the repository at this point in the history
git-svn-id: https://subversion.cs.uiuc.edu/svn/bang/eoh2009@159 69d76c3e-0761-0410-948c-9895a8bb34fc
  • Loading branch information
nbysani2 committed Mar 12, 2009
1 parent e5a4bc3 commit a820e52
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 7 deletions.
47 changes: 44 additions & 3 deletions src/base/bang-module-registry.c
@@ -1,12 +1,46 @@
#include"bang-module.h"
#include"bang-utils.h"
#include"string.h"

static BANG_hashmap *modules = NULL;

typedef struct {
BANG_module *module;
char started;
} module_wrapper_t;

typedef struct {
char *name;
unsigned char *version;
} module_wrapper_key_t;

static unsigned int hash_module_wrapper_key_t(const void *data) {
const module_wrapper_key_t *module_key = data;

unsigned int hashcode;

hashcode = strlen(module_key->name);
hashcode |= module_key->name[hashcode/4] << 24;
hashcode |= module_key->name[hashcode/2] << 12;
hashcode |= module_key->version[0] << 4;
hashcode |= module_key->version[1] << 8;

return hashcode;
}

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) +
strcmp(mk1->name, mk2->name);
}

void BANG_new_module(char *path, char **module_name, unsigned char **module_version) {

BANG_module* new_mod = BANG_load_module(path);

*module_name = new_mod->info->module_name;
*module_version = new_mod->info->module_version;

}

BANG_module* BANG_get_module(char *module_name, unsigned char *module_version) {
Expand All @@ -29,3 +63,10 @@ void BANG_module_inform_new_peer(char *module_name, unsigned char *module_versio
new_peer = 0;
// TODO: gotta call this, but need the params - BANG_module_new_peer(const BANG_module *module, uuid_t peer, uuid_t new_peer);
}

void BANG_module_registry_init() {
modules = new_BANG_hashmap(&hash_module_wrapper_key_t,&compare_module_wrapper_key_t);
}

void BANG_module_registry_close() {
}
4 changes: 4 additions & 0 deletions src/base/bang-module-registry.h
Expand Up @@ -51,4 +51,8 @@ int BANG_start_module(char *module_name, unsigned char *module_version);
* \brief If the given module is running, tells it about the new peer.
*/
void BANG_module_inform_new_peer(char *module_name, unsigned char *module_version, uuid_t new_peer);

void BANG_module_registry_init();
void BANG_module_registry_close();

#endif
7 changes: 4 additions & 3 deletions src/base/bang-routing.c
Expand Up @@ -50,7 +50,7 @@ static int add_uuid_to_peer(const void *p, void *peer_uuid);
static int remove_uuid_from_peer(const void *p, void *r);
static void free_peer_to_uuids(void *old);
static peer_to_uuids* new_peer_to_uuids(int peer_id);
static int uuid_hashcode(const void *uuid);
static unsigned int uuid_hashcode(const void *uuid);
static int uuid_ptr_compare(const void *uuid1, const void *uuid2);
static peer_or_module *new_pom_module_route(BANG_module *module);
static peer_or_module *new_pom_peer_route(int peer_id, char *module_name, unsigned char *module_version);
Expand Down Expand Up @@ -185,10 +185,11 @@ static peer_to_uuids* new_peer_to_uuids(int peer_id) {
return new;
}

static int uuid_hashcode(const void *uuid) {
static unsigned int uuid_hashcode(const void *uuid) {
assert(uuid != NULL);

int hc = (*((uuid_t*)uuid)[0] << 2) & (*((uuid_t*)uuid)[15]);
unsigned int hc = (*((uuid_t*)uuid)[0] << 8) | (*((uuid_t*)uuid)[15]);
hc |= (*((uuid_t*)uuid)[3] << 16) | (*((uuid_t*)uuid)[7]) << 24;

return hc;
}
Expand Down
12 changes: 11 additions & 1 deletion src/base/bang-utils.h
Expand Up @@ -52,7 +52,7 @@ typedef struct {
BANG_linked_list *free_space;
} BANG_set;

typedef int (*BANG_hashcode) (const void *);
typedef unsigned int (*BANG_hashcode) (const void *);
typedef int (*BANG_compare) (const void*,const void*);

typedef struct {
Expand Down Expand Up @@ -190,8 +190,18 @@ void BANG_linked_list_enumerate(BANG_linked_list *lst, void (*it_callback) (cons
*/
int BANG_linked_list_conditional_iterate(BANG_linked_list *lst, int (*it_callback) (const void*,void*), void *data);

/**
* \brief Allocates and returns a BANG set.
*
* \return A newly intialized BANG set.
*/
BANG_set* new_BANG_set();

/**
* \param set The set to get rid of.
*
* \brief Dealloctes a BANG set.
*/
void free_BANG_set(BANG_set *set);

int BANG_set_add(BANG_set *s, void *data);
Expand Down

0 comments on commit a820e52

Please sign in to comment.