Changeset 11575
- Timestamp:
- 07/24/11 21:00:00 (13 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Main.h
r11530 r11575 7 7 8 8 #include "LocalControl.h" 9 #include "Configuration.h" 9 10 10 void MainThread(StateMachineImp *io_service, bool dummy) 11 namespace Main 11 12 { 12 // This is necessary so that the StateMachien Thread can signal the 13 // Readline to exit 14 io_service->Run(dummy); 15 Readline::Stop(); 16 } 13 void SetupConfiguration(Configuration &conf) 14 { 15 const string n = conf.GetName()+".log"; 17 16 18 /* 19 template<class S> 20 int RunDim(Configuration &conf) 21 { 22 WindowLog wout; 17 po::options_description config("Program options"); 18 config.add_options() 19 ("dns", var<string>("localhost"), "Dim nameserver (overwites DIM_DNS_NODE environment variable)") 20 ("host", var<string>(""), "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)") 21 ("log,l", var<string>(n), "Write log-file") 22 ("console,c", var<int>(), "Use console (0=shell, 1=simple buffered, X=simple unbuffered)") 23 ("cmd", vars<string>(), "Execute one or more commands at startup") 24 ("exec,e", vars<string>(), "Execute one or more scrips at startup") 25 ("quit", po_switch(), "Quit after startup"); 26 ; 23 27 24 ReadlineColor::PrintBootMsg(wout, conf.GetName(), false); 28 conf.AddEnv("dns", "DIM_DNS_NODE"); 29 conf.AddEnv("host", "DIM_HOST_NODE"); 25 30 26 //log.SetWindow(stdscr); 27 if (conf.Has("log")) 28 if (!wout.OpenLogFile(conf.Get<string>("log"))) 29 wout << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl; 31 conf.AddOptions(config); 32 } 30 33 31 // Start io_service.Run to use the StateMachineImp::Run() loop 32 // Start io_service.run to only use the commandHandler command detaching 33 AutoScheduler<S> io_service(wout); 34 if (!io_service.EvalConfiguration(conf)) 35 return -1; 34 void Thread(StateMachineImp *io_service, bool dummy) 35 { 36 // This is necessary so that the StateMachien Thread can signal the 37 // Readline to exit 38 io_service->Run(dummy); 39 Readline::Stop(); 40 } 36 41 37 io_service.Run(); 38 39 return 0; 40 } 41 */ 42 43 template<class T, class S> 44 int Main(Configuration &conf, bool dummy=false) 45 { 46 static T shell(conf.GetName().c_str(), 42 template<class T, class S> 43 int execute(Configuration &conf, bool dummy=false) 44 { 45 static T shell(conf.GetName().c_str(), 47 46 conf.Has("console") ? conf.Get<int>("console")!=1 : 0); 48 47 49 WindowLog &win = shell.GetStreamIn();50 WindowLog &wout = shell.GetStreamOut();48 WindowLog &win = shell.GetStreamIn(); 49 WindowLog &wout = shell.GetStreamOut(); 51 50 52 const bool backlog = wout.GetBacklog();53 const bool null = wout.GetNullOutput();54 wout.SetBacklog(false);55 wout.SetNullOutput(false);56 wout.Display(true);51 const bool backlog = wout.GetBacklog(); 52 const bool null = wout.GetNullOutput(); 53 wout.SetBacklog(false); 54 wout.SetNullOutput(false); 55 wout.Display(true); 57 56 58 if (conf.Has("log"))59 if (!wout.OpenLogFile(conf.Get<string>("log")))60 win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;57 if (conf.Has("log")) 58 if (!wout.OpenLogFile(conf.Get<string>("log"))) 59 win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl; 61 60 62 S io_service(wout);61 S io_service(wout); 63 62 64 const boost::filesystem::path path(conf.GetName());63 const boost::filesystem::path path(conf.GetName()); 65 64 66 const string pname = path.parent_path().string();67 const string fname = path.filename();65 const string pname = path.parent_path().string(); 66 const string fname = path.filename(); 68 67 69 const Time now; 70 io_service.Write(now, "/----------------------- Program ------------------------"); 71 io_service.Write(now, "| Program: "PACKAGE_STRING" ("+fname+")"); 72 io_service.Write(now, "| CallPath: "+pname); 73 io_service.Write(now, "| Compiled: "__DATE__" "__TIME__); 74 io_service.Write(now, "| Revision: "REVISION); 75 io_service.Write(now, "| Contact: "PACKAGE_BUGREPORT); 76 io_service.Write(now, "| URL: "PACKAGE_URL); 77 io_service.Write(now, "| Start: "+now.GetAsStr("%c")); 78 io_service.Write(now, "\\----------------------- Options ------------------------"); 79 const multimap<string,string> mmap = conf.GetOptions(); 80 for (multimap<string,string>::const_iterator it=mmap.begin(); it!=mmap.end(); it++) 81 io_service.Write(now, ": "+it->first+(it->second.empty()?"":" = ")+it->second); 82 io_service.Write(now, "\\------------------- Evaluating options -----------------"); 83 const int rc = io_service.EvalOptions(conf); 84 if (rc>=0) 85 { 86 ostringstream str; 87 str << "Exit triggered by EvalOptions with rc=" << rc; 88 io_service.Write(now, str.str(), MessageImp::kError); 89 return rc; 90 } 91 92 const map<string,string> &wco = conf.GetWildcardOptions(); 93 if (wco.size()>0) 94 { 95 io_service.Write(now, "------------- Unrecognized wildcard options -------------", MessageImp::kWarn); 96 97 size_t max = 0; 98 for (map<string,string>::const_iterator it=wco.begin(); it!=wco.end(); it++) 99 if (it->second.length()>max) 100 max = it->second.length(); 101 102 for (map<string,string>::const_iterator it=wco.begin(); it!=wco.end(); it++) 68 const Time now; 69 io_service.Write(now, "/----------------------- Program ------------------------"); 70 io_service.Write(now, "| Program: "PACKAGE_STRING" ("+fname+")"); 71 io_service.Write(now, "| CallPath: "+pname); 72 io_service.Write(now, "| Compiled: "__DATE__" "__TIME__); 73 io_service.Write(now, "| Revision: "REVISION); 74 io_service.Write(now, "| Contact: "PACKAGE_BUGREPORT); 75 io_service.Write(now, "| URL: "PACKAGE_URL); 76 io_service.Write(now, "| Start: "+now.GetAsStr("%c")); 77 io_service.Write(now, "\\----------------------- Options ------------------------"); 78 const multimap<string,string> mmap = conf.GetOptions(); 79 for (multimap<string,string>::const_iterator it=mmap.begin(); it!=mmap.end(); it++) 80 io_service.Write(now, ": "+it->first+(it->second.empty()?"":" = ")+it->second); 81 io_service.Write(now, "\\------------------- Evaluating options -----------------"); 82 const int rc = io_service.EvalOptions(conf); 83 if (rc>=0) 103 84 { 104 85 ostringstream str; 105 str .setf(ios_base::left);106 str << setw(max+1) << it->second << " : " << it->first;107 io_service.Write(now, str.str(), MessageImp::kWarn);86 str << "Exit triggered by EvalOptions with rc=" << rc; 87 io_service.Write(now, str.str(), MessageImp::kError); 88 return rc; 108 89 } 109 io_service.Write(now, "Unrecognized options found, will exit with rc=127", MessageImp::kError); 110 return 127; 90 91 const map<string,string> &wco = conf.GetWildcardOptions(); 92 if (wco.size()>0) 93 { 94 io_service.Write(now, "------------- Unrecognized wildcard options -------------", MessageImp::kWarn); 95 96 size_t max = 0; 97 for (map<string,string>::const_iterator it=wco.begin(); it!=wco.end(); it++) 98 if (it->second.length()>max) 99 max = it->second.length(); 100 101 for (map<string,string>::const_iterator it=wco.begin(); it!=wco.end(); it++) 102 { 103 ostringstream str; 104 str.setf(ios_base::left); 105 str << setw(max+1) << it->second << " : " << it->first; 106 io_service.Write(now, str.str(), MessageImp::kWarn); 107 } 108 io_service.Write(now, "Unrecognized options found, will exit with rc=127", MessageImp::kError); 109 return 127; 110 } 111 112 io_service.Message("==================== Starting main loop ================="); 113 114 wout.SetNullOutput(null); 115 wout.SetBacklog(backlog); 116 117 shell.SetReceiver(io_service); 118 119 // boost::thread t(boost::bind(&AutoScheduler<S>::Run, &io_service)); 120 thread t(bind(Main::Thread, &io_service, dummy)); 121 122 const vector<string> v1 = conf.Vec<string>("cmd"); 123 for (vector<string>::const_iterator it=v1.begin(); it!=v1.end(); it++) 124 shell.ProcessLine(*it); 125 126 const vector<string> v2 = conf.Vec<string>("exec"); 127 for (vector<string>::const_iterator it=v2.begin(); it!=v2.end(); it++) 128 shell.Execute(*it); 129 130 if (conf.Get<bool>("quit")) 131 shell.Stop(); 132 133 shell.Run(); // Run the shell 134 io_service.Stop(); // Signal Loop-thread to stop 135 // io_service.Close(); // Obsolete, done by the destructor 136 // wout << "join: " << t.timed_join(boost::posix_time::milliseconds(0)) << endl; 137 138 // Wait until the StateMachine has finished its thread 139 // before returning and destroying the dim objects which might 140 // still be in use. 141 t.join(); 142 143 return 0; 111 144 } 112 113 io_service.Message("==================== Starting main loop =================");114 115 wout.SetNullOutput(null);116 wout.SetBacklog(backlog);117 118 shell.SetReceiver(io_service);119 120 // boost::thread t(boost::bind(&AutoScheduler<S>::Run, &io_service));121 thread t(bind(MainThread, &io_service, dummy));122 123 const vector<string> v1 = conf.Vec<string>("cmd");124 for (vector<string>::const_iterator it=v1.begin(); it!=v1.end(); it++)125 shell.ProcessLine(*it);126 127 const vector<string> v2 = conf.Vec<string>("exec");128 for (vector<string>::const_iterator it=v2.begin(); it!=v2.end(); it++)129 shell.Execute(*it);130 131 if (conf.Get<bool>("quit"))132 shell.Stop();133 134 shell.Run(); // Run the shell135 io_service.Stop(); // Signal Loop-thread to stop136 // io_service.Close(); // Obsolete, done by the destructor137 // wout << "join: " << t.timed_join(boost::posix_time::milliseconds(0)) << endl;138 139 // Wait until the StateMachine has finished its thread140 // before returning and destroying the dim objects which might141 // still be in use.142 t.join();143 144 return 0;145 145 } 146 146 -
trunk/FACT++/src/biasctrl.cc
r11574 r11575 551 551 // ------------------------------------------------------------------------ 552 552 553 void RunThread(StateMachineImp *io_service)554 {555 // This is necessary so that the StateMachien Thread can signal the556 // Readline to exit557 io_service->Run();558 Readline::Stop();559 }560 561 /*562 template<class S, class T>563 int RunDim(Configuration &conf)564 {565 WindowLog wout;566 567 ReadlineColor::PrintBootMsg(wout, conf.GetName(), false);568 569 570 if (conf.Has("log"))571 if (!wout.OpenLogFile(conf.Get<string>("log")))572 wout << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;573 574 // Start io_service.Run to use the StateMachineImp::Run() loop575 // Start io_service.run to only use the commandHandler command detaching576 StateMachineBias<S, T> io_service(wout);577 if (!io_service.EvalConfiguration(conf))578 return -1;579 580 io_service.Run();581 582 return 0;583 }584 */585 586 553 #include "Main.h" 587 554 … … 589 556 int RunShell(Configuration &conf) 590 557 { 591 return Main<T, StateMachineBias<S, R>>(conf); 592 /* 593 static T shell(conf.GetName().c_str(), conf.Get<int>("console")!=1); 594 595 WindowLog &win = shell.GetStreamIn(); 596 WindowLog &wout = shell.GetStreamOut(); 597 598 if (conf.Has("log")) 599 if (!wout.OpenLogFile(conf.Get<string>("log"))) 600 win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl; 601 602 StateMachineBias<S, R> io_service(wout); 603 if (!io_service.EvalConfiguration(conf)) 604 return -1; 605 606 shell.SetReceiver(io_service); 607 608 boost::thread t(bind(RunThread, &io_service)); 609 // boost::thread t(bind(&StateMachineBias<S>::Run, &io_service)); 610 611 if (conf.Has("cmd")) 612 { 613 const vector<string> v = conf.Get<vector<string>>("cmd"); 614 for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++) 615 shell.ProcessLine(*it); 616 } 617 618 if (conf.Has("exec")) 619 { 620 const vector<string> v = conf.Get<vector<string>>("exec"); 621 for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++) 622 shell.Execute(*it); 623 } 624 625 if (conf.Get<bool>("quit")) 626 shell.Stop(); 627 628 shell.Run(); // Run the shell 629 io_service.Stop(); // Signal Loop-thread to stop 630 // io_service.Close(); // Obsolete, done by the destructor 631 632 // Wait until the StateMachine has finished its thread 633 // before returning and destroying the dim objects which might 634 // still be in use. 635 t.join(); 636 637 return 0;*/ 558 return Main::execute<T, StateMachineBias<S, R>>(conf); 638 559 } 639 560 640 561 void SetupConfiguration(Configuration &conf) 641 562 { 642 const string n = conf.GetName()+".log"; 643 644 po::options_description config("Program options"); 645 config.add_options() 646 ("dns", var<string>("localhost"), "Dim nameserver (overwites DIM_DNS_NODE environment variable)") 647 ("host", var<string>(""), "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)") 648 ("log,l", var<string>(n), "Write log-file") 649 ("no-dim,d", po_bool(), "Disable dim services") 650 ("console,c", var<int>(), "Use console (0=shell, 1=simple buffered, X=simple unbuffered)") 651 ("cmd", vars<string>(), "Execute one or more commands at startup") 652 ("exec,e", vars<string>(), "Execute one or more scrips at startup") 653 ("quit", po_switch(), "Quit after startup"); 654 ; 655 656 po::options_description control("FTM control options"); 563 po::options_description control("BIAS control options"); 657 564 control.add_options() 565 ("no-dim,d", po_bool(), "Disable dim services") 658 566 ("addr,a", var<string>("ttysS0"), "Device address of USB port to bias-power supply") 659 567 ("quiet,q", po_bool(), "Disable printing contents of all received messages (except dynamic data) in clear text.") 660 568 ; 661 569 662 conf.AddEnv("dns", "DIM_DNS_NODE");663 conf.AddEnv("host", "DIM_HOST_NODE");664 665 conf.AddOptions(config);666 570 conf.AddOptions(control); 667 571 } … … 715 619 Configuration conf(argv[0]); 716 620 conf.SetPrintUsage(PrintUsage); 621 Main::SetupConfiguration(conf); 717 622 SetupConfiguration(conf); 718 623 -
trunk/FACT++/src/datalogger.cc
r11574 r11575 2394 2394 int RunShell(Configuration &conf) 2395 2395 { 2396 return Main <T, DataLogger>(conf, true);2396 return Main::execute<T, DataLogger>(conf, true); 2397 2397 } 2398 2398 … … 2445 2445 void SetupConfiguration(Configuration &conf) 2446 2446 { 2447 const string n = conf.GetName()+".log";2448 2449 po::options_description configp("Program options");2450 configp.add_options()2451 ("dns", var<string>("localhost"), "Dim nameserver (overwites DIM_DNS_NODE environment variable)")2452 ("host", var<string>(""), "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")2453 ("log,l", var<string>(n), "Write log-file")2454 ("console,c", var<int>(), "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")2455 ("cmd", vars<string>(), "Execute one or more commands at startup")2456 ("exec,e", vars<string>(), "Execute one or more scrips at startup")2457 ("quit", po_switch(), "Quit after startup");2458 ;2459 2460 2447 po::options_description configs("DataLogger options"); 2461 2448 configs.add_options() … … 2471 2458 ; 2472 2459 2473 conf.AddEnv("dns", "DIM_DNS_NODE");2474 conf.AddEnv("host", "DIM_HOST_NODE");2475 2476 conf.AddOptions(configp);2477 2460 conf.AddOptions(configs); 2478 2461 } … … 2482 2465 Configuration conf(argv[0]); 2483 2466 conf.SetPrintUsage(PrintUsage); 2467 Main::SetupConfiguration(conf); 2484 2468 SetupConfiguration(conf); 2485 2469 -
trunk/FACT++/src/dimctrl.cc
r11574 r11575 34 34 35 35 // ======================================================================== 36 void SetupConfiguration(Configuration &conf)37 {38 const string n = conf.GetName()+".log";39 40 po::options_description config("Program options");41 config.add_options()42 ("dns", var<string>("localhost"), "Dim nameserver (overwites DIM_DNS_NODE environment variable)")43 ("host", var<string>(""), "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")44 ("log,l", var<string>(n), "Write log-file")45 ("console,c", var<int>(0), "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")46 ("cmd", vars<string>(), "Execute one or more commands at startup")47 ("exec,e", vars<string>(), "Execute one or more scrips at startup")48 ("quit", po_switch(), "Quit after startup");49 ;50 51 conf.AddEnv("dns", "DIM_DNS_NODE");52 conf.AddEnv("host", "DIM_HOST_NODE");53 54 conf.AddOptions(config);55 }56 36 57 37 /* … … 82 62 } 83 63 64 #include "Main.h" 65 84 66 int main(int argc, const char *argv[]) 85 67 { 86 68 Configuration conf(argv[0]); 87 69 conf.SetPrintUsage(PrintUsage); 88 SetupConfiguration(conf);70 Main::SetupConfiguration(conf); 89 71 90 72 po::variables_map vm; -
trunk/FACT++/src/drivectrl.cc
r11574 r11575 938 938 void SetupConfiguration(Configuration &conf) 939 939 { 940 const string n = conf.GetName()+".log";941 942 po::options_description config("Program options");943 config.add_options()944 ("dns", var<string>("localhost"), "Dim nameserver (overwites DIM_DNS_NODE environment variable)")945 ("host", var<string>(""), "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")946 ("log,l", var<string>(n), "Write log-file")947 ("no-dim,d", po_switch(), "Disable dim services")948 ("console,c", var<int>(), "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")949 ("cmd", vars<string>(), "Execute one or more commands at startup")950 ("exec,e", vars<string>(), "Execute one or more scrips at startup")951 ("quit", po_switch(), "Quit after startup");952 ;953 954 940 po::options_description control("FTM control options"); 955 941 control.add_options() 942 ("no-dim,d", po_switch(), "Disable dim services") 956 943 ("addr,a", var<string>("localhost:7404"), "Network address of FTM") 957 944 ("quiet,q", po_bool(), "Disable printing contents of all received messages (except dynamic data) in clear text.") 958 945 ; 959 946 960 conf.AddEnv("dns", "DIM_DNS_NODE");961 conf.AddEnv("host", "DIM_HOST_NODE");962 963 conf.AddOptions(config);964 947 conf.AddOptions(control); 965 948 } … … 1013 996 Configuration conf(argv[0]); 1014 997 conf.SetPrintUsage(PrintUsage); 998 Main::SetupConfiguration(conf); 1015 999 SetupConfiguration(conf); 1016 1000 -
trunk/FACT++/src/fadctrl.cc
r11574 r11575 1974 1974 #include "Main.h" 1975 1975 1976 /*1977 void RunThread(StateMachineImp *io_service)1978 {1979 // This is necessary so that the StateMachien Thread can signal the1980 // Readline to exit1981 io_service->Run();1982 Readline::Stop();1983 }1984 */1985 /*1986 template<class S>1987 int RunDim(Configuration &conf)1988 {1989 WindowLog wout;1990 1991 ReadlineColor::PrintBootMsg(wout, conf.GetName(), false);1992 1993 if (conf.Has("log"))1994 if (!wout.OpenLogFile(conf.Get<string>("log")))1995 wout << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;1996 1997 // Start io_service.Run to use the StateMachineImp::Run() loop1998 // Start io_service.run to only use the commandHandler command detaching1999 StateMachineFAD<S> io_service(wout);2000 if (!io_service.EvalConfiguration(conf))2001 return -1;2002 2003 io_service.Run();2004 2005 return 0;2006 }2007 */2008 2009 1976 template<class T, class S> 2010 1977 int RunShell(Configuration &conf) 2011 1978 { 2012 return Main<T, StateMachineFAD<S>>(conf); 2013 /* 2014 static T shell(conf.GetName().c_str(), conf.Get<int>("console")!=1); 2015 2016 WindowLog &win = shell.GetStreamIn(); 2017 WindowLog &wout = shell.GetStreamOut(); 2018 2019 if (conf.Has("log")) 2020 if (!wout.OpenLogFile(conf.Get<string>("log"))) 2021 win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl; 2022 2023 StateMachineFAD<S> io_service(wout); 2024 if (!io_service.EvalConfiguration(conf)) 2025 return -1; 2026 2027 shell.SetReceiver(io_service); 2028 2029 boost::thread t(bind(RunThread, &io_service)); 2030 //boost::thread t(bind(&StateMachineFAD<S>::Run, &io_service)); 2031 2032 if (conf.Has("cmd")) 2033 { 2034 const vector<string> v = conf.Get<vector<string>>("cmd"); 2035 for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++) 2036 shell.ProcessLine(*it); 2037 } 2038 2039 if (conf.Has("exec")) 2040 { 2041 const vector<string> v = conf.Get<vector<string>>("exec"); 2042 for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++) 2043 shell.Execute(*it); 2044 } 2045 2046 if (conf.Get<bool>("quit")) 2047 shell.Stop(); 2048 2049 shell.Run(); // Run the shell 2050 io_service.Stop(); // Signal Loop-thread to stop 2051 2052 // Wait until the StateMachine has finished its thread 2053 // before returning and destroying the dim objects which might 2054 // still be in use. 2055 t.join(); 2056 2057 return 0; 2058 */ 1979 return Main::execute<T, StateMachineFAD<S>>(conf); 2059 1980 } 2060 1981 2061 1982 void SetupConfiguration(Configuration &conf) 2062 1983 { 2063 const string n = conf.GetName()+".log";2064 2065 po::options_description config("Program options");2066 config.add_options()2067 ("dns", var<string>("localhost"), "Dim nameserver (overwites DIM_DNS_NODE environment variable)")2068 ("host", var<string>(""), "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")2069 ("log,l", var<string>(n), "Write log-file")2070 // ("no-dim,d", po_switch(), "Disable dim services")2071 ("console,c", var<int>(), "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")2072 ("cmd", vars<string>(), "Execute one or more commands at startup")2073 ("exec,e", vars<string>(), "Execute one or more scrips at startup")2074 ("quit", po_switch(), "Quit after startup");2075 ;2076 2077 1984 po::options_description control("FAD control options"); 2078 1985 control.add_options() … … 2128 2035 conf.AddEnv("host", "DIM_HOST_NODE"); 2129 2036 2130 conf.AddOptions(config);2131 2037 conf.AddOptions(control); 2132 2038 conf.AddOptions(connect); … … 2160 2066 Configuration conf(argv[0]); 2161 2067 conf.SetPrintUsage(PrintUsage); 2068 Main::SetupConfiguration(conf); 2162 2069 SetupConfiguration(conf); 2163 2070 -
trunk/FACT++/src/fscctrl.cc
r11574 r11575 520 520 #include "Main.h" 521 521 522 /*523 void RunThread(StateMachineImp *io_service)524 {525 // This is necessary so that the StateMachien Thread can signal the526 // Readline to exit527 io_service->Run();528 Readline::Stop();529 }530 */531 /*532 template<class S, class T>533 int RunDim(Configuration &conf)534 {535 WindowLog wout;536 537 ReadlineColor::PrintBootMsg(wout, conf.GetName(), false);538 539 540 if (conf.Has("log"))541 if (!wout.OpenLogFile(conf.Get<string>("log")))542 wout << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;543 544 // Start io_service.Run to use the StateMachineImp::Run() loop545 // Start io_service.run to only use the commandHandler command detaching546 StateMachineFSC<S, T> io_service(wout);547 if (!io_service.EvalConfiguration(conf))548 return -1;549 550 io_service.Run();551 552 return 0;553 }554 */555 556 522 template<class T, class S, class R> 557 523 int RunShell(Configuration &conf) 558 524 { 559 return Main<T, StateMachineFSC<S, R>>(conf); 560 /* 561 static T shell(conf.GetName().c_str(), conf.Get<int>("console")!=1); 562 563 WindowLog &win = shell.GetStreamIn(); 564 WindowLog &wout = shell.GetStreamOut(); 565 566 if (conf.Has("log")) 567 if (!wout.OpenLogFile(conf.Get<string>("log"))) 568 win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl; 569 570 StateMachineFSC<S, R> io_service(wout); 571 if (!io_service.EvalConfiguration(conf)) 572 return -1; 573 574 shell.SetReceiver(io_service); 575 576 boost::thread t(boost::bind(RunThread, &io_service)); 577 // boost::thread t(boost::bind(&StateMachineFSC<S>::Run, &io_service)); 578 579 if (conf.Has("cmd")) 580 { 581 const vector<string> v = conf.Get<vector<string>>("cmd"); 582 for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++) 583 shell.ProcessLine(*it); 584 } 585 586 if (conf.Has("exec")) 587 { 588 const vector<string> v = conf.Get<vector<string>>("exec"); 589 for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++) 590 shell.Execute(*it); 591 } 592 593 if (conf.Get<bool>("quit")) 594 shell.Stop(); 595 596 shell.Run(); // Run the shell 597 io_service.Stop(); // Signal Loop-thread to stop 598 // io_service.Close(); // Obsolete, done by the destructor 599 600 // Wait until the StateMachine has finished its thread 601 // before returning and destroying the dim objects which might 602 // still be in use. 603 t.join(); 604 605 return 0; 606 */ 525 return Main::execute<T, StateMachineFSC<S, R>>(conf); 607 526 } 608 527 609 528 void SetupConfiguration(Configuration &conf) 610 529 { 611 const string n = conf.GetName()+".log";612 613 po::options_description config("Program options");614 config.add_options()615 ("dns", var<string>("localhost"), "Dim nameserver (overwites DIM_DNS_NODE environment variable)")616 ("host", var<string>(""), "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")617 ("log,l", var<string>(n), "Write log-file")618 ("no-dim,d", po_bool(), "Disable dim services")619 ("console,c", var<int>(), "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")620 ("cmd", vars<string>(), "Execute one or more commands at startup")621 ("exec,e", vars<string>(), "Execute one or more scrips at startup")622 ("quit,q", po_switch(), "Quit after startup");623 ;624 625 530 po::options_description control("FTM control options"); 626 531 control.add_options() … … 629 534 ; 630 535 631 conf.AddEnv("dns", "DIM_DNS_NODE");632 conf.AddEnv("host", "DIM_HOST_NODE");633 634 conf.AddOptions(config);635 536 conf.AddOptions(control); 636 537 } … … 684 585 Configuration conf(argv[0]); 685 586 conf.SetPrintUsage(PrintUsage); 587 Main::SetupConfiguration(conf); 686 588 SetupConfiguration(conf); 687 589 -
trunk/FACT++/src/ftmctrl.cc
r11574 r11575 2331 2331 #include "Main.h" 2332 2332 2333 /*2334 void RunThread(StateMachineImp *io_service)2335 {2336 // This is necessary so that the StateMachien Thread can signal the2337 // Readline to exit2338 io_service->Run();2339 Readline::Stop();2340 }2341 */2342 /*2343 template<class S, class T>2344 int RunDim(Configuration &conf)2345 {2346 WindowLog wout;2347 2348 ReadlineColor::PrintBootMsg(wout, conf.GetName(), false);2349 2350 if (conf.Has("log"))2351 if (!wout.OpenLogFile(conf.Get<string>("log")))2352 wout << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;2353 2354 // Start io_service.Run to use the StateMachineImp::Run() loop2355 // Start io_service.run to only use the commandHandler command detaching2356 StateMachineFTM<S, T> io_service(wout);2357 if (!io_service.EvalConfiguration(conf))2358 return -1;2359 2360 io_service.Run();2361 2362 return 0;2363 }2364 */2365 2366 2333 template<class T, class S, class R> 2367 2334 int RunShell(Configuration &conf) 2368 2335 { 2369 return Main<T, StateMachineFTM<S, R>>(conf); 2370 /* 2371 static T shell(conf.GetName().c_str(), conf.Get<int>("console")!=1); 2372 2373 WindowLog &win = shell.GetStreamIn(); 2374 WindowLog &wout = shell.GetStreamOut(); 2375 2376 if (conf.Has("log")) 2377 if (!wout.OpenLogFile(conf.Get<string>("log"))) 2378 win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl; 2379 2380 StateMachineFTM<S, R> io_service(wout); 2381 if (!io_service.EvalConfiguration(conf)) 2382 return -1; 2383 2384 shell.SetReceiver(io_service); 2385 2386 boost::thread t(bind(RunThread, &io_service)); 2387 // boost::thread t(bind(&StateMachineFTM<S>::Run, &io_service)); 2388 2389 if (conf.Has("cmd")) 2390 { 2391 const vector<string> v = conf.Get<vector<string>>("cmd"); 2392 for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++) 2393 shell.ProcessLine(*it); 2394 } 2395 2396 if (conf.Has("exec")) 2397 { 2398 const vector<string> v = conf.Get<vector<string>>("exec"); 2399 for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++) 2400 shell.Execute(*it); 2401 } 2402 2403 if (conf.Get<bool>("quit")) 2404 shell.Stop(); 2405 2406 shell.Run(); // Run the shell 2407 io_service.Stop(); // Signal Loop-thread to stop 2408 // io_service.Close(); // Obsolete, done by the destructor 2409 2410 // Wait until the StateMachine has finished its thread 2411 // before returning and destroying the dim objects which might 2412 // still be in use. 2413 t.join(); 2414 2415 return 0; 2416 */ 2336 return Main::execute<T, StateMachineFTM<S, R>>(conf); 2417 2337 } 2418 2338 2419 2339 void SetupConfiguration(Configuration &conf) 2420 2340 { 2421 const string n = conf.GetName()+".log";2422 2423 po::options_description config("Program options");2424 config.add_options()2425 ("dns", var<string>("localhost"), "Dim nameserver (overwites DIM_DNS_NODE environment variable)")2426 ("host", var<string>(""), "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")2427 ("no-dim,d", po_bool(), "Disable dim services")2428 ("console,c", var<int>(), "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")2429 ("cmd", vars<string>(), "Execute one or more commands at startup")2430 ("exec,e", vars<string>(), "Execute one or more scrips at startup")2431 ("quit", po_switch(), "Quit after startup");2432 ;2433 2434 2341 po::options_description control("Control options"); 2435 2342 control.add_options() 2343 ("no-dim", po_bool(), "Disable dim services") 2436 2344 ("addr,a", var<string>("localhost:5000"), "Network address of FTM") 2437 2345 ("quiet,q", po_bool(), "Disable printing contents of all received messages (except dynamic data) in clear text.") … … 2481 2389 ; 2482 2390 2483 conf.AddEnv("dns", "DIM_DNS_NODE");2484 conf.AddEnv("host", "DIM_HOST_NODE");2485 2486 conf.AddOptions(config);2487 2391 conf.AddOptions(control); 2488 2392 conf.AddOptions(runtype); … … 2537 2441 Configuration conf(argv[0]); 2538 2442 conf.SetPrintUsage(PrintUsage); 2443 Main::SetupConfiguration(conf); 2539 2444 SetupConfiguration(conf); 2540 2445 -
trunk/FACT++/src/mcp.cc
r11574 r11575 422 422 #include "Main.h" 423 423 424 /*425 void RunThread(StateMachineImp *io_service)426 {427 // This is necessary so that the StateMachien Thread can signal the428 // Readline to exit429 io_service->Run();430 Readline::Stop();431 }432 */433 /*434 template<class S, class T>435 int RunDim(Configuration &conf)436 {437 WindowLog wout;438 439 ReadlineColor::PrintBootMsg(wout, conf.GetName(), false);440 441 442 if (conf.Has("log"))443 if (!wout.OpenLogFile(conf.Get<string>("log")))444 wout << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;445 446 // Start io_service.Run to use the StateMachineImp::Run() loop447 // Start io_service.run to only use the commandHandler command detaching448 StateMachineMCP<S, T> io_service(wout);449 if (!io_service.EvalConfiguration(conf))450 return -1;451 452 io_service.Run();453 454 return 0;455 }456 */457 458 424 template<class T> 459 425 int RunShell(Configuration &conf) 460 426 { 461 return Main<T, StateMachineMCP>(conf); 462 /* 463 static T shell(conf.GetName().c_str(), conf.Get<int>("console")!=1); 464 465 WindowLog &win = shell.GetStreamIn(); 466 WindowLog &wout = shell.GetStreamOut(); 467 468 if (conf.Has("log")) 469 if (!wout.OpenLogFile(conf.Get<string>("log"))) 470 win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl; 471 472 StateMachineMCP<S, R> io_service(wout); 473 if (!io_service.EvalConfiguration(conf)) 474 return -1; 475 476 shell.SetReceiver(io_service); 477 478 boost::thread t(bind(RunThread, &io_service)); 479 // boost::thread t(bind(&StateMachineMCP<S>::Run, &io_service)); 480 481 if (conf.Has("cmd")) 482 { 483 const vector<string> v = conf.Get<vector<string>>("cmd"); 484 for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++) 485 shell.ProcessLine(*it); 486 } 487 488 if (conf.Has("exec")) 489 { 490 const vector<string> v = conf.Get<vector<string>>("exec"); 491 for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++) 492 shell.Execute(*it); 493 } 494 495 if (conf.Get<bool>("quit")) 496 shell.Stop(); 497 498 shell.Run(); // Run the shell 499 io_service.Stop(); // Signal Loop-thread to stop 500 // io_service.Close(); // Obsolete, done by the destructor 501 502 // Wait until the StateMachine has finished its thread 503 // before returning and destroying the dim objects which might 504 // still be in use. 505 t.join(); 506 507 return 0; 508 */ 509 } 510 511 void SetupConfiguration(Configuration &conf) 512 { 513 const string n = conf.GetName()+".log"; 514 515 po::options_description config("Program options"); 516 config.add_options() 517 ("dns", var<string>("localhost"), "Dim nameserver (overwites DIM_DNS_NODE environment variable)") 518 ("host", var<string>(""), "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)") 519 ("log,l", var<string>(n), "Write log-file") 520 // ("no-dim,d", po_bool(), "Disable dim services") 521 ("console,c", var<int>(), "Use console (0=shell, 1=simple buffered, X=simple unbuffered)") 522 ("cmd", vars<string>(), "Execute one or more commands at startup") 523 ("exec,e", vars<string>(), "Execute one or more scrips at startup") 524 ("quit,q", po_switch(), "Quit after startup"); 525 ; 526 /* 527 po::options_description control("FTM control options"); 528 control.add_options() 529 ("addr,a", var<string>("localhost:5000"), "Network address of FTM") 530 ("quiet,q", po_bool(), "Disable printing contents of all received messages (except dynamic data) in clear text.") 531 ; 532 */ 533 conf.AddEnv("dns", "DIM_DNS_NODE"); 534 conf.AddEnv("host", "DIM_HOST_NODE"); 535 536 conf.AddOptions(config); 537 // conf.AddOptions(control); 427 return Main::execute<T, StateMachineMCP>(conf); 538 428 } 539 429 … … 586 476 Configuration conf(argv[0]); 587 477 conf.SetPrintUsage(PrintUsage); 588 SetupConfiguration(conf);478 Main::SetupConfiguration(conf); 589 479 590 480 po::variables_map vm; -
trunk/FACT++/src/scheduler.cc
r11574 r11575 710 710 // ------------------------------------------------------------------------ 711 711 #include "Main.h" 712 /*713 void RunThread(StateMachineImp *io_service)714 {715 // This is necessary so that the StateMachien Thread can signal the716 // Readline to exit717 io_service->Run();718 Readline::Stop();719 }720 */721 /*722 template<class S>723 int RunDim(Configuration &conf)724 {725 WindowLog wout;726 727 ReadlineColor::PrintBootMsg(wout, conf.GetName(), false);728 729 //log.SetWindow(stdscr);730 if (conf.Has("log"))731 if (!wout.OpenLogFile(conf.Get<string>("log")))732 wout << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;733 734 // Start io_service.Run to use the StateMachineImp::Run() loop735 // Start io_service.run to only use the commandHandler command detaching736 AutoScheduler<S> io_service(wout);737 if (!io_service.EvalConfiguration(conf))738 return -1;739 740 io_service.Run();741 742 return 0;743 }744 */745 712 746 713 template<class T, class S> 747 714 int RunShell(Configuration &conf) 748 715 { 749 return Main<T, AutoScheduler<S>>(conf); 750 /* 751 static T shell(conf.GetName().c_str(), conf.Get<int>("console")!=1); 752 753 WindowLog &win = shell.GetStreamIn(); 754 WindowLog &wout = shell.GetStreamOut(); 755 756 if (conf.Has("log")) 757 if (!wout.OpenLogFile(conf.Get<string>("log"))) 758 win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl; 759 760 AutoScheduler<S> io_service(wout); 761 if (!io_service.EvalConfiguration(conf)) 762 return -1; 763 764 shell.SetReceiver(io_service); 765 766 // boost::thread t(boost::bind(&AutoScheduler<S>::Run, &io_service)); 767 boost::thread t(boost::bind(RunThread, &io_service)); 768 769 if (conf.Has("cmd")) 770 { 771 const vector<string> v = conf.Get<vector<string>>("cmd"); 772 for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++) 773 shell.ProcessLine(*it); 774 } 775 776 if (conf.Has("exec")) 777 { 778 const vector<string> v = conf.Get<vector<string>>("exec"); 779 for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++) 780 shell.Execute(*it); 781 } 782 783 if (conf.Get<bool>("quit")) 784 shell.Stop(); 785 786 shell.Run(); // Run the shell 787 io_service.Stop(); // Signal Loop-thread to stop 788 // io_service.Close(); // Obsolete, done by the destructor 789 // wout << "join: " << t.timed_join(boost::posix_time::milliseconds(0)) << endl; 790 791 // Wait until the StateMachine has finished its thread 792 // before returning and destroying the dim objects which might 793 // still be in use. 794 t.join(); 795 796 return 0; 797 */ 716 return Main::execute<T, AutoScheduler<S>>(conf); 798 717 } 799 718 800 719 void SetupConfiguration(Configuration &conf) 801 720 { 802 const string n = conf.GetName()+".log";803 804 //po::options_description config("Program options");805 po::options_description config("Configuration");806 config.add_options()807 ("dns", var<string>("localhost"), "Dim nameserver (overwites DIM_DNS_NODE environment variable)")808 ("host", var<string>(""), "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")809 ("log,l", var<string>(n), "Write log-file")810 ("no-dim,d", po_switch(), "Disable dim services")811 ("console,c", var<int>(), "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")812 ("cmd", vars<string>(), "Execute one or more commands at startup")813 ("exec,e", vars<string>(), "Execute one or more scrips at startup")814 ("quit", po_switch(), "Quit after startup");815 816 721 po::options_description control("Scheduler options"); 817 722 control.add_options() 723 ("no-dim", po_switch(), "Disable dim services") 818 724 ("schedule-database", var<string>() 819 725 #if BOOST_VERSION >= 104200 … … 843 749 p.add("schedule", 1); // The first positional options 844 750 845 conf.AddEnv("dns", "DIM_DNS_NODE");846 conf.AddEnv("host", "DIM_HOST_NODE");847 848 conf.AddOptions(config);849 751 conf.AddOptions(control); 850 752 conf.SetArgumentPositions(p); … … 876 778 Configuration conf(argv[0]); 877 779 conf.SetPrintUsage(PrintUsage); 780 Main::SetupConfiguration(conf); 878 781 SetupConfiguration(conf); 879 782
Note:
See TracChangeset
for help on using the changeset viewer.