Changeset 14674


Ignore:
Timestamp:
11/20/12 19:57:27 (12 years ago)
Author:
tbretz
Message:
Implemenetd a way to just check if a server is available and command descriptions have been received.
Location:
trunk/FACT++/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/InterpreterV8.cc

    r14672 r14674  
    217217    string command = *str;
    218218
     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
    219228    // Escape all string arguments. All others can be kept as they are.
    220229    for (int i=1; i<args.Length(); i++)
     
    233242    }
    234243
    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
    236253}
    237254
  • trunk/FACT++/src/RemoteControl.cc

    r14543 r14674  
    33// ==========================================================================
    44
    5 bool RemoteControlImp::ProcessCommand(const std::string &str)
     5bool RemoteControlImp::ProcessCommand(const std::string &str, bool change)
    66{
    77    if (fCurrentServer.empty())
     
    1010        const size_t p2 = str.find_first_of('/');
    1111
     12        const bool is_cmd = p2!=string::npos && p1>p2;
     13
    1214        string s = str;
    13         if (p2!=string::npos && p1>p2)
     15        if (is_cmd)
    1416            s = str.substr(0, p2);
    1517
     
    1719        {
    1820            const string c = str.substr(p2+1);
    19             return !SendDimCommand(lout, s, c);
     21            return SendDimCommand(lout, s, c, !change);
    2022        }
    2123
    2224        if (HasServer(s))
    2325        {
     26            if (!change)
     27                return SendDimCommand(lout, str, "", !change);
     28
    2429            fCurrentServer = s;
    2530            return true;
    2631        }
    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
    2839        return false;
    2940    }
     
    3445        return true;
    3546    }
    36 
    37     return SendDimCommand(lout, fCurrentServer, str);
     47    return SendDimCommand(lout, fCurrentServer, str, !change);
    3848}
    3949
  • trunk/FACT++/src/RemoteControl.h

    r14647 r14674  
    3434    }
    3535    virtual ~RemoteControlImp() { }
    36     bool ProcessCommand(const std::string &str);
     36    bool ProcessCommand(const std::string &str, bool change=true);
    3737
    3838    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; }
    4040};
    4141
     
    144144    int PrintDescription(std::ostream &out, bool iscmd, const std::string &serv="", const std::string &service="") const
    145145    { 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
    148151        try
    149152        {
    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;
    154154        }
    155155        catch (const runtime_error &e)
     
    165165    void  JsStart(const std::string &)        { SetSection(-2); }
    166166    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); }
    168168    void  JsOut(const std::string &msg)       { lin << msg << endl; }
    169169    void  JsPrint(const std::string &msg)     { if (fImp) fImp->Comment(msg.empty()?" ":msg); }
  • trunk/FACT++/src/StateMachineDimControl.cc

    r14668 r14674  
    133133}
    134134
    135 void StateMachineDimControl::SendDimCommand(const string &server, string str, ostream &lout)
     135bool StateMachineDimControl::SendDimCommand(const string &server, string str, ostream &lout)
    136136{
    137137    const lock_guard<mutex> guard(fMutex);
    138138
    139139    if (fServerList.find(server)==fServerList.end())
    140         throw runtime_error("Server '"+server+"' not online.");
     140        throw runtime_error("SendDimCommand - Server '"+server+"' not online.");
    141141
    142142    str = Tools::Trim(str);
     
    153153    for (auto is=fServiceList.begin(); is!=fServiceList.end(); is++)
    154154    {
     155        if (str.empty() && is->server==server)
     156            return true;
     157
    155158        if (is->server!=server || is->service!=name)
    156159            continue;
     
    185188            throw runtime_error("ERROR - Sending command "+cmd+" failed.");
    186189
    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;
    191197}
    192198
  • trunk/FACT++/src/StateMachineDimControl.h

    r14662 r14674  
    6666    State GetServerState(const std::string &server);
    6767
    68     void SendDimCommand(const std::string &server, std::string str, std::ostream &lout);
     68    bool SendDimCommand(const std::string &server, std::string str, std::ostream &lout);
    6969
    7070    void SetStateCallback(const std::function<void(const std::string &, const State &)> &func) { fStateCallback = func; }
Note: See TracChangeset for help on using the changeset viewer.