source: trunk/FACT++/src/dimctrl.cc@ 11577

Last change on this file since 11577 was 11575, checked in by tbretz, 14 years ago
Moved common option setup to Main.h; created Main namespace
File size: 2.8 KB
Line 
1#include "Dim.h"
2#include "Configuration.h"
3#include "RemoteControl.h"
4
5using namespace std;
6
7template <class T>
8void RunShell(Configuration &conf)
9{
10 // A normal kill will call its destructor! (Very nice feature ;) )
11 static T shell(conf.GetName().c_str(), conf.Get<int>("console")!=1);
12
13 WindowLog &win = shell.GetStreamIn();
14 WindowLog &wout = shell.GetStreamOut();
15
16 if (conf.Has("log"))
17 if (!wout.OpenLogFile(conf.Get<string>("log")))
18 win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
19
20 const vector<string> v1 = conf.Vec<string>("cmd");
21 for (vector<string>::const_iterator it=v1.begin(); it!=v1.end(); it++)
22 shell.ProcessLine(*it);
23
24 const vector<string> v2 = conf.Vec<string>("exec");
25 for (vector<string>::const_iterator it=v2.begin(); it!=v2.end(); it++)
26 shell.Execute(*it);
27
28 if (conf.Get<bool>("quit"))
29 shell.Stop();
30
31 shell.Run();
32}
33
34
35// ========================================================================
36
37/*
38 Extract usage clause(s) [if any] for SYNOPSIS.
39 Translators: "Usage" and "or" here are patterns (regular expressions) which
40 are used to match the usage synopsis in program output. An example from cp
41 (GNU coreutils) which contains both strings:
42 Usage: cp [OPTION]... [-T] SOURCE DEST
43 or: cp [OPTION]... SOURCE... DIRECTORY
44 or: cp [OPTION]... -t DIRECTORY SOURCE...
45 */
46void PrintUsage()
47{
48 cout << "\n"
49 "The console connects to all available Dim Servers and allows to "
50 "easily access all of their commands.\n"
51 "\n"
52 "Usage: dimctrl [-c type] [OPTIONS]\n"
53 " or: dimctrl [OPTIONS]\n";
54 cout << endl;
55
56}
57
58void PrintHelp()
59{
60 /* Additional help text which is printed after the configuration
61 options goes here */
62}
63
64#include "Main.h"
65
66int main(int argc, const char *argv[])
67{
68 Configuration conf(argv[0]);
69 conf.SetPrintUsage(PrintUsage);
70 Main::SetupConfiguration(conf);
71
72 po::variables_map vm;
73 try
74 {
75 vm = conf.Parse(argc, argv);
76 }
77#if BOOST_VERSION > 104000
78 catch (po::multiple_occurrences &e)
79 {
80 cerr << "Program options invalid due to: " << e.what() << " of '" << e.get_option_name() << "'." << endl;
81 return -1;
82 }
83#endif
84 catch (exception& e)
85 {
86 cerr << "Program options invalid due to: " << e.what() << endl;
87 return -1;
88 }
89
90 if (conf.HasVersion() || conf.HasPrint())
91 return -1;
92
93 if (conf.HasHelp())
94 {
95 PrintHelp();
96 return -1;
97 }
98
99 Dim::Setup(conf.Get<string>("dns"), conf.Get<string>("host"));
100
101 if (conf.Get<int>("console")==0)
102 //Main<RemoteShell, DummyService>(conf);
103 RunShell<RemoteShell>(conf);
104 else
105 //Main<RemoteConsole, DummyService>(conf);
106 RunShell<RemoteConsole>(conf);
107
108
109 return 0;
110}
Note: See TracBrowser for help on using the repository browser.