Changeset 12964
- Timestamp:
- 02/29/12 10:06:34 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/dimctrl.cc
r12458 r12964 1 #include "Dim.h"2 #include "Configuration.h"3 1 #include "RemoteControl.h" 2 #include "Main.h" 4 3 5 4 using namespace std; 6 5 7 template <class T> 8 void RunShell(Configuration &conf) 9 { 10 // A normal kill will call its destructor! (Very nice feature ;) ) 11 static T shell(conf.GetName().c_str(), 12 conf.Has("console") ? conf.Get<int>("console")!=1 : conf.Get<bool>("null")); 6 // ======================================================================== 13 7 14 WindowLog &win = shell.GetStreamIn();15 WindowLog &wout = shell.GetStreamOut();16 17 if (conf.Has("log"))18 if (!wout.OpenLogFile(conf.Get<string>("log"), conf.Get<bool>("append-log")))19 win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;20 21 const vector<string> v1 = conf.Vec<string>("cmd");22 for (vector<string>::const_iterator it=v1.begin(); it!=v1.end(); it++)23 shell.ProcessLine(*it);24 25 const vector<string> v2 = conf.Vec<string>("exec");26 for (vector<string>::const_iterator it=v2.begin(); it!=v2.end(); it++)27 shell.Execute(*it);28 29 if (conf.Get<bool>("quit"))30 shell.Stop();31 32 shell.Run();33 }34 35 36 // ========================================================================37 8 38 9 /* … … 52 23 "\n" 53 24 "Usage: dimctrl [-c type] [OPTIONS]\n" 54 " or: dimctrl [OPTIONS]\n"; 25 " or: dimctrl [OPTIONS]\n\n"; 26 27 Main::PrintUsage(); 55 28 cout << endl; 56 57 29 } 58 30 59 31 void PrintHelp() 60 32 { 61 /* Additional help text which is printed after the configuration62 options goes here */63 33 } 64 34 65 #include "Main.h" 35 // A simple dummy state machine 36 class DimCtrl : public MainImp, public MessageImp 37 { 38 bool fStop; 39 40 public: 41 DimCtrl(ostream &out=cout) : MessageImp(out), fStop(false) 42 { 43 } 44 45 int EvalOptions(Configuration &conf) { return -1; } 46 void Stop() { fStop = true; } 47 int Run(bool) { while (!fStop) usleep(1000); return 0; } 48 }; 66 49 67 50 int main(int argc, const char *argv[]) … … 74 57 return -1; 75 58 76 Dim::Setup(conf.Get<string>("dns"), conf.Get<string>("host"));77 78 59 if (!conf.Has("console")) 79 //Main<RemoteShell, DummyService>(conf); 80 RunShell<RemoteShell>(conf); 60 return Main::execute<RemoteConsole, DimCtrl>(conf); 81 61 else 82 //Main<RemoteConsole, DummyService>(conf); 83 RunShell<RemoteConsole>(conf); 84 62 return Main::execute<RemoteShell, DimCtrl>(conf); 85 63 86 64 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.