| iMatix home page | << | < | > | >> |
SMT Version 2.81 |
#include "smtlib.h" AGENT * agent_declare ( const char *agent_name /* Name of agent to declare */ )
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 |
{ 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); }
| << | < | > | >> | Copyright © 1996-99 iMatix Corporation |