ceptr
 All Data Structures Files Functions Variables Typedefs Macros Modules Pages
receptor.h
Go to the documentation of this file.
1 
12 #ifndef _CEPTR_RECEPTOR_H
13 #define _CEPTR_RECEPTOR_H
14 
15 #include "semtable.h"
16 #include "tree.h"
17 #include "def.h"
18 #include "label.h"
19 #include "process.h"
20 #include "scape.h"
21 
22 // delivery errors
23 enum {noDeliveryErr};
24 
25 /****************** create and destroy receptors */
26 T *__r_make_definitions();
27 T *_r_make_state();
30 T *__r_build_expectation(Symbol carrier,T *pattern,T *action,T *with,T *until,T *using,T *cid);
31 void _r_add_expectation(Receptor *r,Aspect aspect,Symbol carrier,T *pattern,T *action,T *with,T *until, T *using,T *cid);
32 void __r_add_expectation(Receptor *r,Aspect aspect,T *e);
33 void _r_remove_expectation(Receptor *r,T *expectation);
34 void _r_free(Receptor *r);
35 
36 /***************** receptor symbols, structures, and processes */
37 
38 Symbol _r_define_symbol(Receptor *r,Structure s,char *label);
40 Structure _r_define_structure(Receptor *r,char *label,int num_params,...);
41 Structure __r_define_structure(Receptor *r,char *label,T *structure_def);
43 size_t __r_get_symbol_size(Receptor *r,Symbol s,void *surface);
44 Process _r_define_process(Receptor *r,T *code,char *name,char *intention,T *signature,T *link);
45 Protocol _r_define_protocol(Receptor *r,T *p);
46 
48 int _r_def_match(Receptor *r,Symbol s,T *t);
49 
50 /***************** receptor instances and xaddrs */
51 
54 T * _r_set_instance(Receptor *r,Xaddr x,T *t);
56 TreeHash _r_hash(Receptor *r,Xaddr t);
57 
58 /****************** receptor serialization */
59 void _r_serialize(Receptor *r,void **surfaceP,size_t *lengthP);
60 Receptor * _r_unserialize(SemTable *sem,void *surface);
61 
62 /****************** receptor signaling */
63 #define __r_make_addr(p,t,a) ___r_make_addr(p,t,a,0)
64 T *___r_make_addr(T *parent,Symbol type,ReceptorAddress addr,bool is_run_node);
65 ReceptorAddress __r_get_addr(T *addr);
66 
67 T * __r_make_signal(ReceptorAddress from,ReceptorAddress to,Aspect aspect,Symbol carrier,T *signal_contents,UUIDt *in_response_to,T* until,T *conversation);
68 T* __r_send(Receptor *r,T *signal);
69 T* _r_send(Receptor *r,T *signal);
70 T* _r_request(Receptor *r,T *signal,Symbol response_carrier,T *code_point,int process_id,T *cid);
71 void evaluateEndCondition(T *ec,bool *cleanup,bool *allow);
72 void __r_test_expectation(Receptor *r,T *expectation,T *signal);
73 bool __cid_equal(SemTable *sem,T *cid1,T*cid2);
74 T *__cid_new(T *parent,UUIDt *c,T *topic);
75 UUIDt *__cid_getUUID(T *cid);
76 T * _r_add_conversation(Receptor *r,UUIDt *parent_u,UUIDt *u,T *until,T *wakeup);
77 T *_r_find_conversation(Receptor *r, UUIDt *cuuid);
78 T *__r_cleanup_conversation(Receptor *r, UUIDt *cuuid);
79 Error _r_deliver(Receptor *r, T *signal);
80 
81 /****************** internal utilities */
82 T *__r_get_aspect(Receptor *r,Aspect aspect);
83 T *__r_get_expectations(Receptor *r,Aspect aspect);
84 T *__r_get_signals(Receptor *r,Aspect aspect);
85 Receptor * __r_get_receptor(T *installed_receptor);
86 
87 /***************** Tree debugging utilities */
88 char *__td(Receptor *r,T *t,char *buf);
89 char *_td(Receptor *r,T *t);
90 char *_r_get_structure_name(Receptor *r,Structure s);
91 char *_r_get_symbol_name(Receptor *r,Symbol s);
92 char *_r_get_process_name(Receptor *r,Process p);
93 
94 Xaddr G_null_xaddr;
95 #define is_null_symbol(s) ((s).semtype == 0 && (s).context == 0 && (s).id == 0)
96 #define is_null_xaddr(x) (is_null_symbol(x.symbol) && (x).addr == 0)
97 #define is_xaddr_eq(x,y) (semeq(x.symbol,y.symbol) && (x).addr == (y).addr)
98 
99 #define spec_is_symbol_equal(r,got, expected) spec_total++; if (semeq(expected,got)){putchar('.');} else {putchar('F');sprintf(failures[spec_failures++],"%s:%d expected %s to be %s but was %s",__FUNCTION__,__LINE__,#got,_r_get_symbol_name(r,expected),_r_get_symbol_name(r,got));}
100 
101 #define spec_is_structure_equal(r,got, expected) spec_total++; if (semeq(expected,got)){putchar('.');} else {putchar('F');sprintf(failures[spec_failures++],"%s:%d expected %s to be %s but was %s",__FUNCTION__,__LINE__,#got,_r_get_structure_name(r,expected),_r_get_structure_name(r,got));}
102 
103 #define spec_is_process_equal(r,got, expected) spec_total++; if (semeq(expected,got)){putchar('.');} else {putchar('F');sprintf(failures[spec_failures++],"%s:%d expected %s to be %s but was %s",__FUNCTION__,__LINE__,#got,_r_get_process_name(r,expected),_r_get_process_name(r,got));}
104 
105 #define spec_is_xaddr_equal(sem,got,expected) spec_total++; if (is_xaddr_eq(got,expected)){putchar('.');} else {putchar('F');sprintf(failures[spec_failures++],"%s:%d expected %s to be %s.%d but was %s.%d",__FUNCTION__,__LINE__,#got,!is_null_symbol(expected.symbol)?_sem_get_name(sem,expected.symbol):"0",expected.addr,!is_null_symbol(got.symbol) ? _sem_get_name(sem,got.symbol):"0",got.addr);}
106 
107 /***************** Built-in core and edge receptors */
108 Receptor *_r_makeStreamEdgeReceptor(SemTable *sem);
109 SocketListener *_r_addListener(Receptor *r,int port,T *code,T*params,T *err_handler,char *delim);
110 void _r_addReader(Receptor *r,Stream *st,ReceptorAddress to,Aspect aspect,Symbol carrier,Symbol result_symbol,bool conversation);
111 void _r_addWriter(Receptor *r,Stream *st,Aspect aspect);
112 void _r_defineClockReceptor(SemTable *sem);
113 Receptor *_r_makeClockReceptor(SemTable *sem);
114 void *___clock_thread(void *arg);
115 #define __r_make_tick() __r_make_timestamp(TICK,00)
116 T *__r_make_timestamp(Symbol s,int delta);
117 void __r_kill(Receptor *r);
118 ReceptorAddress __r_get_self_address(Receptor *r);
119 
120 void __r_dump_instances(Receptor *r);
121 
122 #endif
123 
Definition: ceptr_types.h:114
Structure __r_get_symbol_structure(Receptor *r, Symbol s)
find a symbol's structure
Definition: receptor.c:299
void _r_serialize(Receptor *r, void **surfaceP, size_t *lengthP)
Definition: receptor.c:432
Definition: stream.h:30
header file for symbol and structure definition functions
void __r_test_expectation(Receptor *r, T *expectation, T *signal)
Definition: receptor.c:656
void _r_free(Receptor *r)
Definition: receptor.c:186
semantic trees header file
Receptor * __r_get_receptor(T *installed_receptor)
Definition: receptor.c:1039
TreeHash _r_hash(Receptor *r, Xaddr t)
Definition: receptor.c:414
Receptor * _r_new_receptor_from_package(SemTable *sem, Symbol s, T *p, T *bindings)
Creates a new receptor from a receptor package.
Definition: receptor.c:114
Structure _r_define_structure(Receptor *r, char *label, int num_params,...)
Definition: receptor.c:236
void _r_add_expectation(Receptor *r, Aspect aspect, Symbol carrier, T *pattern, T *action, T *with, T *until, T *using, T *cid)
Adds an expectation to a receptor's aspect.
Definition: receptor.c:164
Structure __r_define_structure(Receptor *r, char *label, T *structure_def)
Definition: receptor.c:258
Receptor * _r_new(SemTable *sem, SemanticID r)
Creates a new receptor.
Definition: receptor.c:88
Receptor * _r_unserialize(SemTable *sem, void *surface)
Definition: receptor.c:459
T * _r_send(Receptor *r, T *signal)
Definition: receptor.c:556
SemanticID _r_get_sem_by_label(Receptor *r, char *label)
Definition: receptor.c:288
processing header files
T * __r_make_signal(ReceptorAddress from, ReceptorAddress to, Aspect aspect, Symbol carrier, T *signal_contents, UUIDt *in_response_to, T *until, T *conversation)
Definition: receptor.c:515
T * _r_build_def_semtrex(Receptor *r, Symbol s)
Definition: receptor.c:325
scape header files
header file for table for coordinating meaning across a vmhost
size_t __r_get_symbol_size(Receptor *r, Symbol s, void *surface)
Definition: receptor.c:314
T * _r_get_instance(Receptor *r, Xaddr x)
Definition: receptor.c:379
void * ___clock_thread(void *arg)
Definition: receptor.c:1250
Label tables map human readable text strings to parts of semantic trees.
Symbol _r_define_symbol(Receptor *r, Structure s, char *label)
Definition: receptor.c:218
Error _r_deliver(Receptor *r, T *signal)
Definition: receptor.c:954
T * _r_set_instance(Receptor *r, Xaddr x, T *t)
Definition: receptor.c:394
Process _r_define_process(Receptor *r, T *code, char *name, char *intention, T *signature, T *link)
Definition: receptor.c:275
T * _r_delete_instance(Receptor *r, Xaddr x)
Definition: receptor.c:407
T * _r_request(Receptor *r, T *signal, Symbol response_carrier, T *code_point, int process_id, T *cid)
Definition: receptor.c:575
int _r_def_match(Receptor *r, Symbol s, T *t)
Definition: receptor.c:343
Xaddr _r_new_instance(Receptor *r, T *t)
Definition: receptor.c:365