Ipc: Difference between revisions

From CLONWiki
Jump to navigation Jump to search
Boiarino (talk | contribs)
Boiarino (talk | contribs)
Line 73: Line 73:
If information is requested, program suppose to send back following:
If information is requested, program suppose to send back following:


  server << clrm << "control" << "reply" << "status:myname" << ... << endm;
  server << clrm << "control" << "info" << "status:myname" << ... << endm;
  server << clrm << "control" << "reply" << "statistics:myname" << ... << endm;
  server << clrm << "control" << "info" << "statistics:myname" << ... << endm;

Revision as of 16:31, 14 September 2017

General info

Interprocess communication in Hall B is based on package located in $CLON/src/ipc. Currently it is based on ActiveMQ, which can be replaced with another messager if necessary, for example jlab-developed xMsg. Switching between messagers is done by changing $CLON/src/Makefile.include and recompiling entire $CLON area. ActiveMQ or any other messager must be installed in /usr/local/src area.

Top level classes can be found in $CLON/src/ipc/ipc.s/ipc_lib.h, test program is $CLON/src/ipc/main/ipc_client.cc.

Sender subscribes to the 4-field topic

TOPIC1.TOPIC2.TOPIC3.TOPIC4

and start message from message format character string

(char *)"FORMAT:TOPIC4:TOPIC3:TOPIC2:TOPIC1"

with following format:

Topic (defaults are NULL or '*'):

TOPIC1 - usually getenv("EXPID")
TOPIC2 - usually getenv("SESSION")
TOPIC3 - message class, for example 'control', 'epics', 'daq' etc
TOPIC4 - unique name of sender, usually program name

Message format:

FORMAT - message format, for example 'cmd', 'json' etc, 'MessageActionXXXX.h' must be provided for every format
TOPIC4 (optional)
TOPIC3 (optional)
TOPIC2 (optional)
TOPIC1 (optional)


Typical user code includes following:

#include "ipc_lib.h"
#include "MessageActionControl.h"
#include "MessageActionXXXX.h" // XXXX is particular listener, like MessageActionEPICS.h
IpcServer &server = IpcServer::Instance(); // get ipc server instance, it is implemented as singleton
main()
{
  // following call sets topic for sender ("par1.par2.par3.par4") and receiver ("par1.par2.par5.par6")
  // 1st and 2nd params - usually EXPID and SESSION, or EXPID and NULL
  // 3rd and 4th params - 'class' and 'destination' for sender only, for example 'epics' and 'dbrouter' (sending to class 'epics' and destination 'dbrouter')
  // 5th and 6th params (optional) - 'class' and 'destination' for receiver only, for example 'epics' and '*' (listen for messages with class 'epics' and any destination)
  // for example:
  server.init(getenv("EXPID"), getenv("SESSION"), (char *)"epics", (char *)"dbrouter", (char *)"epics", (char *)"*");
  MessageActionControl  *control = new MessageActionControl((char *)"myname");
  MessageActionXXXX        *xxxx = new MessageActionXXXX();
  server.addActionListener(control);
  server.addActionListener(xxxx);
  server << clrm << ...stuff... << endm;
  server.close();
}


MessageActionControl.h

Sends commands and receives status. Command message sent by program 'myname' must has following format:

server.init(getenv("EXPID"), getenv("SESSION"), "control", destination);
server << clrm << "control:myname" << "command" << "quit" << endm;        // request to quit
server << clrm << "control:myname" << "command" << "status" << endm;      // request for status
server << clrm << "control:myname" << "command" << "statistics" << endm;  // request for statistics

If information is requested, program suppose to send back following:

server << clrm << "control" << "info" << "status:myname" << ... << endm;
server << clrm << "control" << "info" << "statistics:myname" << ... << endm;