source: trunk/FACT++/src/test3.cc@ 10221

Last change on this file since 10221 was 10221, checked in by tbretz, 11 years ago
Added the --dns option and proper environment variable mapping of DIM_DNS_NODE
File size: 2.3 KB
Line 
1#include <boost/regex.hpp>
2#include <readline/readline.h>
3
4#include "tools.h"
5#include "Time.h"
6#include "StateMachineDim.h"
7#include "MessageDim.h"
8#include "Shell.h"
9#include "ServiceList.h"
10#include "Configuration.h"
11
12using namespace std;
13
14#include "RemoteControl.h"
15
16template <class T>
17void RunShell(Configuration &conf)
18{
19 // A normal kill will call its destructor! (Very nice feature ;) )
20 static T shell(conf.GetName().c_str(), conf.Get<int>("console")!=1);
21
22 WindowLog &win = shell.GetStreamIn();
23 WindowLog &wout = shell.GetStreamOut();
24
25 if (conf.Has("log"))
26 if (!wout.OpenLogFile(conf.Get<string>("log")))
27 win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
28
29 shell.Run();
30}
31
32
33// ========================================================================
34void SetupConfiguration(Configuration &conf)
35{
36 const string n = conf.GetName()+".log";
37
38 po::options_description config("Program options");
39 config.add_options()
40 ("dns", var<string>("localhost"), "Dim nameserver host name (Overwites DIM_DNS_NODE environment variable)")
41 ("log,l", var<string>(n), "Write log-file")
42 ("console,c", var<int>(), "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
43 ;
44
45 conf.AddEnv("dns", "DIM_DNS_NODE");
46
47 conf.AddOptions(config);
48}
49
50int main(int argc, char *argv[])
51{
52 cout << "Starting " << argv[0] << "..." << endl;
53
54 Configuration conf(argv[0]);
55 SetupConfiguration(conf);
56
57 po::variables_map vm;
58 try
59 {
60 vm = conf.Parse(argc, argv);
61 }
62 catch (std::exception &e)
63 {
64 po::multiple_occurrences *MO = dynamic_cast<po::multiple_occurrences*>(&e);
65 if (MO)
66 cout << "Error: " << e.what() << " of '" << MO->get_option_name() << "' option." << endl;
67 else
68 cout << "Error: " << e.what() << endl;
69 cout << endl;
70
71 return -1;
72 }
73
74 if (conf.HasHelp() || conf.HasPrint())
75 return -1;
76
77 // To allow overwriting of DIM_DNS_NODE set 0 to 1
78 setenv("DIM_DNS_NODE", conf.Get<string>("dns").c_str(), 1);
79
80 if (conf.Get<int>("console")==0)
81 RunShell<RemoteShell>(conf);
82 else
83 RunShell<RemoteConsole>(conf);
84
85
86 return 0;
87}
Note: See TracBrowser for help on using the repository browser.