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

Last change on this file since 11902 was 11578, checked in by tbretz, 13 years ago
Moved some part of the initialization from main to Configure::DoParse
File size: 2.3 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 if (!conf.DoParse(argc, argv, PrintHelp))
73 return -1;
74
75 Dim::Setup(conf.Get<string>("dns"), conf.Get<string>("host"));
76
77 if (conf.Get<int>("console")==0)
78 //Main<RemoteShell, DummyService>(conf);
79 RunShell<RemoteShell>(conf);
80 else
81 //Main<RemoteConsole, DummyService>(conf);
82 RunShell<RemoteConsole>(conf);
83
84
85 return 0;
86}
Note: See TracBrowser for help on using the repository browser.