Adding application specific variablesTailoring the softwareDocumenting event segment packet typesAdding commands

Adding commands

Readout supports extending the command interpreter. This allows you to integrate application specific commands into the Readout program. To add a command extension you must:

Deriving a class from CDAQTCLProcessor requires that you implement a constructor, that defines the command keyword, and an operator() that executes the command when the interpreter decodes it. The call sequence for operator() is:

      virtual int 
       operator()(CTCLInterpreter&  rInterp, 
                            CTCLResult&  rResult, 
			    int  argc, char**  argv)
      

Where:

rInterp is a reference to the interpreter object that is running the command. The interpreter provides services to the command that allow it to parse its arguments in various ways as well as acess to the expression evaluator.
rResult is a reference to the interpreter's result string. The result string can be thought of as the return value from the command. This object provides support for appending strings or list elements to the result.
argc The number of items in the command list. note that the 'first' of these is the command keyword itself.
argv A pointer to an array of pointer to command list elements.
operator() is expected to return one of:
TCL_OK if the command succeeded.
TCL_ERROR if the command failed.

The code below implements a command class that echoes its input parameters (including the command keyword itself) to the result string:

      class Echo : public DAQTCLCommand {
      public:
	 Echo(const char* keyword, 
	      CTCLInterpreter& rInterp) :
	    DAQTCLCommand(char* keyword, 
			  CTCLInterpreter& rInterp) {}
	 virtual int operator()(CTCLInterpreter& rInterp,
			        CTCLResult&      rResult,
				int               argc,
				char**            argv) {
	    while(argc) {
	       rResult.AppendElement(*argv);
	    
	       argv++;
	       argc--;
	    }
	    return TCL_OK;
	 }
      };
      

Once the command has been created, it must be registered on the interpreter that runs in the readout program. This is done by adding code to AddUserCommands. Note that this function will be called in the context of the interpreter's execution thread.

The sample code below registers the command "Echo" to execute as defined in the Echo object.

      
      void 
      CMyReadout::AddUserCommands(CExperiment& rExperiment,
				  CInterpreterStartup& rStartup,
				  CInterpreterCore& rCore)
      {
	 CTCLInterpreter* pInterp = rStartup.getInterpreter();
	 Echo* pCommand = new Echo("Echo", *pInterp);
	 pCommand->Register();
      }
      
      

Report documentation errors to Ron Fox (fox@nscl.msu.edu)or NSCL's Bugzilla page

Adding application specific variablesTailoring the softwareDocumenting event segment packet typesAdding commands