4.7 Event Handlers
An event handler is a user-defined function called by the SRL to handle a specific event that occurs on a specified device.
This subsection was not listed in the mapping spreadsheet, so it is unclear whether it should really map to this location rather than the Event Handling module.Typically, in a Windows environment, processing events within a thread or using a separate thread to process events tends to be more efficient than using event handlers. However, if event handlers are used, such as when an application is being ported from Linux, then you must use the asynchronous with SRL callback model.
The following guidelines apply to using event handlers:
- more than one handler can be enabled for an event. The SRL calls all specified handlers when the event is detected
- handlers can be enabled or disabled from any thread
- general handlers can be enabled to handle all events on a specific device
- a handler can be enabled to handle any event on any device
- synchronous functions cannot be called from a handler
By default, when the sr_enbhdlr( ) function is first called, a thread internal to the SRL is created to service the application-enabled event handlers. This SRL handler thread exists as long as one handler is still enabled. The creation of this internal SRL event handler thread is controlled by the SR_MODELTYPE value of the SRL sr_setparm( ) function. The SRL handler thread should be:
- enabled when using the asynchronous with SRL callback model. Enable the SRL event handler thread by not specifying the SR_MODELTYPE value (default is to enable) or by setting this value to SR_MTASYNC (do not specify SR_STASYNC).
- disabled when using an application-handler thread wherein a separate event handler thread is created within the application that calls the sr_waitevt( ) and gc_GetMetaEvent( ) functions. For an application-handler model, use the asynchronous with SRL callback model but set the SR_MODELTYPE value to SR_STASYNC to disable the creation of the internal SRL event handler thread.
Note: An application-handler thread must not call any synchronous functions.
See the Standard Runtime Library (SRL) Programming Guide for your operating system for the hierarchy (priority) order in which event handlers are called.
Click here to contact Telecom Support Resources
Copyright 2002, Intel Corporation