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

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

Parameters
loutthe ostream to which errors and debug output is redirected
serverThe name of the server to which the command should be send, e.g. DRIVE
strCommand and data, eg "TRACK 12.5 13.8"
Returns
If parsing the string was successfull and the command exists in the network true is returned, false otherwise.

Definition at line 732 of file ServiceList.cc.

References GetFormat(), Converter::GetVector(), HasService(), kBlue, kGreen, kRed, and DimClient::sendCommand().

Referenced by DumpServiceList(), and SendDimCommand().

733 {
734  // Find the delimiter between the command name and the data
735  size_t p0 = str.find_first_of(' ');
736  if (p0==string::npos)
737  p0 = str.length();
738 
739  // Get just the command name separated from the data
740  const string name = str.substr(0, p0);
741 
742  // Compile the command which will be sent to the state-machine
743  const string cmd = server + '/' + name;
744 
745  if (!HasService(server, name))
746  {
747  lout << kRed << "Unkown command '" << cmd << "'" << endl;
748  return false;
749  }
750 
751  // Get the format of the event data
752  const string fmt = GetFormat(cmd);
753 
754  // Convert the user entered data according to the format string
755  // into a data block which will be attached to the event
756  const Converter conv(lout, fmt, false);
757  if (!conv)
758  {
759  lout << kRed << "Couldn't properly parse the format... ignored." << endl;
760  return false;
761  }
762 
763  try
764  {
765  lout << kBlue << cmd;
766  const vector<char> v = conv.GetVector(str.substr(p0));
767  lout << endl;
768 
769  const int rc = DimClient::sendCommand(cmd.c_str(), (void*)v.data(), v.size());
770  if (rc)
771  lout << kGreen << "Command " << cmd << " emitted successfully to DimClient." << endl;
772  else
773  lout << kRed << "ERROR - Sending command " << cmd << " failed." << endl;
774  }
775  catch (const std::runtime_error &e)
776  {
777  lout << endl << kRed << e.what() << endl;
778  return false;
779  }
780 
781  return true;
782 }
static int sendCommand(const char *name, int data)
Definition: diccpp.cxx:1098
Set color Green.
Definition: WindowLog.h:18
char str[80]
Definition: test_client.c:7
Set color Red.
Definition: WindowLog.h:17
bool HasService(const std::string &server, const std::string &service) const
Definition: ServiceList.cc:491
std::string GetFormat(const std::string &server, const std::string &name) const
Definition: ServiceList.cc:388
Set color Blue.
Definition: WindowLog.h:20
A compiler for the DIM data format string.
Definition: Converter.h:16

+ Here is the call graph for this function:

+ Here is the caller graph for this function: