Event Framework

The main support for concurrency in the OSE C++ class libraries comes in the form of a mechanism for building event driven systems. This is based around a central job queue and a dispatcher, which takes successive jobs from the queue and executes them. To support real time systems, there also exist a number of event sources which will schedule jobs to trigger an agent to be notified when an event of interest occurs. The major event sources include timers, signals and the availability of data for reading on a socket.

The major classes in the OSE C++ class library involved in providing this functionality are the

OTC_Dispatcher, OTC_EVAgent and OTC_Job classes, plus the various event classes related to the event sources. In the C++ implementation, communication of events is mainly performed by pass- ing around event objects and having a single event handler method in an agent to deal with them. In the Python implementation, separate callback functions can be registered by an agent against each event of interest.

Note that only the major features of the C++ implementation are reflected in the Python interface. Py- thon does not provide a means of creating your own event types or event sources. A Python agent is also not able to process any events except those from the major event sources.

Scheduling a Job

Scheduling of jobs comes in the form of registering a callback function with the dispatcher for execu- tion. A job may be scheduled as a priority job, a standard job, or an idle job. The type of job determines where in the order of existing jobs, a new job will be placed. Any priority jobs are executed before a standard job is processed. When there are no priority jobs or standard jobs remaining, any pending idle

25

Page 25
Image 25
Python 7.0pl5, Python Manual manual Event Framework, Scheduling a Job