Sending Messages - send_message, started_died_hook

Cogent Tools Demo and Tutorials: Version 4.0
Prev | Chapter 9. Common Functions for Any Program (in `lib/common.g`) | Next

# 9.9. Sending Messages - `send_message`, `started_died_hook`

This function uses the Gamma `send_async` function to send executable code to the Controller. This sends an message asynchronously, which allows this function to continue without waiting for a reply from the Controller. This breaks a potential feedback loop, because the Controller also sends messages (start and stop) to the Monitor.

       /*--------------------------------------------------------------------
        * Function:    send_message
        * Returns:     t or nil
        * Description: Sends information messages for the Controller's text box.
        *              The text of the messages is stored in the file
        *              'messages.txt'.
        *------------------------------------------------------------------*/
       function send_message(msg)
       {
         local tsk;
         if ((tsk = locate_task("control", nil)) != nil)
           {
             if(msg == "nsnames")
                 send_async(tsk, `show_names(text2));
             else
                 send_async(tsk, `anygui_show_text(text, read_msg(@msg), 1));
             close_task(tsk);
           }
       }

This `started_died_hook` function is run whenever a task starts or dies, and is used to update the Process Status display. The multiple-length optional argument (see Function Arguments in the Gamma manual) allows for multiple tasks starting and stopping.

       /*--------------------------------------------------------------------
        * Function:    started_died_hook
        * Returns:     t or nil
        * Description: Called whenever a task starts or dies, this function
        *              calls send_message() to change the process status display.
        *              Gets added to the Controller from within the
        *              program_startup() function.
        *------------------------------------------------------------------*/
       function started_died_hook(!a?...=nil)
       {
         send_message("nsnames");
       }

Prev | Home | Next
Stop Processes - `stop_processes` | Up | Abstracted Functions

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.