| iMatix home page
| << | < | > | >>
SMT Logo SMT
Version 2.81

 

queue_deliver

#include "smtlib.h"
int
queue_deliver (
    QUEUE  *queue,                      /*  Queue containing events          */
    THREAD *thread)                     /*  Agent thread to receive event    */

Synopsis

Tries to deliver an event from a queue to an agent thread. The event, if deliverable, is removed from the queue and stored in the thread-> event block. Returns 1 if an event was delivered, else 0.

Source Code - (smtlib.c)

{
    AGENT   *agent;                     /*  Agent to receive event           */
    EVENT   *event;                     /*  Event information block          */
    EVENT   *deliver_event;             /*  Event to deliver                 */
    METHOD  *method;                    /*  Method information block         */
    int     top_priority;               /*  Highest event priority so far    */

#if (defined (SMT_TRACE))
    trace ("queue_deliver: thread=%s in %s", thread-> name,
                                             thread-> queue-> agent-> name);
#endif
    /*  Get event to deliver - find event with highest method priority       */
    top_priority  = -1;
    deliver_event = NULL;
    agent = thread-> queue-> agent;
    event = queue-> events.next;
    while ((NODE *) event != &queue-> events)
      {
        if (event-> priority == SMT_PRIORITY_NULL)
          {
            /*  Lookup method; if method is not declared, reject event      */
            method = method lookup (agent, event-> name);
            if (method == NULL)
              {
                /*  Reject this event, but keep our place in the queue...   */
                sendfmt (&console, "ERROR", "Event %s not declared by %s",
                         event-> name, agent-> name);
                event = event-> next;
                event reject (queue, event-> prev);
                continue;
              }
            else
            /*  If null method, accept event but discard it                 */
            if (method-> event_number == SMT_NULL_EVENT)
              {
                event = event-> next;
                node_destroy (event accept (queue, event-> prev));
                continue;
              }
            /*  Update the event values, to save a lookup next time         */
            event-> priority     = method-> priority;
            event-> event_number = method-> event_number;
          }
        if (event-> priority > top_priority)
          {
            top_priority  = event-> priority;
            deliver_event = event;
          }
        event = event-> next;
      }
    if (deliver_event)
      {
        /*  Deliver event to thread                                          */
        if (thread-> event)
            event destroy (thread-> event);
        thread-> the_next_event = deliver_event-> event_number;
        thread-> event = event accept (queue, deliver_event);
        return (1);                     /*  We delivered the event           */
      }
    else
        return (0);                     /*  We did not find an event         */
}

| << | < | > | >> iMatix Copyright © 1996-99 iMatix Corporation