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

5.3 Subscribe using criteria

5.3.1 How to define criteria

IS API defines class called ISCriteria to make advanced selection of information objects in the IS repository. This chapter summarizes different types of subscriptions, which can be done using the ISCriteria class.

ISCriteria( "P.*" )
"P.*"

Subscribes to all of information objects, whose names start with capital P.

ISCriteria( "P.*", Person::type() )
"P.*" && Person::type()

Subscribes to all information objects of type Person, whose names start with capital P.

ISCriteria( "P.*", Person::type(), ISCriteria::OR )
"P.*" || Person::type()

Subscribes to all information objects of type Person or all the objects, whose names start with capital P.

One can also used the ~ and ! operators, which are defined for the ISType class in order to compose advanced criteria like it is shown in the following examples.

ISCriteria( "P.*", !Person::type() )
"P.*" && !Person::type()

Subscribes to all information objects of any type but Person, whose names start with capital P.

ISCriteria( "P.*", ~Person::type() )
"P.*" && ~Person::type()

Subscribes to all information objects of type Person or of any type, which is subtype of the Person, whose names start with capital P.

5.3.2 How to subscribe using criteria

"Listing 5.2" shows how an application can subscribe for a subset of information in the particular server of the IS repository.

Listing 5.2   Subscribe using criteria

1: // include main IS header file
2: #include <Person.h>
3: #include <is/inforeceiver.h>
4: #include <ipc/core.h>
5:
6: void callback(ISCallbackInfo * isc){
7: std::cout << "CALLBACK:: " << isc->name() << std::endl;
8: std::cout << "Reason code : " << isc->reason() << std::endl;
9:
10: ISInfoAny isi;
11: isc->value(isa);
12: std::cout << isa;
13: }
14:
15: int main( int ac, char ** av ){
16: // Initialise communication library
17: IPCCore::init( ac, av );
18:
19: // Create the instance of partition
20: IPCPartition partition("MyPartition");
21:
22: // Create the IS receiver instance the specific partitition
23: ISInfoReceiver rec(partitition);
24:
25: // Subscribe for all
26: rec.subscribe( "MyServer", ".*", callback );
27:
28: // Subscribe for all objects of type Person or any
29: // subtype of type Person
30: rec.subscribe( "MyServer", ~Person::type() && ".*", callback );
31:
32: // Subscribe for all objects of any type but Person OR
33: // whose name starts with capital `P'
34: ISCriteria criteria( "P.*", !Person::type(), Criteria::OR );
35: rec.subscribe( "MyServer", criteria, callback );
36:
37: // call method run to block the current thread until
38: // somebody will call the stop for the rec object
39: rec.run();
40:
41: // Remove subscriptions
42: rec.unsubscribe( "MyServer", ".*" );
43: rec.unsubscribe( "MyServer", ~Person::type() && ".*" );
44: rec.unsubscribe( "MyServer", criteria );
45: return 0;
46: }

This program is very similar to the one which is shown in "Listing 5.1". The only difference is in the subscribe call (line 28). The first argument of the subscribe method specifies the IS server name, the second one the subscription criteria and the last one the callback function. The subscription criteria must be a valid POSIX-style regular expression. The callback function has the same format as the function for an individual information subscription.

When any information in this particular IS server is changed the callback function is called. The isc argument (line 4) is a pointer to the object that describes the information which has been changed. One can get name, type and value of the changed information from this object. In addition it can also be used to get the reason why the callback has been called. The valid reasons are: information has been inserted, updated or removed from the IS repository.


2 July 1998 - WebMaster
Copyright © CERN 1998