Пример #1
0
static
void wildcard_router_receive(receiver_t* self,
			     bytecode_stream_t* message, context_t* context)
{
    router_t* router = (router_t*) self;
    bytecode_t* selector = message->pop(message);

    if(selector && selector->verb == route_atom) {
	bytecode_t* destination = message->pop(message);

	if(!destination) {
	    WARNING1("no destination provided.");
	    return;
	} else {
	    atom_t dest = destination->verb;

	    TRACE2("routing towards selector '%s' requested.", atom_get_cstring_value(dest));
	    if(dest == star_atom) {
		map_iterator_t i; 
		map_value_t pslot = NULL_MAP_VALUE;
		
		map_get_iterator(&router->children, &i);
		
		while (map_value_is_there (pslot = map_iterator_next(&i))) {
		    router_slot_t* slot = map_value_obtain (pslot);
		    // clone each message
		    bytecode_stream_t* message_copy = bytecode_stream_instantiate_toplevel(NULL);
		    message_copy->copy(message_copy, message);

		    TRACE2("sending event to slot: '%s'", 
			   atom_get_cstring_value(slot->name));
		    if(!router_route(slot, message_copy, context)) {
			WARNING2("route '%s' not defined.", 
				 atom_get_cstring_value(slot->name));
		    }
		}
		map_iterator_destroy (&i);
		map_iterator_retire (&i);

		bytecode_stream_retire (message);
	    } else {
		if(!router_route(get_slot(router, dest), message, context)) {
		    WARNING2("route '%s' not defined.", 
			     atom_get_cstring_value(dest));
		}
	    }
	}
    } else {
	message->push(message, selector);
	router->receive_backup(self, message, context);
    }
}
Пример #2
0
static void receiver_eval_all_pending(receiver_t *self, context_t *context)
{
    map_iterator_t it;
    map_value_t pfifo;

    map_get_iterator(&self->fifos, &it);
    while (map_value_is_there(pfifo = map_iterator_next(&it))) {
        message_fifo_t *fifo = map_value_obtain(pfifo);
        self->eval_pending(self, fifo->atom, context);
    }
    map_iterator_destroy(&it);
    map_iterator_retire(&it);
}
Пример #3
0
static message_node_t *receiver_peek_any_pending(receiver_t *self,
                                                 context_t *context)
{
    map_iterator_t it;
    message_node_t *head = NULL;
    map_value_t pfifo;

    /* find first occurence of next event in any fifo */
    map_get_iterator(&self->fifos, &it);
    while (map_value_is_there(pfifo = map_iterator_next(&it))) {
        message_fifo_t *fifo = map_value_obtain(pfifo);
        message_node_t *node = self->peek_pending(self, fifo->atom, context);
        if (head == NULL) {
            head = node;
        } else if (node && node->context->ms < head->context->ms) {
            head = node;
        }
    }
    map_iterator_destroy(&it);
    map_iterator_retire(&it);

    return head;
}