Пример #1
0
static void fifo_all(void)
{
	add_dir(     FOUND, "");
	add_fifo(    FOUND, "a");
	add_fifo(    FOUND, "b");
	snprintf(extra_config, sizeof(extra_config),
		"include=%s\n"
		"read_all_fifos=1\n",
		fullpath);
}
Пример #2
0
static void fifo_individual(void)
{
	add_dir(     FOUND, "");
	add_fifo(    FOUND, "a");
	add_fifo(    FOUND, "b");
	add_fifo_special(FOUND, "c");
	snprintf(extra_config, sizeof(extra_config),
		"include=%s\n"
		"read_fifo=%s/a\n"
		"read_fifo=%s/b\n",
		fullpath, fullpath, fullpath);
}
Пример #3
0
static void receiver_open(receiver_t *self, atom_t selector)
{
    message_fifo_t *fifo = get_fifo(self, selector);
    if (!fifo) {
        fifo = add_fifo(self, selector);
    }
    fifo->closed_p = 0;
}
Пример #4
0
static void receiver_set_definition(struct receiver_t *self, atom_t a,
                                    bytecode_stream_t *args, recp_f f)
{
    ((definitions_t *)&self->dispatcher.definitions)
        ->set_callback((definitions_t *)&self->dispatcher.definitions, a, args,
                       f);

    add_fifo(self, a);
}
Пример #5
0
static void receiver_receive(receiver_t *self, bytecode_stream_t *message,
                             context_t *context)
{
    atom_t selector;
    message_fifo_t *fifo;
    message_node_t *node;
    node_iterator_t it;

    if (!message || !message->end) {
        WARNING1("message === NULL");
        return;
    }

    selector = message->end->code.verb;
    fifo = get_fifo(self, selector);
    node = calloc(sizeof(message_node_t), 1);

    if (!fifo)
        fifo = add_fifo(self, selector);

    if (fifo->closed_p) {
        /* destroy the message and the context objects */
        bytecode_stream_retire(message);
        context_retire(context);

        return;
    }

    /*
       insert message in the right position

       messages are ordered by decreasing context from beginning to end.
    */
    if (get_node_iterator(fifo, &it)) {
        message_node_t *current = NULL;
        message_node_t *last = NULL;

        TRACE3("adding at: %f in fifo: %s", context->ms,
               atom_get_cstring_value(fifo->atom));

        while ((current = node_iterator_next(&it)) &&
               context->is_in(context, current->context)) {
            /* advance until context is not anymore in current context */
            TRACE2("current at: %f", current->context->ms);
            last = current;
        }

        if (last == NULL) {
            if (fifo->end == NULL) {
                TRACE1("append to empty fifo");
                node->next = node;
                node->prev = node;
                fifo->end = node;
            } else {
                if (context->is_in(context, current->context)) {
                    TRACE2("insert after current at %f", current->context->ms);
                    node->prev = current;
                    node->next = current->next;
                    current->next = node;
                    node->next->prev = node;
                } else {
                    TRACE2("insert before current at %f", current->context->ms);
                    node->next = current;
                    node->prev = current->prev;
                    current->prev = node;
                    node->prev->next = node;
                }
                if (current == fifo->end)
                    fifo->end = node;
            }
        } else {
            if (context->is_in(context, last->context)) {
                TRACE2("insert after last at %f", last->context->ms);
                node->prev = last;
                node->next = last->next;
                last->next = node;
                node->next->prev = node;
            } else {
                TRACE2("insert before last at %f", last->context->ms);
                node->next = last;
                node->prev = last->prev;
                last->prev = node;
                node->prev->next = node;
            }
            if (last == fifo->end)
                fifo->end = node;
        }
    }
    node->bytecodes = message;
    node->context = context;
    node->dispatched_p = 0;

    if (node->context->dispatch_now_p) {
        self->eval(self, node->bytecodes, node->context);
        node->dispatched_p = 1;
    }
}