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

2.3 Reading simple information

2.3.1 Getting the last value of the information

Once an information is published any other application can read it. "Listing 2.4" shows how a C++ program can get the latest information value. This program uses the getValue method of the ISInfoDictionary class in order to get the value of the specific information from the IS.

Listing 2.4   Reading last value of information

1: #include <is/infoT.h>
2: #include <is/infodictionary.h>
3: #include <ipc/core.h>
4:
5: int main ( int ac, char ** av ){
6: // Initialise communication library
7: IPCCore::init( ac, av );
8:
9: // Create the instance of partition
10: IPCPartition partition("MyPartition");
11:
12: // Create the IS dictionary the specific partitition
13: ISInfoDictionary dict(partitition);
14:
15: // Create the instances of the information that will be read
16: ISInfoInt voltage;
17: ISInfoFloat temperature;
18:
19: // Read information
20: dict.getValue( "MyServer.DeviceVoltage", voltage );
21: dict.getValue( "MyServer.DeviceTemperature", temperature );
22: return 0;
23: }

2.3.2 Getting information history

"Listing 2.5" shows how a C++ program can get the all information values, including the latest value and also all or some history values This program uses the getValues template method of the ISInfoDictionary class in order to get the all the value of the specific information from the IS.

Listing 2.5   Reading history of information

1: // include the IS header file
2: #include <is/infoT.h>
3: #include <is/infodictionary.h>
4: #include <ipc/core.h>
5:
6: int main ( int ac, char ** av ){
7: // Initialise communication library
8: IPCCore::init( ac, av );
9:
10: // Create the instance of partition
11: IPCPartition partition("MyPartition");
12:
13: // Create the IS dictionary instance
14: // using the partitition object as parameter
15: ISInfoDictionary dict(partitition);
16:
17: // Create the instances of the information
18: // that will be red
19: std::vector<ISInfoInt> voltages;
20: std::vector<ISInfoFloat> temperatures;
21:
22: // Read information history
23: dict.getValues( "MyServer.DeviceVoltage", voltages );
24: dict.getValues( "MyServer.DeviceTemperature", temperatures );
25:
26: for ( size_t i = 0; i < voltages.size(); i++ )
27: std::cout << "Voltage [" << i << "] = " << voltages[i] << std::endl;
28:
29: for ( size_t i = 0; i < voltages.size(); i++ )
30: std::cout << "Temperatures [" << i << "] = " << temperatures[i] << std::endl;
31:
32: return 0;
33: }

The lines 21-27 shows how to read all the history values for the "MyServer.DeviceVoltage" and "MyServer.DeviceTemperature" information respectively. The history values are stored in the vector, which is provided as second argument of the getValues function. The information values in the resulting vector are sorted by their time with the most recent value in the first element of the vector.

The list of history values might be long and one may want to read only the last N history values instead of reading all of them. This can be done by using the 3d parameter of the getValues function as it is shown in "Listing 2.6".

Listing 2.6   Reading last 10 values from information history

1: // include the IS header file
2: #include <is/infoT.h>
3: #include <is/infodictionary.h>
4: #include <ipc/core.h>
5:
6: int main ( int ac, char ** av ){
7:
8: ...
9:
10: std::vector<ISInfoInt> voltages;
11: std::vector<ISInfoFloat> temperatures;
12:
13: // Read the last 10 history values information
14: dict.getValues( "MyServer.DeviceVoltage", voltages, 10 );
15: dict.getValues( "MyServer.DeviceTemperature", temperatures, 10 );
16:
17: return 0;
18: }

This 3d parameter has a default value set to -1, which means that all history values have to be read. Setting this parameter to some other positive value N will result in reading at most the N last information values. If the current history size is less than N, then the number of elements in the vector will be equal to the current history size.


2 July 1998 - WebMaster
Copyright © CERN 1998