Introduction
Previous Topic  Next Topic 

This library provides the task management functions for starting and stopping tasks, sleeping, retrieving task arguments etc.


A new task can be started in the Telecom Engine either by naming a program in the TEX command line, using the TOOLS tab in the TE Run-Time Engine Window or by using the task_spawn(), task_exec() or task_chain() functions in the CXTASK.DLL.        The  task_spawn() function starts a new task and the original task continues processing.  The  task_exec() function starts a new task and the calling task is suspended until the new task stops.      The task_chain() function starts a new task and kills the calling task.


If spawn successfully launches a new task, then the return value is the task ID of the new task.  Otherwise a negative number is returned to indicate an error:



task_id = task_spawn("CHILD");

if (task_id < 0)

    errlog("Error spawning CHILD.TEX, Cannot continue ");

    exit (1);

endif


Arguments may be optionally passed to the new task. 


task_spawn("SLAVE", port,chan);


The new task can retrieve these arguments by using the task_arg() function.      A typical application will have a single MASTER program that then spawns all other tasks in the system.   Usually there would be one task in charge of each network channel and the port and channel number (amongst other parameters) would be passed to the slave task.      Here is a simple example using the CXACULAB.DLL library:



// MASTER.TEX program:

int port, chan;

main

    port=0;    //  The first E1

    // Spawn a slave task for each channel of the E1

     for (chan = 1; line <= 30; chan++)

        task_spawn("SLAVE", port,chan);

    endfor

endmain


// SLAVE.TEX program:

int port, line;

main

    // Get the port and chan that this task is in charge of ..

    port = task_arg(1);

    chan=task_arg(2);


    // Enable inbound calls on chan

    CCenablein(port,chan)

   

    // Wait for incoming call

    while(CCwait(port,chan,0) != CS_INCOMING_CALL_DETECTED)

         ;

    end

   

     // Answer the call

    CCaccept(port,chan);


    ...


endmain



The MASTER.TEX program (which would be specified on the command line to the TEX.EXE run-time program) spawns 30 SLAVE.TEX tasks, each one in charge of a single channel (the port and channel being passed as arguments to the SLAVE task).    The SLAVE task the waits for and incoming call on the channel and answers the phone when one arrives.      This task could then start playing speech files or could call task_chain() to launch another application (depending of the received DID digits for example).