From: user Date: Thu, 19 Mar 2009 17:12:28 +0000 (+0000) Subject: first cut of Object Notification API and tests X-Git-Url: https://vcs.maemo.org/git/?p=cilux;a=commitdiff_plain;h=f9280086a261a27b286001ea0fd419de750a57c2 first cut of Object Notification API and tests --- diff --git a/src/drivers/nt/test/testni.c b/src/drivers/nt/test/testni.c index 0b059fa..87e3709 100644 --- a/src/drivers/nt/test/testni.c +++ b/src/drivers/nt/test/testni.c @@ -9,6 +9,11 @@ static int handles_resource(char* name); static void sync_resource(ni_resource* res); +static void start_tests(void); +static void running_tests(ni_event* evt); + +static void test_state(n_object* o, char* os, char* uid, char* cont); + /* -------------------------------------------------------------------------- */ EXPORT int testni_module_loaded(void) @@ -17,13 +22,17 @@ EXPORT int testni_module_loaded(void) k_log_out("Test NI Driver initialised"); + start_tests(); + return 1; } EXPORT int testni_module_event(void* data) { - k_log_out("Test NI got event: %p", data); ni_event* evt=data; + + running_tests(evt); + ni_event_delete(evt); return 1; } @@ -46,6 +55,95 @@ void sync_resource(ni_resource* res) /* -------------------------------------------------------------------------- */ - +/* + - object.create .update .commit .rollback (auto inc version #?) + - object.see - may return empty so wait for .. + - seestate(object) - state asked for /or/ object is subscribing + */ +void start_tests(void) +{ + k_log_out("Creating o11111"); + + char* o11111s = "UID: 11111-4141a\n" + "\n" + "This: is one content\n"; + + n_object* o11111 = n_object_new(o11111s); + + test_state(o11111, o11111s, "11111-4141a", "is one content"); + + k_log_out("Committing o11111"); + + n_commit(o11111); + + k_log_out("Creating o22222"); + + char* o22222s = "UID: 22222-ef990\n" + "\n" + "This: is two content\n"; + + n_object* o22222 = n_object_new(o22222s); + + test_state(o22222, o22222s, "22222-ef990", "is two content"); + + n_object* o2 = n_see(o11111, "22222-ef990"); + + k_assert(!o2, "Object 2 has not been committed yet, but Object 1 can see it:\n%s\n", n_to_string(o2)); + + n_commit(o22222); + + o2 = n_see(o11111, "22222-ef990"); + + k_assert(o2!=0, "Object 2 has been committed, but can't be seen by Object 1"); + + test_state(o2, o22222s, "22222-ef990", "is two content"); + + n_object* o3 = n_see(o22222, "33333-18bbc"); + + k_assert(!o3, "Object 3 has not been created yet, but Object 2 can see it:\n%s", n_to_string(o3)); +} + +void running_tests(ni_event* evt) +{ + char* o33333s = + "UID: 33333-18bbc\n" + "\n" + "This: is three content\n"; + + n_object* o33333 = n_object_new(o33333s); + + n_commit(o33333); + +} + +/* -------------------------------------------------------------------------- */ + +void test_state(n_object* o, char* os, char* uid, char* cont) +{ + char* c; + + k_log_out("Checking %s", uid); + + c=n_to_string(o); + k_assert(c && !strcmp(c, os), "To-string was\n%s", c? c: "null"); + + c=n_uid(o); + k_assert(c && !strcmp(c, uid), "UID was %s in n_uid", c? c: "null"); + + c=n_header(o, "UID"); + k_assert(c && !strcmp(c, uid), "UID was %s in n_header", c? c: "null"); + + c=k_hashtable_get(n_headers(o), "UID"); + k_assert(c && !strcmp(c, uid), "UID was %s in hash get", c? c: "null"); + + c=k_hashtable_get(n_content(o), "This"); + k_assert(c && !strcmp(c, cont), "Content was %s", c? c: "null"); + + c=n_to_string(o); + k_assert(c && !strcmp(c, os), "To-string was\n%s", c? c: "null"); +} + +/* -------------------------------------------------------------------------- */ + diff --git a/src/include/kernelapi.h b/src/include/kernelapi.h index deb9e79..d16a506 100644 --- a/src/include/kernelapi.h +++ b/src/include/kernelapi.h @@ -209,6 +209,7 @@ PUBLIC void k_free(void* o); PUBLIC void k_log_out(char* format, ...); PUBLIC void k_log_err(char* format, ...); +PUBLIC void k_assert( int t, char* format, ...); PUBLIC void k_fatal( char* format, ...); /* -------------------------------------------------------------------------- */ diff --git a/src/include/ni.h b/src/include/ni.h index 32c90b2..7916190 100644 --- a/src/include/ni.h +++ b/src/include/ni.h @@ -4,6 +4,22 @@ /* -------------------------------------------------------------------------- */ +typedef struct n_object{ + k_hashtable* headers; + k_hashtable* content; +} n_object; + +PUBLIC n_object* n_object_new(char* s); +PUBLIC void n_commit(n_object* o); +PUBLIC n_object* n_see(n_object* o, char* uid); +PUBLIC char* n_to_string(n_object* o); +PUBLIC char* n_uid(n_object* o); +PUBLIC char* n_header(n_object* o, char* name); +PUBLIC k_hashtable* n_headers(n_object* o); +PUBLIC k_hashtable* n_content(n_object* o); + +/* -------------------------------------------------------------------------- */ + PUBLIC char* ni_hostname(void); PUBLIC void ni_hostname_set(char* name); @@ -66,7 +82,7 @@ PUBLIC void ni_response(ni_event* evt, char* protocol, char* connection, k_channel* chan); -EXPORT void ni_request(ni_event* evt, +PUBLIC void ni_request(ni_event* evt, char* to, char* method, k_channel* chan); diff --git a/src/ni/ni.c b/src/ni/ni.c index f0ccc5f..fae4db1 100644 --- a/src/ni/ni.c +++ b/src/ni/ni.c @@ -8,6 +8,47 @@ /* -}{---- ------------------------------------------------------------------ */ +EXPORT n_object* n_object_new(char* s) +{ + return 0; +} + +EXPORT void n_commit(n_object* o) +{ +} + +EXPORT n_object* n_see(n_object* o, char* uid) +{ + return 0; +} + +EXPORT char* n_to_string(n_object* o) +{ + return 0; +} + +EXPORT char* n_uid(n_object* o) +{ + return 0; +} + +EXPORT char* n_header(n_object* o, char* name) +{ + return 0; +} + +EXPORT k_hashtable* n_headers(n_object* o) +{ + return 0; +} + +EXPORT k_hashtable* n_content(n_object* o) +{ + return 0; +} + +/* -}{---- ------------------------------------------------------------------ */ + #define TMPBUFSIZE 4096 static char tmpbuf[TMPBUFSIZE]; static char* hostname; @@ -629,7 +670,7 @@ EXPORT void ni_register_driver(char* name, { ni_driver* d=ni_driver_new(name, handles_resource, sync_resource); if(!strcmp(name, "np")) npdriver=d; - else moddriver=d; + else moddriver=d; } /* -}{---- ------------------------------------------------------------------ */ diff --git a/src/platform/kernelapi.c b/src/platform/kernelapi.c index 993808e..e8e2854 100644 --- a/src/platform/kernelapi.c +++ b/src/platform/kernelapi.c @@ -1462,7 +1462,7 @@ EXPORT void k_log_err(char* format, ...) va_list ap; va_start(ap, format); if(LOG_TO_STD){ - VPRINTFERR(format,ap); + VPRINTFERR(format, ap); PRINTFERR("\n"); FFLUSH(stderr); } @@ -1475,14 +1475,47 @@ EXPORT void k_log_err(char* format, ...) va_end(ap); } +EXPORT void k_assert(int t, char* format, ...) +{ + va_list ap; + va_start(ap, format); + if(!t){ + if(LOG_TO_STD){ + VPRINTFERR(format, ap); + PRINTFERR("\n"); + FFLUSH(stderr); + } + else{ + vsnprintf(logbuf, LOGBUFSIZE,format,ap); + *(logbuf+LOGBUFSIZE-2)='\n'; + *(logbuf+LOGBUFSIZE-1)=0; + write_to_logfile_cern_style(logbuf,1); + } + k_log_err("Terminating Cilux"); + k_log_err("---------------------"); + EXIT(-1); + } + va_end(ap); +} + EXPORT void k_fatal(char* format, ...) { va_list ap; va_start(ap, format); - k_log_out(format, ap); + if(LOG_TO_STD){ + VPRINTFERR(format, ap); + PRINTFERR("\n"); + FFLUSH(stderr); + } + else{ + vsnprintf(logbuf, LOGBUFSIZE,format,ap); + *(logbuf+LOGBUFSIZE-2)='\n'; + *(logbuf+LOGBUFSIZE-1)=0; + write_to_logfile_cern_style(logbuf,1); + } va_end(ap); - k_log_out("Terminating Cilux"); - k_log_out("---------------------"); + k_log_err("Terminating Cilux"); + k_log_err("---------------------"); EXIT(1); } diff --git a/src/platform/linux/kernelplat.c b/src/platform/linux/kernelplat.c index 96b92e3..605eb2d 100644 --- a/src/platform/linux/kernelplat.c +++ b/src/platform/linux/kernelplat.c @@ -1,18 +1,6 @@ /* -------------------------------------------------------------------------- */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* -------------------------------------------------------------------------- */ - static fd_set rd_fd_set; static fd_set wr_fd_set; static fd_set ex_fd_set; diff --git a/src/platform/linux/kernelplat.h b/src/platform/linux/kernelplat.h index dd06f41..aedb741 100644 --- a/src/platform/linux/kernelplat.h +++ b/src/platform/linux/kernelplat.h @@ -3,6 +3,15 @@ #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include