Changeset 14741


Ignore:
Timestamp:
12/08/12 13:29:00 (12 years ago)
Author:
tbretz
Message:
Added the possibility to return states of a given server back from StateMachienDimControl
Location:
trunk/FACT++/src
Files:
5 edited

Legend:

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

    r14709 r14741  
    433433}
    434434
     435Handle<Value> InterpreterV8::FuncGetStates(const Arguments& args)
     436{
     437    if (args.Length()>1)
     438        return ThrowException(String::New("getStates must not take more than one arguments."));
     439
     440    if (args.Length()==1 && !args[0]->IsString())
     441        return ThrowException(String::New("Argument must be an string."));
     442
     443    const string server = args.Length()==1 ? *String::AsciiValue(args[0]) : "DIM_CONTROL";
     444
     445    const vector<State> states = JsGetStates(server);
     446
     447    HandleScope handle_scope;
     448
     449    Handle<Object> list = Object::New();
     450    if (list.IsEmpty())
     451        return Undefined();
     452
     453    for (auto it=states.begin(); it!=states.end(); it++)
     454    {
     455        Handle<Value> entry = StringObject::New(String::New(it->name.c_str()));
     456        if (entry.IsEmpty())
     457            return Undefined();
     458
     459        StringObject::Cast(*entry)->Set(String::New("description"), String::New(it->comment.c_str()), ReadOnly);
     460        list->Set(Integer::New(it->index), entry, ReadOnly);
     461    }
     462
     463    return handle_scope.Close(list);
     464}
     465
    435466// ==========================================================================
    436467//                             Internal functions
     
    441472// function is called.  Prints its arguments on stdout separated by
    442473// spaces and ending with a newline.
    443 Handle<Value> InterpreterV8::FuncPrint(const Arguments& args)
     474Handle<Value> InterpreterV8::FuncLog(const Arguments& args)
    444475{
    445476    for (int i=0; i<args.Length(); i++)
     
    19261957    // Create a template for the global object.
    19271958    Handle<ObjectTemplate> dim = ObjectTemplate::New();
    1928     dim->Set(String::New("print"),   FunctionTemplate::New(WrapPrint), ReadOnly);
    1929     dim->Set(String::New("alarm"),   FunctionTemplate::New(WrapAlarm), ReadOnly);
    1930     dim->Set(String::New("wait"),    FunctionTemplate::New(WrapWait),  ReadOnly);
    1931     dim->Set(String::New("send"),    FunctionTemplate::New(WrapSend),  ReadOnly);
    1932     dim->Set(String::New("state"),   FunctionTemplate::New(WrapState), ReadOnly);
    1933     dim->Set(String::New("version"), Integer::New(DIM_VERSION_NUMBER), ReadOnly);
     1959    dim->Set(String::New("log"),       FunctionTemplate::New(WrapLog),       ReadOnly);
     1960    dim->Set(String::New("alarm"),     FunctionTemplate::New(WrapAlarm),     ReadOnly);
     1961    dim->Set(String::New("wait"),      FunctionTemplate::New(WrapWait),      ReadOnly);
     1962    dim->Set(String::New("send"),      FunctionTemplate::New(WrapSend),      ReadOnly);
     1963    dim->Set(String::New("state"),     FunctionTemplate::New(WrapState),     ReadOnly);
     1964    dim->Set(String::New("version"),   Integer::New(DIM_VERSION_NUMBER),     ReadOnly);
     1965    dim->Set(String::New("getStates"), FunctionTemplate::New(WrapGetStates), ReadOnly);
    19341966
    19351967    Handle<ObjectTemplate> dimctrl = ObjectTemplate::New();
  • trunk/FACT++/src/InterpreterV8.h

    r14709 r14741  
    6767    v8::Handle<v8::Value> FuncThread(const v8::Arguments& args);
    6868    v8::Handle<v8::Value> FuncKill(const v8::Arguments& args);
    69     v8::Handle<v8::Value> FuncPrint(const v8::Arguments& args);
     69    v8::Handle<v8::Value> FuncLog(const v8::Arguments& args);
    7070    v8::Handle<v8::Value> FuncAlarm(const v8::Arguments& args);
    7171    v8::Handle<v8::Value> FuncOut(const v8::Arguments& args);
     
    7676    v8::Handle<v8::Value> FuncSetState(const v8::Arguments& args);
    7777    v8::Handle<v8::Value> FuncGetState(const v8::Arguments& args);
     78    v8::Handle<v8::Value> FuncGetStates(const v8::Arguments& args);
    7879    v8::Handle<v8::Value> FuncNewState(const v8::Arguments& args);
    7980    //v8::Handle<v8::Value> FuncOpen(const v8::Arguments& args);
     
    113114    static v8::Handle<v8::Value> WrapInclude(const v8::Arguments &args)  { if (This) return This->FuncInclude(args);  else return v8::Undefined(); }
    114115    static v8::Handle<v8::Value> WrapFile(const v8::Arguments &args)     { if (This) return This->FuncFile(args);     else return v8::Undefined(); }
    115     static v8::Handle<v8::Value> WrapPrint(const v8::Arguments &args)    { if (This) return This->FuncPrint(args);    else return v8::Undefined(); }
     116    static v8::Handle<v8::Value> WrapLog(const v8::Arguments &args)      { if (This) return This->FuncLog(args);      else return v8::Undefined(); }
    116117    static v8::Handle<v8::Value> WrapAlarm(const v8::Arguments &args)    { if (This) return This->FuncAlarm(args);    else return v8::Undefined(); }
    117118    static v8::Handle<v8::Value> WrapOut(const v8::Arguments &args)      { if (This) return This->FuncOut(args);      else return v8::Undefined(); }
     
    126127    static v8::Handle<v8::Value> WrapSetState(const v8::Arguments &args) { if (This) return This->FuncSetState(args); else return v8::Undefined(); }
    127128    static v8::Handle<v8::Value> WrapGetState(const v8::Arguments &args) { if (This) return This->FuncGetState(args); else return v8::Undefined(); }
     129    static v8::Handle<v8::Value> WrapGetStates(const v8::Arguments &args){ if (This) return This->FuncGetStates(args);else return v8::Undefined(); }
    128130    //static v8::Handle<v8::Value> WrapOpen(const v8::Arguments &args)     { if (This) return This->FuncOpen(args);     else return v8::Undefined(); }
    129131    static v8::Handle<v8::Value> WrapSubscription(const v8::Arguments &args){ if (This) return This->FuncSubscription(args);else return v8::Undefined(); }
     
    181183    virtual int   JsGetState(const std::string &) const { return -2; }
    182184    virtual State JsGetCurrentState() const { return State(); }
     185    virtual std::vector<State> JsGetStates(const std::string &) { return std::vector<State>(); }
    183186
    184187    virtual std::vector<Description> JsDescription(const std::string &) { return std::vector<Description>(); };
  • trunk/FACT++/src/RemoteControl.h

    r14721 r14741  
    174174    bool  JsSetState(int s)                   { if (!fImp || fImp->GetCurrentState()<2) return false; SetSection(s-4); return true; }
    175175    int   JsGetState(const string &n) const   { return fImp ? fImp->GetStateIndex(n) : StateMachineImp::kSM_NotAvailable; }
     176    vector<State> JsGetStates(const string &server) { return fImp ? fImp->GetStates(server) : vector<State>(); }
    176177    State JsGetCurrentState() const
    177178    {
     
    186187        return fImp && fImp->AddStateName(s, n, c);
    187188    }
    188 
    189189
    190190    /*
  • trunk/FACT++/src/StateMachineDimControl.cc

    r14718 r14741  
    445445}
    446446
     447vector<State> StateMachineDimControl::GetStates(const string &server)
     448{
     449    const lock_guard<mutex> guard(fMutex);
     450
     451    vector<State> rc;
     452
     453    for (auto it=fStateDescriptionList.begin(); it!=fStateDescriptionList.end(); it++)
     454    {
     455        if (it->first.first!=server)
     456            continue;
     457
     458        rc.push_back(State(it->first.second, it->second.first, it->second.second));
     459    }
     460
     461    return rc;
     462}
     463
    447464
    448465int StateMachineDimControl::HandleAddService(const Service &svc)
     
    506523    fScriptUser = fUser;
    507524
     525    // FIXME: Check fUser for quotes!
     526
    508527    const map<string, string> &js = conf.GetOptions<string>("JavaScript.");
    509528    for (auto it=js.begin(); it!=js.end(); it++)
     
    555574
    556575    if (conf.Has("start"))
    557         return Dim::SendCommand("DIM_CONTROL/START", conf.Get<string>("start")+" user="+fUser) + 1;
     576        return Dim::SendCommand("DIM_CONTROL/START", conf.Get<string>("start")+" user='"+fUser+"'") + 1;
    558577
    559578    if (conf.Has("batch"))
    560         return Dim::SendCommand("DIM_CONTROL/EXECUTE", conf.Get<string>("batch")+" user="+fUser) + 1;
     579        return Dim::SendCommand("DIM_CONTROL/EXECUTE", conf.Get<string>("batch")+" user='"+fUser+"'") + 1;
    561580
    562581    if (conf.Has("msg"))
  • trunk/FACT++/src/StateMachineDimControl.h

    r14718 r14741  
    6060    std::vector<std::string> GetCommandList();
    6161    std::vector<Description> GetDescription(const std::string &service);
     62    std::vector<State>       GetStates(const std::string &server);
     63
    6264
    6365    int PrintStates(std::ostream &out, const std::string &serv="");
Note: See TracChangeset for help on using the changeset viewer.