| Previous | Menu | Next |
|
The work of receiving an event from an ECS Engine and dispatching it to the downstream process is encapsulated in the handleEvent() method of the ECS_EventReceiver class. To build an event receiver requires deriving your own receiver class from ECS_EventReceiver and overriding its handleEvent() method with your own. You can then instantiate the new receiver class and pass it to the ECS_Engine. Whenever an event arrives from the ECS Engine, your handleEvent() method is called. The following source code illustrates the principles:
.
.
.
//---------- The myReceiver Class --------
class myReceiver : public ECS_EventReceiver
{
public:
myReceiver() : _count(0) {};
int32 handleEvent(const ECS_Event& event, const char* streamName);
~myReceiver();
private:
int32 _count;
};
myReceiver::~myReceiver()
{
cout << "Received " << _count << " events" << endl;
}
int32 myReceiver::handleEvent(const ECS_Event& event, const char*)
{
cout << "Received Event:" << endl;
cout << "\t" << event.getPdu() << endl;
_count++;
return ECS_SUCCESS;
}
bool endloop = false;
// ------- The main program ----------
int main(int argc, char* argv[])
{
int32 status = ECS_SUCCESS;
int32 instance = 1;
char c;
// Need to catch termination signals so that
// communication with the engine is properly
// shutdown. The API will do this automatically,
// but only if main() returns or exit() is called.
signal(SIGTERM, exitHandler);
signal(SIGINT, exitHandler);
// Create a handle for engine instance 1
ECS_Engine engine(instance);
// Create an instance of the event output handler class
myReceiver receiver;
// Set the filter as required...
// Register the output handler instance with the engine
status = engine.addEventReceiver(receiver);
// This is an example of using ECS::poll()
// This is useful when the receiving program is
// doing things other than receiving events.
while (endloop == false)
{
Sleep(1);
ECS::poll();
}
return status;
}
|