Changeset 14674
- Timestamp:
- 11/20/12 19:57:27 (12 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/InterpreterV8.cc
r14672 r14674 217 217 string command = *str; 218 218 219 if (command.length()==0) 220 return ThrowException(String::New("Server name empty.")); 221 222 if (args.Length()==0) 223 { 224 if (command.find_first_of('/')==string::npos) 225 command += "/"; 226 } 227 219 228 // Escape all string arguments. All others can be kept as they are. 220 229 for (int i=1; i<args.Length(); i++) … … 233 242 } 234 243 235 return Boolean::New(JsSend(command)); 244 try 245 { 246 return Boolean::New(JsSend(command)); 247 } 248 catch (const runtime_error &e) 249 { 250 return ThrowException(String::New(e.what())); 251 } 252 236 253 } 237 254 -
trunk/FACT++/src/RemoteControl.cc
r14543 r14674 3 3 // ========================================================================== 4 4 5 bool RemoteControlImp::ProcessCommand(const std::string &str )5 bool RemoteControlImp::ProcessCommand(const std::string &str, bool change) 6 6 { 7 7 if (fCurrentServer.empty()) … … 10 10 const size_t p2 = str.find_first_of('/'); 11 11 12 const bool is_cmd = p2!=string::npos && p1>p2; 13 12 14 string s = str; 13 if ( p2!=string::npos && p1>p2)15 if (is_cmd) 14 16 s = str.substr(0, p2); 15 17 … … 17 19 { 18 20 const string c = str.substr(p2+1); 19 return !SendDimCommand(lout, s, c);21 return SendDimCommand(lout, s, c, !change); 20 22 } 21 23 22 24 if (HasServer(s)) 23 25 { 26 if (!change) 27 return SendDimCommand(lout, str, "", !change); 28 24 29 fCurrentServer = s; 25 30 return true; 26 31 } 27 lout << kRed << "Unkown server '" << s << "'" << endl; 32 33 if (!change && is_cmd) 34 throw runtime_error("Unkown server '"+s+"'"); 35 36 if (change) 37 lout << kRed << "Unkown server '" << s << "'" << endl; 38 28 39 return false; 29 40 } … … 34 45 return true; 35 46 } 36 37 return SendDimCommand(lout, fCurrentServer, str); 47 return SendDimCommand(lout, fCurrentServer, str, !change); 38 48 } 39 49 -
trunk/FACT++/src/RemoteControl.h
r14647 r14674 34 34 } 35 35 virtual ~RemoteControlImp() { } 36 bool ProcessCommand(const std::string &str );36 bool ProcessCommand(const std::string &str, bool change=true); 37 37 38 38 virtual bool HasServer(const std::string &) { return false; } 39 virtual bool SendDimCommand(ostream &, std::string &, const std::string &) { return false; }39 virtual bool SendDimCommand(ostream &, const std::string &, const std::string &, bool = false) { return false; } 40 40 }; 41 41 … … 144 144 int PrintDescription(std::ostream &out, bool iscmd, const std::string &serv="", const std::string &service="") const 145 145 { return fImp ? fImp->PrintDescription(out, iscmd, serv, service) : 0; } 146 bool SendDimCommand(ostream &out, std::string &server, const std::string &str) 147 { 146 bool SendDimCommand(ostream &out, const std::string &server, const std::string &str, bool do_throw=false) 147 { 148 if (do_throw) 149 return fImp ? fImp->SendDimCommand(server, str, out) : false; 150 148 151 try 149 152 { 150 if (fImp) 151 fImp->SendDimCommand(server, str, out); 152 //lout << kGreen << "Command emitted successfully to " << server << "." << endl; 153 return true; 153 return fImp ? fImp->SendDimCommand(server, str, out) : false; 154 154 } 155 155 catch (const runtime_error &e) … … 165 165 void JsStart(const std::string &) { SetSection(-2); } 166 166 void JsEnd(const std::string &) { UnsubscribeAll(); SetSection(-4); } 167 bool JsSend(const std::string &str) { return ProcessCommand(str ); }167 bool JsSend(const std::string &str) { return ProcessCommand(str, false); } 168 168 void JsOut(const std::string &msg) { lin << msg << endl; } 169 169 void JsPrint(const std::string &msg) { if (fImp) fImp->Comment(msg.empty()?" ":msg); } -
trunk/FACT++/src/StateMachineDimControl.cc
r14668 r14674 133 133 } 134 134 135 voidStateMachineDimControl::SendDimCommand(const string &server, string str, ostream &lout)135 bool StateMachineDimControl::SendDimCommand(const string &server, string str, ostream &lout) 136 136 { 137 137 const lock_guard<mutex> guard(fMutex); 138 138 139 139 if (fServerList.find(server)==fServerList.end()) 140 throw runtime_error("Se rver '"+server+"' not online.");140 throw runtime_error("SendDimCommand - Server '"+server+"' not online."); 141 141 142 142 str = Tools::Trim(str); … … 153 153 for (auto is=fServiceList.begin(); is!=fServiceList.end(); is++) 154 154 { 155 if (str.empty() && is->server==server) 156 return true; 157 155 158 if (is->server!=server || is->service!=name) 156 159 continue; … … 185 188 throw runtime_error("ERROR - Sending command "+cmd+" failed."); 186 189 187 return; 188 } 189 190 throw runtime_error("Unkown server '"+server+"'"); 190 return true; 191 } 192 193 if (!str.empty()) 194 throw runtime_error("SendDimCommand - Format information for "+server+"/"+name+" not yet available."); 195 196 return false; 191 197 } 192 198 -
trunk/FACT++/src/StateMachineDimControl.h
r14662 r14674 66 66 State GetServerState(const std::string &server); 67 67 68 voidSendDimCommand(const std::string &server, std::string str, std::ostream &lout);68 bool SendDimCommand(const std::string &server, std::string str, std::ostream &lout); 69 69 70 70 void SetStateCallback(const std::function<void(const std::string &, const State &)> &func) { fStateCallback = func; }
Note:
See TracChangeset
for help on using the changeset viewer.