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

 

agent_declare

#include "smtlib.h"
AGENT *
agent_declare (
    const char *agent_name              /*  Name of agent to declare         */
)

Synopsis

Declares a new agent. Typically you'll do this when you are initialising a agent. You must declare the agent before you can create queues, threads, or methods for that agent. The agent name is an arbitrary text, unique within the application. Returns the address of the created AGENT block. If there was an error, returns NULL and sets smt_errno to one of these values:
SMT NOTREADY smt_init() was not called, or failed
SMT OUTOFMEMORY Not enough heap memory left
SMT AGENTEXISTS A agent with this name is already declared
Agents and threads are stored in the dictionary as follows: a name is built of three parts: s~agent~[thread]. This name is the key into the dictionary and lets us find a agent, or thread by name. Then, all agents are chained into a linked list that is attached to the agents list. Each agent has a sublist of queues, and each queue has a sublist of threads. Each thread has a pointer to the parent queue respectively. This cross-linking lets us browse the list of agents/threads from any point. Names are always stored in lower-case. Sets agent priority to SMT_PRIORITY_NORMAL; sets router flag to FALSE, and max_threads to 0.

Source Code - (smtlib.c)

{
    SYMBOL  *dict_entry;                /*  Dictionary symbol                */
    AGENT   *agent;                     /*  Agent information block          */
    char    *full_name;                 /*  Full agent name                  */

#if (defined (SMT_TRACE))
    trace ("agent_declare: agent=%s", agent_name);
#endif
    ASSERT (agent_name);
    if (!smt_alive)                     /*  If SMT API was not correctly     */
      {                                 /*    initialised, forget it         */
        smt_errno = SMT_NOTREADY;
        return (NULL);
      }

    /*  Check that agent is not already declared                             */
    full_name = get_entity_name (agent_name, NULL);
    if (sym_lookup_symbol (dict, full_name))
      {
        smt_errno = SMT_AGENTEXISTS;
        return (NULL);
      }

    /*  Now create entry for the agent                                       */
    dict_entry = sym_create_symbol (dict, full_name, NULL);
    if (dict_entry == NULL)
      {
        smt_errno = SMT_OUTOFMEMORY;
        return (NULL);
      }

    /*  Allocate an AGENT block and attach it to the agent list              */
    agent = (AGENT *) node_create (agents.prev, sizeof (AGENT));
    if (agent == NULL)
      {
        sym_delete_symbol (dict, dict_entry);
        smt_errno = SMT_OUTOFMEMORY;
        return (NULL);
      }

    /*  Point the dictionary entry to the agent information block            */
    dict_entry-> data = agent;

    /*  Now initialise the agent - all fields are already set to zero        */
    node_reset (&agent-> methods);
    node_reset (&agent-> queues);
    agent-> symbol = dict_entry;
    agent-> name    = mem_strdup (agent_name);

    /*  These fields must be set by the calling program                      */
    agent-> tcb_size     = 0;           /*  Size of thread context block     */
    agent-> maxevent     = 0;           /*  Number of events defined         */
    agent-> maxmodule    = 0;           /*  Number of modules defined        */
    agent-> maxstate     = 0;           /*  Number of states defined         */
    agent-> initialise   = NULL;        /*  Initialise-the-thread            */
    agent-> LR_nextst    = NULL;        /*  Next state table                 */
    agent-> LR_action    = NULL;        /*  Action table                     */
    agent-> LR_offset    = NULL;        /*  Vector offset table              */
    agent-> LR_vector    = NULL;        /*  Vector table                     */
    agent-> LR_module    = NULL;        /*  Module table                     */
    agent-> LR_defaults = 0;            /*  Defaults state                   */

    /*  These fields may be changed by the calling program                   */
    agent-> stack_size   = 0;           /*  Subdialog stack size (if reqd)   */
    agent-> LR_mname     = NULL;        /*  Module name table (if animated)  */
    agent-> LR_sname     = NULL;        /*  State name table (if animated)   */
    agent-> LR_ename     = NULL;        /*  Event name table (if animated)   */
    agent-> priority     = SMT_PRIORITY_NORMAL;
    agent-> router       = FALSE;       /*  Agent acts as a router           */
    agent-> animate      = FALSE;       /*  Agent animation enabled          */
    agent-> max_threads = 0;            /*  Max. number of threads           */

    return (agent);
}

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