Skip to content

Commit

Permalink
Made sqlite3 the way to track routes, modified the makefile to
Browse files Browse the repository at this point in the history
accomadate.
  • Loading branch information
Nikhil Samith Bysani committed Jan 18, 2009
1 parent 863a596 commit c0e9e91
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
3 changes: 1 addition & 2 deletions Makefile
Expand Up @@ -11,8 +11,7 @@ SRCEXT=.c

COPTS=-Wall -Wextra -Werror -O3 -g -D_REENTRANT -lpthread

GTKOPTS=`pkg-config --cflags --libs gtk+-2.0 --libs openssl ` -lgthread-2.0

GTKOPTS=`pkg-config --cflags --libs gtk+-2.0 --libs openssl --libs uuid --libs sqlite3 --libs gthread-2.0`
LOBJS=bang-com$(OBJEXT) \
bang-net$(OBJEXT) \
bang-signals$(OBJEXT) \
Expand Down
3 changes: 3 additions & 0 deletions src/base/bang-core.c
Expand Up @@ -9,6 +9,7 @@
#include"bang-core.h"
#include"bang-net.h"
#include"bang-com.h"
#include"bang-routing.h"
#include"bang-signals.h"
#include<stdlib.h>
#include<stdio.h>
Expand Down Expand Up @@ -44,12 +45,14 @@ void BANG_init(int *argc, char **argv) {
BANG_sig_init();
BANG_com_init();
BANG_net_init(set_port,0);
BANG_route_init();
}

void BANG_close() {
#ifdef BDEBUG_1
fprintf(stderr,"BANG library closing.\n");
#endif
BANG_route_close();
BANG_com_close();
BANG_net_close();
BANG_sig_close();
Expand Down
29 changes: 28 additions & 1 deletion src/base/bang-routing.c
@@ -1,7 +1,14 @@
#include"bang-routing.h"
#include<stdlib.h>
/* I am really reeling in those external libraries! */
#include<sqlite3.h>
#include<uuid/uuid.h>

#define DB_CREATE_STR "CREATE TABLE mappings(route_uuid blob unique primary key, remote integer, id integer, callbacks blob, name text, version text)"
#define REMOTE_ROUTE 2
#define LOCAL_ROUTE 1

static sqlite3 *db;

void BANG_register_module_route(BANG_module *module) {

Expand All @@ -12,5 +19,25 @@ void BANG_register_module_route(BANG_module *module) {
module->info->peers_info->peer_number = 1;
module->info->peers_info->validity[module->info->my_id] = 1;

/* TODO: Use locks, register to some global variable */
sqlite3_stmt *insert_module;
sqlite3_prepare_v2(db,"INSERT INTO mappings (route_uuid,remote,callbacks,name,text) VALUES (?,1,?,?,?)",73,&insert_module,NULL);
sqlite3_bind_blob(insert_module,1,module->info->peers_info->uuids[module->info->my_id],sizeof(uuid_t),SQLITE_STATIC);
}

void BANG_route_init() {
#ifdef BDEBUG_1
fprintf(stderr,"BANG route initializing.\n");
#endif
sqlite3_close(db);
}

void BANG_route_close() {
#ifdef BDEBUG_1
fprintf(stderr,"BANG route closing.\n");
#endif
sqlite3_open_v2(":memory",&db,SQLITE_OPEN_READWRITE | SQLITE_OPEN_FULLMUTEX,NULL);
/*TODO: check for errors.
* Create database.
*/
sqlite3_exec(db,DB_CREATE_STR,NULL,NULL,NULL);
}
4 changes: 4 additions & 0 deletions src/base/bang-routing.h
Expand Up @@ -94,4 +94,8 @@ void BANG_register_module_route(BANG_module *module);
* \brief Registers a remote module route.
*/
void BANG_register_peer_route(uuid_t uuid, int peer, char *module_name, char* module_version);

void BANG_route_init();

void BANG_route_close();
#endif

0 comments on commit c0e9e91

Please sign in to comment.