ceptr
 All Data Structures Files Functions Variables Typedefs Macros Modules Pages
Virtual Machine Host Receptor

The Virtual Machine Host runs receptors and interfaces between the outside world and the cptr world. More...

Files

file  vmhost.c
 virtual machine host receptor implementation
 
file  vmhost.h
 vmhost implementation header file
 

Data Structures

struct  thread
 
struct  ActiveReceptor
 
struct  ReceptorRoute
 
struct  VMHost
 

Macros

#define SELF_RECEPTOR_ADDR   -1
 
#define MAX_ACTIVE_RECEPTORS   1000
 
#define MAX_RECEPTORS   1000
 

Typedefs

typedef struct thread thread
 
typedef struct ActiveReceptor ActiveReceptor
 
typedef struct ReceptorRoute ReceptorRoute
 
typedef struct VMHost VMHost
 

Functions

VMHost__v_init (Receptor *r, SemTable *sem)
 
VMHost_v_new ()
 Creates a new virtual machine host. More...
 
void _v_free (VMHost *r)
 
Xaddr _v_load_receptor_package (VMHost *v, T *p)
 
Xaddr _v_install_r (VMHost *v, Xaddr package, T *bindings, char *label)
 
Xaddr _v_new_receptor (VMHost *v, Receptor *parent, Symbol s, Receptor *r)
 
void _v_activate (VMHost *v, Xaddr x)
 
void _v_send (VMHost *v, ReceptorAddress from, ReceptorAddress to, Aspect aspect, Symbol carrier, T *contents)
 
void _v_send_signals (VMHost *v, T *signals)
 
void _v_deliver_signals (VMHost *v, Receptor *sender)
 
void * __v_process (void *arg)
 
void _v_instantiate_builtins (VMHost *v)
 
void _v_start_vmhost (VMHost *v)
 
void _v_start_thread (thread *t, void *(*start_routine)(void *), void *arg)
 
void _v_join_thread (thread *t)
 

Detailed Description

The Virtual Machine Host runs receptors and interfaces between the outside world and the cptr world.

Function Documentation

void* __v_process ( void *  arg)

this is the VMhost main monitoring and execution thread

Definition at line 273 of file vmhost.c.

void _v_activate ( VMHost v,
Xaddr  x 
)

Activate a receptor

Parameters
[in]vVMHost
[in]xXaddr of receptor to activate

Definition at line 172 of file vmhost.c.

void _v_deliver_signals ( VMHost v,
Receptor sender 
)
Todo:
this should probably be implemented in a scape but for now

scaffolding function for signal delivery

Definition at line 235 of file vmhost.c.

void _v_free ( VMHost v)

Destroys a vmhost freeing all memory it uses.

Parameters
[in]vthe VMHost to free

Definition at line 71 of file vmhost.c.

Xaddr _v_install_r ( VMHost v,
Xaddr  package,
T bindings,
char *  label 
)

install a receptor into vmhost, creating a symbol for it

Parameters
[in]vVMHost in which to install the receptor
[in]packagexaddr of package to install
[in]bindingscompleted manifest which specifies how the receptor will be installed
[in]labellabel to be used for the semantic name for this receptor
Returns
Xaddr of the instance

Examples (from test suite):

