CERN -> IPT Group -> FrameMaker at CERN
Information Service User's Guide

8.2 Implementing IS command listener

"Listing 8.1" shows what an application has to do in order to be able to receive commands, which are sent to the information objects provided by this application.

First, the user program has to include the is/infoprovider.h which declares the ISInfoProvider and ISCommandListener classes. Then it is necessary to declare the command listener class, which has to inherit the ISCommandListener and override a single pure virtual function defined in this class. In the above example this is done by lines 5-13. The user's command listener class is called MyCommandListener. This class provides implementation of the command function. This function will be called when a command to this information provider is received. It has two arguments: first one is a command itself and the second one is the name of the information object, to which this command has been sent.

Listing 8.1   Command listener example

1: // include main IS header file
2: #include <is/infoprovider.h>
3: #include <ipc/core.h>
4:
5: class MyCommandListener : public ISCommandListener {
6: public:
7: void command( const std::string & name,
8: const std::string & cmd ) {
9: std::cout << "MyCommandListener:: command '"
10: << cmd << "' received for the '"
11: << name << "' info" << std::endl;
12: }
13: };
14:
15: int main( int ac, char ** av ) {
16: // Initialise communication library
17: IPCCore::init( ac, av );
18:
19: // Create the instance of command listener
20: MyCommandListener lst;
21:
22: // Register the command listener
23: ISInfoProvider::instance().addCommandListener( &lst );
24: ...
25: // Deactivate the command listener before exiting
26: ISInfoProvider::instance().removeCommandListener( &lst );
27: return 0;
28: }

Then the program creates the instance of the MyCommandListener class and activates this instance using the ISInfoProvider::addCommandListener function (line 23). Only after the call to the addCommandListener function, the user's command listener will be able to receive commands. The counterpart of the addCommandListener function is the ISInfoProvider::removeCommandListener one, which can be used to deactivate a particular command listener as it is shown in line 26.


2 July 1998 - WebMaster
Copyright © CERN 1998