ceptr
 All Data Structures Files Functions Variables Typedefs Macros Modules Pages
ceptr.c
Go to the documentation of this file.
1 
8 #include "ceptr.h"
9 #include "accumulator.h"
10 #include "shell.h"
11 #include "protocol.h"
12 #include <stdio.h>
13 
14 void setupHTTP(VMHost *v) {
15 
16  Symbol HTTP;
17  _sem_get_by_label(v->sem,"HTTP",&HTTP);
18 
19  // create empty edge receptor
20  Receptor *r = _r_makeStreamEdgeReceptor(v->sem);
21  // instantiate it in the vmhost
22  Xaddr edge = _v_new_receptor(v,v->r,STREAM_EDGE,r);
23  // set up a socket listener that will transcode ascii to HTTP_REQUEST and send all the received requests to an HTTP aspect on the same receptor
24  T *code = _t_parse(r->sem,0,"(CONVERSE (SCOPE (ITERATE (PARAMS) (STREAM_ALIVE (PARAM_REF:/2/1)) (INITIATE_PROTOCOL (PNAME:HTTP) (WHICH_INTERACTION:backnforth) (PROTOCOL_BINDINGS (RESOLUTION (WHICH_RECEPTOR (ROLE:HTTP_CLIENT) %)) (RESOLUTION (WHICH_RECEPTOR (ROLE:HTTP_SERVER) %)) (RESOLUTION (WHICH_PROCESS (GOAL:RESPONSE_HANDLER) (ACTUAL_PROCESS:echo2stream))) (RESOLUTION (WHICH_USAGE (USAGE:RESPONSE_HANDLER_PARAMETERS) (ACTUAL_VALUE (PARAM_REF:/2/1)))) (RESOLUTION (WHICH_VALUE (ACTUAL_SYMBOL:HTTP_REQUEST) (ACTUAL_VALUE (STREAM_READ (PARAM_REF:/2/1) (RESULT_SYMBOL:HTTP_REQUEST)))))) ) ) (STREAM_CLOSE (PARAM_REF:/2/1))) (BOOLEAN:1))",__r_make_addr(0,ACTUAL_RECEPTOR,r->addr),__r_make_addr(0,ACTUAL_RECEPTOR,r->addr));
25  // add an error handler that just completes the iteration
26  T *err_handler = _t_parse(r->sem,0,"(CONTINUE (POP_PATH (PARAM_REF:/4/1/1) (RESULT_SYMBOL:CONTINUE_LOCATION) (POP_COUNT:5)) (CONTINUE_VALUE (BOOLEAN:0)))");
27 
28  SocketListener *l = _r_addListener(r,8888,code,0,err_handler,DELIM_CRLF);
29  _v_activate(v,edge);
30 
31  T *bindings = _t_new_root(PROTOCOL_BINDINGS);
32  T *res = _t_newr(bindings,RESOLUTION);
33  T *w = _t_newr(res,WHICH_RECEPTOR);
34  _t_news(w,ROLE,HTTP_SERVER);
35  __r_make_addr(w,ACTUAL_RECEPTOR,r->addr);
36  res = _t_newr(bindings,RESOLUTION);
37  w = _t_newr(res,WHICH_PROCESS);
38  _t_news(w,GOAL,HTTP_REQUEST_HANDLER);
39  _t_news(w,ACTUAL_PROCESS,fill_i_am);
40 
41  _o_express_role(r,HTTP,HTTP_SERVER,HTTP_ASPECT,bindings);
42  _t_free(bindings);
43 }
44 
45 int main(int argc, const char **argv) {
46 
47  G_sem = def_sys();
48  //char *dname = "tmp/shell_vm";
49  //_a_boot(dname);
50 
51  debug_enable(D_SIGNALS+D_BOOT+D_STEP+D_STREAM);
52  // set up the vmhost
53  G_vm = _v_new();
55 
56  Stream *output_stream, *input_stream;
57  Receptor *i_r,*o_r;
58 
59  makeShell(G_vm,stdin,stdout,&i_r,&o_r,&input_stream,&output_stream);
60  output_stream->flags &= ~StreamCloseOnFree; // don't close the stdout on free...
61  input_stream->flags &= ~StreamCloseOnFree; // don't close the stdin on free...
62  input_stream->flags |= StreamLoadByLine; // don't wait for EOF when loading from stdin!!
63 
64  setupHTTP(G_vm);
65 
66  _v_start_vmhost(G_vm);
67 
68  while (G_vm->r->state == Alive) {
69  sleepms(100);
70  };
71 
72  _v_join_thread(&G_vm->clock_thread);
73  _v_join_thread(&G_vm->vm_thread);
74 
75  sys_free(G_sem);
76  return 0;
77 }
T * _t_new_root(Symbol symbol)
Definition: tree.c:160
Definition: ceptr_types.h:114
int state
state information about the receptor that the vmhost manages
Definition: ceptr_types.h:251
Definition: stream.h:30
command line shell receptor header files
void _v_instantiate_builtins(VMHost *v)
Definition: vmhost.c:324
protocol helpers header file
ReceptorAddress addr
the address by which to get messages to this receptor instance
Definition: ceptr_types.h:241
VMHost * _v_new()
Creates a new virtual machine host.
Definition: vmhost.c:41
void _v_activate(VMHost *v, Xaddr x)
Definition: vmhost.c:172
SemTable * sem
Semantic Table for definitions on this host.
Definition: vmhost.h:44
Definition: vmhost.h:40
SemTable * sem
pointer back to the genotype table for this receptor's vmhost instance
Definition: ceptr_types.h:242
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
T * _t_parse(SemTable *sem, T *parent, char *s,...)
Definition: tree.c:919
header file for the accumulator
void _t_free(T *t)
Definition: tree.c:526