FACT++  1.0
void DimServiceInfoList::SendDimCommand ( const std::string &  server,
std::string  str,
std::ostream &  lout 
) const

Tries to send a dim command according to the arguments. The command given is evaluated according to the available format string.

Parameters
serverThe name of the server to which the command should be send, e.g. DRIVE
strCommand and data, eg "TRACK 12.5 13.8"
loutthe ostream to which errors and debug output is redirected
Exceptions
runtime_errorif the server or command was not found, or if the format associated with the command could not be properly parsed, or if the command could not successfully be emitted.

Definition at line 645 of file DimServiceInfoList.cc.

References Converter::GetVector(), kBlue, DimClient::sendCommandNB(), t, and Tools::Trim().

646 {
647  str = Tools::Trim(str);
648 
649  // Find the delimiter between the command name and the data
650  size_t p0 = str.find_first_of(' ');
651  if (p0==string::npos)
652  p0 = str.length();
653 
654  // Get just the command name separated from the data
655  const string name = str.substr(0, p0);
656 
657  // Compile the command which will be sent to the state-machine
658  const string cmd = server + '/' + name;
659 
660  const ServiceList::const_iterator m = fServiceList.find(server);
661  if (m==fServiceList.end())
662  throw runtime_error("Unkown server '"+server+"'");
663 
664  const TypeList &services = m->second.first;
665 
666  const TypeList::const_iterator t = services.find(name);
667  if (t==services.end())
668  throw runtime_error("Command '"+name+"' not known on server '"+server+"'");
669 
670  if (!t->second.second)
671  throw runtime_error("'"+server+"/"+name+" not a command.");
672 
673  // Get the format of the event data
674  const string fmt = t->second.first;
675 
676  // Avoid compiler warning of unused parameter
677  lout << flush;
678 
679  // Convert the user entered data according to the format string
680  // into a data block which will be attached to the event
681 #ifndef DEBUG
682  ostringstream sout;
683  const Converter conv(sout, fmt, false);
684 #else
685  const Converter conv(lout, fmt, false);
686 #endif
687  if (!conv)
688  throw runtime_error("Couldn't properly parse the format... ignored.");
689 
690 #ifdef DEBUG
691  lout << kBlue << cmd;
692 #endif
693  const vector<char> v = conv.GetVector(str.substr(p0));
694 #ifdef DEBUG
695  lout << kBlue << " [" << v.size() << "]" << endl;
696 #endif
697 
698  DimClient::sendCommandNB(cmd.c_str(), (void*)v.data(), v.size());
699 }
std::map< const std::string, ServiceType > TypeList
ServiceList fServiceList
A map storing the service description to retrieve all informations.
char str[80]
Definition: test_client.c:7
static void sendCommandNB(const char *name, int data)
Definition: diccpp.cxx:1140
Set color Blue.
Definition: WindowLog.h:20
TT t
Definition: test_client.c:26
std::string Trim(const std::string &str)
Definition: tools.cc:68
A compiler for the DIM data format string.
Definition: Converter.h:16

+ Here is the call graph for this function: