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

Definition at line 166 of file StateMachineDimControl.cc.

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

Referenced by RemoteControl< Shell >::SendDimCommand().

167 {
168  const lock_guard<mutex> guard(fMutex);
169 
170  if (fServerList.find(server)==fServerList.end())
171  throw runtime_error("SendDimCommand - Server '"+server+"' not online.");
172 
173  str = Tools::Trim(str);
174 
175  // Find the delimiter between the command name and the data
176  size_t p0 = str.find_first_of(' ');
177  if (p0==string::npos)
178  p0 = str.length();
179 
180  // Get just the command name separated from the data
181  const string name = str.substr(0, p0);
182 
183  // Compile the command which will be sent to the state-machine
184  for (auto is=fServiceList.begin(); is!=fServiceList.end(); is++)
185  {
186  if (str.empty() && is->server==server)
187  return true;
188 
189  if (is->server!=server || is->service!=name)
190  continue;
191 
192  if (!is->iscmd)
193  throw runtime_error("'"+server+"/"+name+" not a command.");
194 
195  // Avoid compiler warning of unused parameter
196  lout << flush;
197 
198  // Convert the user entered data according to the format string
199  // into a data block which will be attached to the event
200 #ifndef DEBUG
201  ostringstream sout;
202  const Converter conv(sout, is->format, false);
203 #else
204  const Converter conv(lout, is->format, false);
205 #endif
206  if (!conv)
207  throw runtime_error("Couldn't properly parse the format... ignored.");
208 
209 #ifdef DEBUG
210  lout << kBlue << server << '/' << name;
211 #endif
212  const vector<char> v = conv.GetVector(str.substr(p0));
213 #ifdef DEBUG
214  lout << kBlue << " [" << v.size() << "]" << endl;
215 #endif
216  const string cmd = server + '/' + name;
217  const int rc = DimClient::sendCommand(cmd.c_str(), (void*)v.data(), v.size());
218  if (!rc)
219  throw runtime_error("ERROR - Sending command "+cmd+" failed.");
220 
221  return true;
222  }
223 
224  if (!str.empty())
225  throw runtime_error("SendDimCommand - Format information for "+server+"/"+name+" not yet available.");
226 
227  return false;
228 }
static int sendCommand(const char *name, int data)
Definition: diccpp.cxx:1098
char str[80]
Definition: test_client.c:7
Set color Blue.
Definition: WindowLog.h:20
std::set< Service > fServiceList
std::string Trim(const std::string &str)
Definition: tools.cc:68
A compiler for the DIM data format string.
Definition: Converter.h:16
std::set< std::string > fServerList

+ Here is the call graph for this function:

+ Here is the caller graph for this function: