A Few Simple Examples
The Server publishes one service (integer value)
#include <dis.hxx>
int main()
{
int run = 0;
DimService runNumber("DELPHI/RUN_NUMBER",run);
DimServer::start("RUN_INFO");
// ...
}
The Client subscribes to the service,
requesting it to be updated every 5 seconds.
If the service is not available the value "-1" should
be received instead.
#include <dic.hxx>
int main()
{
DimInfo runNumber("DELPHI/RUN_NUMBER",5,-1);
// ...
cout << "Run Number " << runNumber.getInt()
<< endl;
}
#include <dis.hxx>
int main()
{
int run = 0;
DimService runNumber("DELPHI/RUN_NUMBER",run);
DimServer::start("RUN_INFO");
while(1)
{
// ...
run++;
runNumber.updateService();
}
}
The Client subscribes to one service and
executes a method when the service gets updated
(when the server executes updateService()):
#include <dic.hxx>
class RunNumber : public
DimInfo
{
void infoHandler()
{
cout << "Run Number
" << getInt() << endl;
}
public :
RunNumber() : DimInfo("DELPHI/RUN_NUMBER",-1)
{};
};
int main()
{
RunNumber runNumber;
while(1)
pause();
}
The Server can receive commands (a string):
#include <dis.hxx>
class Command: public
DimCommand
{
void commandHandler()
{
cout << "Received
: " << getString() << endl;
}
public:
Command() :
DimCommand("DELPHI/TEST/CMND","C") {};
};
int main()
{
Command cmnd;
DimServer::start("TEST");
while(1)
pause();
}
The client sends a command:
#include <dic.hxx>
int main()
{
DimClient::sendCommand("DELPHI/TEST/CMND","DO_IT");
}