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

Reacting to file events.

The class CFileEvent allows an application to react asynchronously to events on a file. To use a CFileEvent you will need to:

In the example below, a file event is created to monitor stdin. When input is available on stdin, the first word of the line is echoed back on stdout.

#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;

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