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

Last change on this file since 10216 was 10183, checked in by tbretz, 14 years ago
New import.
File size: 2.1 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("Configuration");
39 config.add_options()
40 ("log,l", var<string>(n), "Write log-file")
41 ("console,c", var<int>(), "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
42 ;
43
44 conf.AddOptionsCommandline(config);
45}
46
47int main(int argc, char *argv[])
48{
49 cout << "Starting " << argv[0] << "..." << endl;
50
51 // We could use putenv to make the Configure class change the value...
52 setenv("DIM_DNS_NODE", "localhost", 0);
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 if (conf.Get<int>("console")==0)
78 RunShell<RemoteShell>(conf);
79 else
80 RunShell<RemoteConsole>(conf);
81
82
83 return 0;
84}
Note: See TracBrowser for help on using the repository browser.