/* VMHost *v = _v_new(); */
/* T *p = _makeTestHTTPServerReceptorPackage(); */
/* Xaddr xp = _v_load_receptor_package(v,p); */
/* Xaddr x = _v_install_r(v,xp,0,"hello world"); */
/* // installing the receptor should instantiate a receptor from the package with the given bindings and symbol label */
/* T *r = _r_get_instance(v->r,x); */
/* spec_is_symbol_equal(v->r,x.symbol,INSTALLED_RECEPTOR); */
/* spec_is_symbol_equal(v->r,_t_symbol(_t_child(r,1)),_r_get_symbol_by_label(v->r,"hello world")); */
/* // and the definition labels of the instantiated receptor should all be set up properly */
/* Receptor *httpr = (Receptor *)_t_surface(_t_child(r,1)); */
/* spec_is_equal(_r_get_symbol_by_label(httpr,"HTTP_REQUEST"),HTTP_REQUEST); */
/* spec_is_equal(_r_get_symbol_by_label(httpr,"hellow"),-1); // hard-coded process symbol */
/* // trying to re-install the receptor should fail */
/* x = _v_install_r(v,xp,0,"hellow world"); */
/* spec_is_true(is_null_xaddr(x)); */
/* // because the receptor's id is in the installed_receptors scape */
/* T *pack = _r_get_instance(v->c,xp); */
/* T *id = _t_child(pack,2); */
/* TreeHash h = _t_hash(v->r->sem,id); */
/* spec_is_xaddr_equal(v->r->sem,_s_get(v->installed_receptors,h),xp); */
/* _v_free(v); */
Todo:
expand the manifest to allow optional binding, etc, using semtrex to do the matching instead of assuming positional matching

Definition at line 109 of file vmhost.c.

void _v_instantiate_builtins ( VMHost v)

create all the built in receptors that exist in all VMhosts

Definition at line 324 of file vmhost.c.

Xaddr _v_load_receptor_package ( VMHost v,
T p 
)

Add a receptor package into the local compository to make it available for installation and binding

Parameters
[in]vVMHost in which to install the receptor
[in]preceptor package
Returns
Xaddr of the receptor package in the compository
Todo:
validate signature and checksums??

Examples (from test suite):

/* VMHost *v = _v_new(); */
/* T *p = _makeTestHTTPAppReceptorPackage(); */
/* Xaddr x = _v_load_receptor_package(v,p); */
/* T *p1 = _r_get_instance(v->c,x); */
/* spec_is_ptr_equal(p,p1); */
/* _v_free(v); */

Definition at line 90 of file vmhost.c.

VMHost* _v_new ( )

Creates a new virtual machine host.

allocates all the memory needed in the heap

Returns
pointer to a newly allocated VMHost

Examples (from test suite):

VMHost *v = _v_new();
SemTable *sem = v->r->sem;
// test that the base contexts and defs were created
spec_is_equal(sem->contexts,_NUM_DEFAULT_CONTEXTS);
spec_is_equal(_t_children(_t_child(sem->stores[0].definitions,SEM_TYPE_SYMBOL)),NUM_SYS_SYMBOLS-1);
spec_is_equal(_t_children(_t_child(sem->stores[0].definitions,SEM_TYPE_STRUCTURE)),NUM_SYS_STRUCTURES-1);
spec_is_str_equal(t2s(v->r->root),"(RECEPTOR_INSTANCE (INSTANCE_OF:SYS_RECEPTOR) (CONTEXT_NUM:0) (PARENT_CONTEXT_NUM:-1) (RECEPTOR_STATE (FLUX (DEFAULT_ASPECT (EXPECTATIONS) (SIGNALS))) (PENDING_SIGNALS) (PENDING_RESPONSES) (CONVERSATIONS) (RECEPTOR_ELAPSED_TIME:0)))");
// test the installed receptors scape
spec_is_sem_equal(v->installed_receptors->key_source,RECEPTOR_IDENTIFIER);
spec_is_sem_equal(v->installed_receptors->data_source,RECEPTOR_SURFACE);
_v_free(v);

Definition at line 41 of file vmhost.c.

void _v_send ( VMHost v,
ReceptorAddress  from,
ReceptorAddress  to,
Aspect  aspect,
Symbol  carrier,
T contents 
)

scaffolding for send a signal from ouside the VMhost

Examples (from test suite):

