ceptr
 All Data Structures Files Functions Variables Typedefs Macros Modules Pages
group_spec.h
Go to the documentation of this file.
1 
7 #include "../src/group.h"
8 
9 void testGroupCreate() {
10  Receptor *r = makeGroup(G_vm,"ceptr chat");
11  Receptor *m = _r_new(G_sem,TEST_RECEPTOR);
12  Xaddr mx = _v_new_receptor(G_vm,G_vm->r,TEST_RECEPTOR,m);
13  _v_activate(G_vm,mx);
14 
15  spec_is_str_equal(_td(r,_t_child(r->root,1)),"(INSTANCE_OF:ceptr chat)");
16  spec_is_str_equal(_td(r,r->flux),"(FLUX (DEFAULT_ASPECT (EXPECTATIONS (EXPECTATION (CARRIER:enrollment) (PATTERN (SEMTREX_SYMBOL_ANY)) (ACTION:enroll) (PARAMS) (END_CONDITIONS (UNLIMITED))) (EXPECTATION (CARRIER:converse) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:MESSAGE_TEXT))) (ACTION:group_listen) (PARAMS (SLOT (USAGE:NULL_SYMBOL))) (END_CONDITIONS (UNLIMITED)))) (SIGNALS)))");
17 
18  // bindings for m to request membership
19  T *bindings = _t_new_root(PROTOCOL_BINDINGS);
20  T *res = _t_newr(bindings,RESOLUTION);
21  T *w = _t_newr(res,WHICH_RECEPTOR);
22  _t_news(w,ROLE,GROUP);
23  __r_make_addr(w,ACTUAL_RECEPTOR,r->addr);
24  res = _t_newr(bindings,RESOLUTION);
25  w = _t_newr(res,WHICH_RECEPTOR);
26  _t_news(w,ROLE,MEMBER);
27  __r_make_addr(w,ACTUAL_RECEPTOR,m->addr);
28 
29  // @todo bleah, this should be a better proc, at least with a SIGNAL_REF
30  // or something.
31  T *noop = _t_new_root(NOOP);
32  _t_newi(noop,TEST_INT_SYMBOL,314);
33  Process proc = _r_define_process(m,noop,"do nothing","long desc...",NULL,NULL);
34 
35  T *bindings2 = _t_build(G_sem,0,PROTOCOL_BINDINGS,RESOLUTION,WHICH_PROCESS,GOAL,HANDLER,ACTUAL_PROCESS,proc,NULL_SYMBOL,NULL_SYMBOL,NULL_SYMBOL);
36 
37  _o_express_role(m,group1,MEMBER,DEFAULT_ASPECT,bindings2);
38  _t_free(bindings2);
39  _o_initiate(m,group1,enrollment,bindings);
40 
41  _p_reduceq(m->q);
42  _v_deliver_signals(G_vm,m);
43  _p_reduceq(r->q);
44 
45  // see that member got added to the group
46  spec_is_str_equal(_td(r,_t_child(__r_get_signals(r,DEFAULT_ASPECT),1)),"(SIGNAL (ENVELOPE (FROM_ADDRESS (RECEPTOR_ADDR:4)) (TO_ADDRESS (RECEPTOR_ADDR:3)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:enrollment) (SIGNAL_UUID)) (BODY:{(YUP)}) (RUN_TREE (WHICH_XADDR:MEMBER.1) (PARAMS)))");
47 
48  T *t = _t_new_root(ITERATION_DATA);
49  _a_get_instances(&r->instances,MEMBER,t);
50  spec_is_str_equal(t2s(t),"(ITERATION_DATA (MEMBER (RECEPTOR_ADDR:4)))");
51  _t_free(t);
52 
53  res = _t_newr(bindings,RESOLUTION);
54  w = _t_newr(res,WHICH_VALUE);
55  _t_news(w,USAGE,MESSAGE_TEXT);
56  T *val = _t_newr(w,ACTUAL_VALUE);
57  val = _t_new_str(val,MESSAGE_TEXT,"hi there!");
58 
59 
60  //debug_enable(D_PROTOCOL+D_SIGNALS+D_TREE);
61  _o_initiate(m,group1,converse,bindings);
62  /* _test_reduce_signals(r); */
63  _p_reduceq(m->q);
64  _v_deliver_signals(G_vm,m);
65  _p_reduceq(r->q);
66  _v_deliver_signals(G_vm,r);
67  _p_reduceq(m->q);
68 
69  spec_is_str_equal(_td(r,_t_child(__r_get_signals(r,DEFAULT_ASPECT),2)),"(SIGNAL (ENVELOPE (FROM_ADDRESS (RECEPTOR_ADDR:4)) (TO_ADDRESS (RECEPTOR_ADDR:3)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:converse) (SIGNAL_UUID)) (BODY:{(MESSAGE_TEXT:hi there!)}) (RUN_TREE (SIGNAL_UUID) (PARAMS (MESSAGE_TEXT:hi there!))))");
70 
71  t = _t_new_root(ITERATION_DATA);
72  _a_get_instances(&r->instances,MESSAGE_TEXT,t);
73  spec_is_str_equal(t2s(t),"(ITERATION_DATA (MESSAGE_TEXT:hi there!))");
74  _t_free(t);
75 
76  t = _t_new_root(ITERATION_DATA);
77  _a_get_instances(&r->instances,MEMBER,t);
78  spec_is_str_equal(t2s(t),"(ITERATION_DATA (MEMBER (RECEPTOR_ADDR:4)))");
79  _t_free(t);
80 
81  spec_is_str_equal(_td(m,_t_child(__r_get_signals(m,DEFAULT_ASPECT),1)),"(SIGNAL (ENVELOPE (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:4)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:converse) (SIGNAL_UUID)) (BODY:{(MESSAGE_TEXT:hi there!)}) (RUN_TREE (TEST_INT_SYMBOL:314) (PARAMS)))");
82  debug_disable(D_PROTOCOL+D_SIGNALS);
83 
84  _t_free(bindings);
85  // @todo find bug that causes _r_free to freak out, seems like a loop in the tree
86  // _r_free(r);
87  // _r_free(m);
88 }
89 
90 void testGroup() {
91  G_vm = _v_new();
92  testGroupCreate();
93  _v_free(G_vm);
94 }
T * _t_new_root(Symbol symbol)
Definition: tree.c:160
Definition: ceptr_types.h:114
Error _p_reduceq(Q *q)
Definition: process.c:2126
T * _t_child(T *t, int i)
Definition: tree.c:1251
void _v_free(VMHost *v)
Definition: vmhost.c:71
ReceptorAddress addr
the address by which to get messages to this receptor instance
Definition: ceptr_types.h:241
Instances instances
the instances store
Definition: ceptr_types.h:249
VMHost * _v_new()
Creates a new virtual machine host.
Definition: vmhost.c:41
Q * q
process queue
Definition: ceptr_types.h:250
T * flux
pointer for quick access to the flux
Definition: ceptr_types.h:243
void _v_activate(VMHost *v, Xaddr x)
Definition: vmhost.c:172
Receptor * _r_new(SemTable *sem, SemanticID r)
Creates a new receptor.
Definition: receptor.c:88
void _o_initiate(Receptor *r, SemanticID protocol, SemanticID interaction, T *bindings)
Definition: protocol.c:506
T * root
RECEPTOR_INSTANCE semantic tree.
Definition: ceptr_types.h:238
void _o_express_role(Receptor *r, Protocol protocol, Symbol role, Aspect aspect, T *bindings)
Definition: protocol.c:409
Receptor * r
Receptor data for this vm host.
Definition: vmhost.h:43
void _v_deliver_signals(VMHost *v, Receptor *sender)
Definition: vmhost.c:235
Process _r_define_process(Receptor *r, T *code, char *name, char *intention, T *signature, T *link)
Definition: receptor.c:275
void _t_free(T *t)
Definition: tree.c:526
T * _t_build(SemTable *sem, T *parent,...)
Definition: tree.c:635