Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

Event Driven Programming model

What is event driven software.

A simple way to understand the event driven programming model is to compare and contrast it with the the traditional model. In the traditional model the programmer:

In the event driven model, the programmer:

Event driven software is a win whenever:

Both of these criteria are true for the spectrodaq framework.

Event management and the spectrodaq framework

In the spectrodaq event framework, event handlers are member functions of classes descended from the CEvent class. Thus events are handled as follows:

The example below shows this process:

#include <iostream.h>
#include <stdio.h>
#include <spectrodaq.h>
#include <SpectroFramework.h>

class Echo : public CFileEvent
{
public:
  Echo(int fd, const char* pName);
  virtual void OnReadable(istream& rin);
};

Echo::Echo(int fd, const char* pName):
  CFileEvent(fd, pName)
{
  AppendClassInfo();
}

void
Echo::OnReadable(istream& rin)
{
  CFileEvent::OnReadable(rin);
  string word;
  rin >> word;
  cout << word << endl;
}

class MyApp : public DAQROCNode
{
protected:
  virtual int operator()(int argc, char** argv);
};

int
MyApp::operator()(int argc, char** argv)
{
  Echo echo(fileno(stdin), "EchoProcessor");

  echo.Enable();
  DAQThreadId id = echo.getThreadId();

  Join(id);                     // Wait for echo to exit.
}


MyApp theapp;

The Echo class subclasses CFileEvent which is an event handler that watches for events on a file descriptor. Overriding OnReadable supplies application specific behavior for a file descriptor when the file becomes readable. The line in MyApp::operator() which reads:

        Echo echo(fileno(stdin), "EchoProcessor");
creates an instance of this event to listen for and react to input on stdin. and the call to echo.Enable() starts the thread.

When the event thread detecs input on stdin, it calls Echo::OnReadable which proceses the input in an application specific manner.


Generated on Thu Jan 6 16:58:45 2005 for Spectrodaq External Event Framework by  doxygen 1.3.9.1