/* VMHost *v = _v_new(); */
/* // create and install a stub HTTP server receptor */
/* T *httpd_rp = _makeTestHTTPServerReceptorPackage(); */
/* Xaddr httpd_px = _v_load_receptor_package(v,httpd_rp); */
/* Xaddr httpd_x = _v_install_r(v,httpd_px,0,"http server"); */
/* T *installed_httpd = _r_get_instance(v->r,httpd_x); */
/* Receptor *httpd_r = (Receptor *)_t_surface(_t_child(installed_httpd,1)); */
/* // create and install an app bound to a HOST */
/* T *p = _makeTestHTTPAppReceptorPackage(); */
/* Xaddr xp = _v_load_receptor_package(v,p); */
/* T *b = _t_new_root(BINDINGS); */
/* T *pair = _t_newr(b,BINDING_PAIR); */
/* char *host = "helloworld.com"; */
/* _t_new(pair,MANIFEST_LABEL,"host",5); */
/* _t_new(pair,HTTP_REQUEST_HOST,host,strlen(host)); */
/* Xaddr x = _v_install_r(v,xp,b,"hello world app"); */
/* T *installed_hellow = _r_get_instance(v->r,x); */
/* Receptor *hello_r = (Receptor *)_t_surface(_t_child(installed_hellow,1)); */
/* // add a listener that matches on any request with "Host: helloworld.org" */
/* // /HTTP_REQUEST/.*,HTTP_REQUEST_HOST=helloworld.org */
/* T *act = _t_newp(0,ACTION,-1); */
/* T *expect = _t_new_root(PATTERN); */
/* T *req = _t_newi(expect,SEMTREX_SYMBOL_LITERAL,HTTP_REQUEST); */
/* T *ss = _t_newi(req,SEMTREX_SEQUENCE,0); */
/* T *sss = _t_newi(ss,SEMTREX_ZERO_OR_MORE,0); */
/* _t_newi(sss,SEMTREX_SYMBOL_ANY,0); */
/* int size = sizeof(Svalue)+strlen(host)+1; */
/* Svalue *sv = malloc(size); */
/* sv->symbol = HTTP_REQUEST_HOST; */
/* sv->flags = 0; */
/* sv->count = 1; */
/* sv->length = strlen(host); */
/* strcpy((char *)&sv->value,host); */
/* _t_new(ss,SEMTREX_VALUE_LITERAL,sv,size); */
/* char buf[2000]; */
/* // just check that we got our semtrex right */
/* spec_is_str_equal(_dump_semtrex(G_sem,req,buf),"/(HTTP_REQUEST/.*,HTTP_REQUEST_HOST=helloworld.com)"); */
/* free(sv); */
/* _r_add_expectation(hello_r,DEFAULT_ASPECT,HTTP_REQUEST,expect,act,0,0,0); */
/* // build up an HTTP_REQUEST tree that corresponds with a simple get for host helloworld.com */
/* T *s = _t_new_root(HTTP_REQUEST); */
/* T *s_version = _t_newr(s,HTTP_REQUEST_VERSION); */
/* _t_newi(s_version,VERSION_MAJOR,1); */
/* _t_newi(s_version,VERSION_MINOR,1); */
/* T *s_method = _t_new(s,HTTP_REQUEST_METHOD,"GET",4); */
/* T *s_path = _t_newr(s,HTTP_REQUEST_PATH); */
/* T *s_host = _t_new(s,HTTP_REQUEST_HOST,"helloworld.com",15); */
/* // put it on the flux to simulate that it has just been parsed out of an octet stream from a TCP/IP receptor */
/* /// @todo */
/* //int path[] = {1,2,TREE_PATH_TERMINATOR}; */
/* //T *fs = _t_get(httpd_r->flux,path); */
/* //simulate that an HTTP_Request signal from the http_server receptor has been sent */
/* Xaddr xs = _v_send(v,x,httpd_x,DEFAULT_ASPECT,s); */
/* // confirm that the signal has not been delivered and is still in pending list (because receptors aren't active) */
/* spec_is_equal(_t_children(v->pending_signals),1); */
/* // activate the two receptors */
/* _v_activate(v,httpd_x); */
/* _v_activate(v,x); */
Receptor *_makeAliveProtocolReceptor(VMHost *v);

Definition at line 194 of file vmhost.c.

void _v_send_signals ( VMHost v,
T signals 
)

walk through the list of signals and send them

Definition at line 203 of file vmhost.c.