30 Global Call API for HMP on Windows Programming Guide — August 2006
Programming Models
and gc_GetMetaEvent() functions. When these functions return with an event, the event
information is stored in the METAEVENT data structure. The event information retrieved
determines the exact event that occurred and is valid until the sr_waitevt() and
gc_GetMetaEvent() functions are called again.
For Windows environments, the asynchronous models provided for application development also
include:
asynchronous model with event handlers
asynchronous with Windows callback
asynchronous with Win32 synchronization
extended asynchronous programming
The asynchronous programming models are recommended for more complex applications that
require coordinating multiple tasks. Asynchronous model applications typically run faster than
synchronous models and require lower levels of system resources. Asynchronous models reduce
processor loading because of the reduced number of threads inherent in asynchronous models and
the elimination of scheduling overhead. Asynchronous models use processor resources more
efficiently because multiple channels are handled in a single thread or in a few threads. See
Section 5.1, “General Programming Tips”, on page 77 for details. Of the asynchronous models, the
asynchronous with SRL callback model and the asynchronous with Windows callback model
provide the tightest integration with the Windows message/event mechanism. Asynchronous model
applications are typically more complex than corresponding synchronous model applications due
to a higher level of resource management (that is, the number of channels managed by a thread and
the tracking of completion events) and the development of a state machine.
After the application issues an asynchronous function, the application uses the sr_waitevt()
function to wait for events on Intel Dialogic devices. All event coding can be accomplished using
switch statements in the main thread. When an event is available, event information may be
retrieved using the gc_GetMetaEvent() function. Retrieved event information is valid until the
sr_waitevt( ) function is called again. The asynchronous model does not use event handlers to
process events.
In this model, the SRL handler thread must be initiated by the application by setting the
SR_MODELTYPE value to SR_STASYNC.
2.2.2 Asynchronous Model with Event Handlers
The asynchronous with event handlers model uses the sr_enbhdlr( ) function to automatically
create the SRL handler thread. The application does not need to call the sr_waitevt( ) function
since the thread created by the sr_enbhdlr() already calls the sr_waitevt( ) function to get events.
Each call to the sr_enbhdlr() function allows the Intel Dialogic events to be serviced when the
operating system schedules the SRL handler thread for execution.
Note: The SR_MODELTYPE value must not be set to SR_STASYNC because the SRL handler thread
must be created by the sr_enbhdlr() call. The event handler must not call the sr_waitevt( )
function or any synchronous Intel Dialogic function.