/* -------------------------------------------------------------------------- */
-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);
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");
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;
}
/* -------------------------------------------------------------------------- */
-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"
n_commit(o11111);
- k_log_out("Creating o22222");
+ k_log_out("Creating o22222 ------------------");
char* o22222s = "UID: 22222-ef990\n"
"\n"
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"
n_object* o33333 = n_object_new(o33333s);
n_commit(o33333);
+}
+void cast_event_3(n_object* o, n_object* c)
+{
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
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*);
/* -------------------------------------------------------------------------- */