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

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