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

 

The Time Slot Agent - SMTSLOT

Manages 'time slots', a mechanism to allow long-running programs to 'switch on' and 'switch off' at specific times during the day. The time slot agent simulates a wall timer, i.e. a timer that switches a device like a lamp or electric heater on and off during the day.

To use SMTSLOT, call smtslot init(). This does not create any threads. Create a named thread, then send SPECIFY events to define the various time slots for your application. Then send an ON or OFF event to initialise the timer. The time slot agent then sends a SWITCH_ON event when the timer move to an 'ON' state, and a SWITCH_OFF event when the timer moves to an 'OFF' state. Errors are sent to the console, not the requesting program. SMTSLOT supports these methods:

Example of initialising SMTSLOT:

/*  Static data                                                 */
static QID
    slotq;                       /*  Time slot event queue      */

    /*  In agent initialisation code                            */
    THREAD  *thread;            /*  Handle to various threads   */
    /*  Ensure that time slot agent is running, else start it   */
    smtslot init ();
    if ((thread = thread create (SMT_SLOT, "myprog")) != NULL)
        slotq = thread-> queue-> qid;
    else
        return (-1);

The SPECIFY Method

Defines one or more time slots. A slot specification is a string, in the format: "name value ...". The name field is a day name ("mon"-"sun"), a date in MD order ("12/31") or a date in YMD order ("95/12/31"). The value is a list of times in 24 hour HH:MM[-HH:MM] format ("7:30-12:30 13:30-17:30 17:35"). A value "off" clears all time slots for that day. The time slot accuracy is SLOT_TICK csecs. Any day that does not have specified values is switched 'off'. Build the event body using exdr_write() and the message definition SMT_SLOT_SPEC. The event body consists of these fields (see exdr_write() for the field types):

SMTTRAN replies to a SPECIFY event with a SLOT_ERROR event if there was an error, else it does not reply.

The ON Method

Sets the timer 'ON'. The event does not have a body. The timer will respond with a SWITCH_OFF event when it moves into an 'OFF' state.

The OFF Method

Sets the timer 'OFF'. The event does not have a body. The timer will respond with a SWITCH_ON event when it moves into an 'ON' state.

Example Of Use

The SMTTST2 agent shows an example of using the time slot agent.

SMTSLOT Implementation

The hypertext view of SMTSLOT's dialog and source code may help to understand how SMTSLOT works.


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