| iMatix home page | << | < | > | >> |
SMT Version 2.81 |
#include "smtlib.h" METHOD * method_declare ( AGENT *agent, /* Create method in this agent */ const char *method_name, /* Name of method to declare */ event_t event_number, /* Method number from dialog */ int priority /* Priority for the method, or 0 */ )
Declares a new method for an agent. All external events that an agent is prepared to method are declared as methods. The agent must already have been declared using agent declare(). The method name is an arbitrary text, unique within the agent. The event number is the number of the event assigned by the dialog code generator; if you specify the event number as SMT_NULL_EVENT, the method is ignored. This discards any incoming events with that name. The priority may be 0 (meaning normal priority), SMT_PRIORITY_LOW, SMT_PRIORITY_HIGH, or another suitable value. Returns the address of the created METHOD block. If there was an error, returns NULL and sets smt_errno to one of:
SMT NOTREADY | smt_init() was not called, or failed |
SMT OUTOFMEMORY | Not enough heap memory left |
SMT NOSUCHAGENT | Specified agent was not declared |
SMT METHODEXISTS | Method is already declared |
{ SYMBOL *dict_entry; /* Dictionary symbol */ METHOD *method; /* Method information block */ char *full_name; /* Full method name */ #if (defined (SMT_TRACE)) trace ("method_declare: agent=%s method=%s", agent-> name, method_name); #endif ASSERT (agent); ASSERT (method_name); if (!smt_alive) /* If SMT API was not correctly */ { /* initialised, forget it */ smt_errno = SMT_NOTREADY; return (NULL); } /* Check that method is not already declared */ full_name = get_method_name (agent-> name, method_name); if (sym_lookup_symbol (dict, full_name)) { smt_errno = SMT_METHODEXISTS; return (NULL); } /* Now create entry for the method */ dict_entry = sym_create_symbol (dict, full_name, NULL); if (dict_entry == NULL) { smt_errno = SMT_OUTOFMEMORY; return (NULL); } /* Allocate a METHOD block and attach it to the method list */ method = (METHOD *) node_create (&agent-> methods, sizeof (METHOD)); if (method == NULL) { sym_delete_symbol (dict, dict_entry); smt_errno = SMT_OUTOFMEMORY; return (NULL); } /* Point the dictionary entry to the method information block */ dict_entry-> data = method; /* Now initialise the method - all fields are already set to zero */ method-> symbol = dict_entry; method-> agent = agent; method-> name = mem_strdup (method_name); method-> priority = priority? priority: SMT_PRIORITY_NORMAL; method-> event_number = event_number; return (method); }
| << | < | > | >> | Copyright © 1996-99 iMatix Corporation |