Changeset 14741
- Timestamp:
- 12/08/12 13:29:00 (12 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/InterpreterV8.cc
r14709 r14741 433 433 } 434 434 435 Handle<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 435 466 // ========================================================================== 436 467 // Internal functions … … 441 472 // function is called. Prints its arguments on stdout separated by 442 473 // spaces and ending with a newline. 443 Handle<Value> InterpreterV8::Func Print(const Arguments& args)474 Handle<Value> InterpreterV8::FuncLog(const Arguments& args) 444 475 { 445 476 for (int i=0; i<args.Length(); i++) … … 1926 1957 // Create a template for the global object. 1927 1958 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); 1934 1966 1935 1967 Handle<ObjectTemplate> dimctrl = ObjectTemplate::New(); -
trunk/FACT++/src/InterpreterV8.h
r14709 r14741 67 67 v8::Handle<v8::Value> FuncThread(const v8::Arguments& args); 68 68 v8::Handle<v8::Value> FuncKill(const v8::Arguments& args); 69 v8::Handle<v8::Value> Func Print(const v8::Arguments& args);69 v8::Handle<v8::Value> FuncLog(const v8::Arguments& args); 70 70 v8::Handle<v8::Value> FuncAlarm(const v8::Arguments& args); 71 71 v8::Handle<v8::Value> FuncOut(const v8::Arguments& args); … … 76 76 v8::Handle<v8::Value> FuncSetState(const v8::Arguments& args); 77 77 v8::Handle<v8::Value> FuncGetState(const v8::Arguments& args); 78 v8::Handle<v8::Value> FuncGetStates(const v8::Arguments& args); 78 79 v8::Handle<v8::Value> FuncNewState(const v8::Arguments& args); 79 80 //v8::Handle<v8::Value> FuncOpen(const v8::Arguments& args); … … 113 114 static v8::Handle<v8::Value> WrapInclude(const v8::Arguments &args) { if (This) return This->FuncInclude(args); else return v8::Undefined(); } 114 115 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> Wrap Print(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(); } 116 117 static v8::Handle<v8::Value> WrapAlarm(const v8::Arguments &args) { if (This) return This->FuncAlarm(args); else return v8::Undefined(); } 117 118 static v8::Handle<v8::Value> WrapOut(const v8::Arguments &args) { if (This) return This->FuncOut(args); else return v8::Undefined(); } … … 126 127 static v8::Handle<v8::Value> WrapSetState(const v8::Arguments &args) { if (This) return This->FuncSetState(args); else return v8::Undefined(); } 127 128 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(); } 128 130 //static v8::Handle<v8::Value> WrapOpen(const v8::Arguments &args) { if (This) return This->FuncOpen(args); else return v8::Undefined(); } 129 131 static v8::Handle<v8::Value> WrapSubscription(const v8::Arguments &args){ if (This) return This->FuncSubscription(args);else return v8::Undefined(); } … … 181 183 virtual int JsGetState(const std::string &) const { return -2; } 182 184 virtual State JsGetCurrentState() const { return State(); } 185 virtual std::vector<State> JsGetStates(const std::string &) { return std::vector<State>(); } 183 186 184 187 virtual std::vector<Description> JsDescription(const std::string &) { return std::vector<Description>(); }; -
trunk/FACT++/src/RemoteControl.h
r14721 r14741 174 174 bool JsSetState(int s) { if (!fImp || fImp->GetCurrentState()<2) return false; SetSection(s-4); return true; } 175 175 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>(); } 176 177 State JsGetCurrentState() const 177 178 { … … 186 187 return fImp && fImp->AddStateName(s, n, c); 187 188 } 188 189 189 190 190 /* -
trunk/FACT++/src/StateMachineDimControl.cc
r14718 r14741 445 445 } 446 446 447 vector<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 447 464 448 465 int StateMachineDimControl::HandleAddService(const Service &svc) … … 506 523 fScriptUser = fUser; 507 524 525 // FIXME: Check fUser for quotes! 526 508 527 const map<string, string> &js = conf.GetOptions<string>("JavaScript."); 509 528 for (auto it=js.begin(); it!=js.end(); it++) … … 555 574 556 575 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; 558 577 559 578 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; 561 580 562 581 if (conf.Has("msg")) -
trunk/FACT++/src/StateMachineDimControl.h
r14718 r14741 60 60 std::vector<std::string> GetCommandList(); 61 61 std::vector<Description> GetDescription(const std::string &service); 62 std::vector<State> GetStates(const std::string &server); 63 62 64 63 65 int PrintStates(std::ostream &out, const std::string &serv="");
Note:
See TracChangeset
for help on using the changeset viewer.