From 4468c11d8b18a2369c9132235ff966f2322bffbc Mon Sep 17 00:00:00 2001 From: user Date: Fri, 20 Mar 2009 12:51:55 +0000 Subject: [PATCH] more test and api stuff --- src/drivers/op/uri2chan.c | 2 +- src/drivers/ot/test/teston.c | 98 ++++++++++++++++++++++++++++++++---------- src/include/notification.h | 24 +++++++++-- src/on/notification.c | 21 ++++++++- 4 files changed, 118 insertions(+), 27 deletions(-) diff --git a/src/drivers/op/uri2chan.c b/src/drivers/op/uri2chan.c index 8586433..6162532 100644 --- a/src/drivers/op/uri2chan.c +++ b/src/drivers/op/uri2chan.c @@ -43,7 +43,7 @@ void init_uri2chan(void) is_np=!strcmp(k_ciux, "op"); if(is_np) listen_nexus(); if(root_nexus()){ - k_log_out("root nexus - but listening on http"); + /* k_log_out("root nexus - but listening on http"); */ listen_http(); } else{ diff --git a/src/drivers/ot/test/teston.c b/src/drivers/ot/test/teston.c index 583f3b3..9379891 100644 --- a/src/drivers/ot/test/teston.c +++ b/src/drivers/ot/test/teston.c @@ -6,11 +6,18 @@ /* -------------------------------------------------------------------------- */ -static int handles_resource(char* name); -static void sync_resource(ni_resource* res); +static int handles_object(char* uid); +static void view_event(n_object* o, n_object* v); +static void cast_event(n_object* o, n_object* c); +static void sync_object(n_object* o); static void start_tests(void); -static void running_tests(ni_event* evt); +static void view_event_1(n_object* o, n_object* v); +static void view_event_2(n_object* o, n_object* v); +static void view_event_3(n_object* o, n_object* v); +static void cast_event_1(n_object* o, n_object* c); +static void cast_event_2(n_object* o, n_object* c); +static void cast_event_3(n_object* o, n_object* c); static void test_state(n_object* o, char* os, char* uid, char* cont); @@ -18,7 +25,7 @@ static void test_state(n_object* o, char* os, char* uid, char* cont); EXPORT int teston_module_loaded(void) { - ni_register_driver("teston", handles_resource, sync_resource); + n_register_driver("teston", handles_object, view_event, cast_event, sync_object); k_log_out("Test ON Driver initialised"); @@ -29,11 +36,7 @@ EXPORT int teston_module_loaded(void) EXPORT int teston_module_event(void* data) { - ni_event* evt=data; - - running_tests(evt); - - ni_event_delete(evt); + n_dispatch((n_event*)data); return 1; } @@ -44,25 +47,43 @@ EXPORT int teston_module_tick(void) /* -------------------------------------------------------------------------- */ -int handles_resource(char* name) +int handles_object(char* uid) { return 1; } -void sync_resource(ni_resource* res) +void sync_object(n_object* o) +{ +} + +/* -------------------------------------------------------------------------- */ + +void view_event(n_object* o, n_object* v) +{ + if(n_uid_is(o, "11111-4141a")) view_event_1(o,v); + if(n_uid_is(o, "22222-ef990")) view_event_2(o,v); + if(n_uid_is(o, "33333-18bbc")) view_event_3(o,v); + k_assert(0, "No match to UID in view_event"); +} + +void cast_event(n_object* o, n_object* c) { + if(n_uid_is(o, "11111-4141a")) cast_event_1(o,c); + if(n_uid_is(o, "22222-ef990")) cast_event_2(o,c); + if(n_uid_is(o, "33333-18bbc")) cast_event_3(o,c); + k_assert(0, "No match to UID in cast_event"); } /* -------------------------------------------------------------------------- */ /* - 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 + - object.view - may return empty so wait for .. + - viewstate(object) - state asked for /or/ object is subscribing */ void start_tests(void) { - k_log_out("Creating o11111"); + k_log_out("Creating o11111 ------------------"); char* o11111s = "UID: 11111-4141a\n" "\n" @@ -76,7 +97,7 @@ void start_tests(void) n_commit(o11111); - k_log_out("Creating o22222"); + k_log_out("Creating o22222 ------------------"); char* o22222s = "UID: 22222-ef990\n" "\n" @@ -86,24 +107,54 @@ void start_tests(void) test_state(o22222, o22222s, "22222-ef990", "is two content"); - n_object* o2 = n_see(o11111, "22222-ef990"); + k_log_out("o11111 views o22222 ------------------"); - k_assert(!o2, "Object 2 has not been committed yet, but Object 1 can see it:\n%s\n", n_to_string(o2)); + n_object* o2 = n_view(o11111, "22222-ef990"); + + k_assert(!o2, "Object 2 has not been committed yet, but Object 1 can view it:\n%s\n", n_to_string(o2)); n_commit(o22222); - o2 = n_see(o11111, "22222-ef990"); + o2 = n_view(o11111, "22222-ef990"); - k_assert(o2!=0, "Object 2 has been committed, but can't be seen by Object 1"); + k_assert(o2!=0, "Object 2 has been committed, but can't be viewed by Object 1"); test_state(o2, o22222s, "22222-ef990", "is two content"); - n_object* o3 = n_see(o22222, "33333-18bbc"); + k_log_out("o22222 views o33333 ------------------"); + + n_object* o3 = n_view(o22222, "33333-18bbc"); + + k_assert(!o3, "Object 3 has not been created yet, but Object 2 can view it:\n%s", n_to_string(o3)); +} + +/* -------------------------------------------------------------------------- */ + +void view_event_1(n_object* o, n_object* v) +{ +} + +/* 2 -> 1 */ +void cast_event_1(n_object* o, n_object* c) +{ +} + +/* -------------------------------------------------------------------------- */ + +/* 1 -> 2 []; 1 -> 2 [*] */ +void view_event_2(n_object* o, n_object* v) +{ +} - k_assert(!o3, "Object 3 has not been created yet, but Object 2 can see it:\n%s", n_to_string(o3)); +/* 3 -> 2 */ +void cast_event_2(n_object* o, n_object* c) +{ } -void running_tests(ni_event* evt) +/* -------------------------------------------------------------------------- */ + +/* 2 -> 3 [] */ +void view_event_3(n_object* o, n_object* v) { char* o33333s = "UID: 33333-18bbc\n" @@ -113,7 +164,10 @@ void running_tests(ni_event* evt) n_object* o33333 = n_object_new(o33333s); n_commit(o33333); +} +void cast_event_3(n_object* o, n_object* c) +{ } /* -------------------------------------------------------------------------- */ diff --git a/src/include/notification.h b/src/include/notification.h index 7916190..14a3030 100644 --- a/src/include/notification.h +++ b/src/include/notification.h @@ -5,18 +5,36 @@ /* -------------------------------------------------------------------------- */ typedef struct n_object{ - k_hashtable* headers; - k_hashtable* content; + k_hashtable* headers; + k_hashtable* content; } n_object; +typedef struct n_event { + n_object* from; + n_object* to; +} n_event; + +typedef int (*n_handles_object)(char*); +typedef void (*n_view_event)(n_object*, n_object*); +typedef void (*n_cast_event)(n_object*, n_object*); +typedef void (*n_sync_object)(n_object*); + +PUBLIC void n_register_driver(char* name, + n_handles_object handles_object, + n_view_event view_event, + n_cast_event cast_event, + n_sync_object sync_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 n_object* n_view(n_object* o, char* uid); PUBLIC char* n_to_string(n_object* o); PUBLIC char* n_uid(n_object* o); +PUBLIC int n_uid_is(n_object* o, char* uid); 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 void n_dispatch(n_event*); /* -------------------------------------------------------------------------- */ diff --git a/src/on/notification.c b/src/on/notification.c index 970b1cb..3833a08 100644 --- a/src/on/notification.c +++ b/src/on/notification.c @@ -8,6 +8,14 @@ /* -}{---- ------------------------------------------------------------------ */ +EXPORT void n_register_driver(char* name, + n_handles_object handles_object, + n_view_event view_event, + n_cast_event cast_event, + n_sync_object sync_object ) +{ +} + EXPORT n_object* n_object_new(char* s) { return 0; @@ -17,7 +25,7 @@ EXPORT void n_commit(n_object* o) { } -EXPORT n_object* n_see(n_object* o, char* uid) +EXPORT n_object* n_view(n_object* o, char* uid) { return 0; } @@ -32,6 +40,11 @@ EXPORT char* n_uid(n_object* o) return 0; } +EXPORT int n_uid_is(n_object* o, char* uid) +{ + return 0; +} + EXPORT char* n_header(n_object* o, char* name) { return 0; @@ -47,6 +60,12 @@ EXPORT k_hashtable* n_content(n_object* o) return 0; } +EXPORT void n_dispatch(n_event* event) +{ + /* one callback per view or cast */ + /* must delete the event */ +} + /* -}{---- ------------------------------------------------------------------ */ #define TMPBUFSIZE 4096 -- 1.7.9.5