CCwait
Previous Topic  Next Topic 

Synopsis:

CCwait(port,chan,timeout_100ms,&pState)

Arguments:

       port The logical E1/T1 port number.

channel The channel number.

pState Pointer to a variable to receive the ID of the event that terminated the CCwait() call.


Description:   This function will wait for an event to be received on a particular port and channel it will return either when an event is detected on the channel or the timeout has expired (or if it is aborted by CCabort()).       The timeout is specified in 100ms units (tenths of a second) after which the function will return if no event has been received.    If -1 (CC_WAIT_FOREVER) is specified for the timeout then  the call will wait forever for an event.      


The function takes a pointer to a variable which will hold the ID of the event received.


Note that the function keeps an internal track of events on a channel and if the state of a channel has changed since the last time it was called then it will return immediately with the current state of the channel.        This is to prevent events from being missed in between calls to CCwait() but it means that the programmer should always check the returned state in a loop to ensure that the expected event is received.    For example:


    // loop waiting for incoming call

    while(1)

          x=CCwait(port,chan,CC_WAIT_FOREVER,&event);

          // Make sure the event we want is received..

          if(x > 0 and event eq CS_INCOMING_CALL_DETECTED)

               break;

          endif

    endwhile

 

    // Answer the call

    CCaccept(port,chan);

 

    // Play a vox file to caller

    SMplay(vox_chan,filename);

   

    // Hangup the call 

    CCdisconnect(port,chan,CAUSE_NORMAL);

 

   // Wait for state to return to IDLE the release call

    while(1)

// THIS WILL RETURN IMMEDIATEDELY THE FIRST TIME IT IS          x=CCwait(port,chan,CC_WAIT_FOREVER,&event);

       if(x eq CS_IDLE)

             break;

       endif

    endwhile



In the second loop above where the application calls CCwait() to check for a return to the state CS_IDLE, the CCwait() call will certainly return immediately the first time through the loop since the state will have changed since it was last called to check for CS_INCOMING_CALL_DETECTED.



Returns:  The function will return 0 if the timeout has expired without receiving an event (or if the function was aborted by a CCabort() call).     It will return 1 if the function terminated because an event was detected (and the event ID will be set in the variable pointed to by pState).    It will return -1 is a bad port or channel was given.