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

Last change on this file since 15345 was 15188, checked in by tbretz, 12 years ago
Fixed some compilation issues with older boost version as installed on gate.
File size: 4.2 KB
Line 
1#include "StateMachineDimControl.h"
2
3#include "RemoteControl.h"
4
5using namespace std;
6
7// ------------------------------------------------------------------------
8
9#include "Main.h"
10
11namespace fs = boost::filesystem;
12
13template<class T>
14int RunShell(Configuration &conf)
15{
16#if BOOST_VERSION < 104600
17 const string fname = fs::path(conf.GetName()).filename();
18#else
19 const string fname = fs::path(conf.GetName()).filename().string();
20#endif
21
22 StateMachineDimControl::fIsServer = fname=="dimserver";
23 return Main::execute<T, StateMachineDimControl>(conf);
24}
25
26void SetupConfiguration(Configuration &conf)
27{
28#if BOOST_VERSION < 104600
29 const string fname = fs::path(conf.GetName()).filename();
30#else
31 const string fname = fs::path(conf.GetName()).filename().string();
32#endif
33
34 po::options_description control("Options ("+fname+")");
35 control.add_options()
36 ("force-console", po_switch(), "Forces console mode in server-mode.")
37 ("debug", po_bool(false), "Print the labels for debugging purpose")
38 ("user,u", var<string>(""), "A user name - just for logging purposes (default is ${USER})")
39 ("JavaScript.*", var<string>(), "Additional arguments which are provided to JavaScripts started in a dimctrl server via the START command")
40 ;
41
42 if (fname!="dimserver")
43 {
44 control.add_options()
45 ("start", var<string>(), "Start a java script with the given name on the dimctrl-server")
46 ("batch", var<string>(), "Start a batch script with the given name at the given label (script.dim[:N]) on the dimctrl-server")
47 ("stop", po_switch(), "Stop a currently running script on the dimctrl-server")
48 ("restart", var<string>(), "Send 'EXIT 126' to the given server")
49 ("msg", var<string>(), "Send a message to the chat server.")
50 ;
51 }
52
53 conf.AddEnv("user", "USER");
54
55 conf.AddOptions(control);
56}
57
58/*
59 Extract usage clause(s) [if any] for SYNOPSIS.
60 Translators: "Usage" and "or" here are patterns (regular expressions) which
61 are used to match the usage synopsis in program output. An example from cp
62 (GNU coreutils) which contains both strings:
63 Usage: cp [OPTION]... [-T] SOURCE DEST
64 or: cp [OPTION]... SOURCE... DIRECTORY
65 or: cp [OPTION]... -t DIRECTORY SOURCE...
66 */
67void PrintUsage()
68{
69 cout <<
70 "The dim control is a central master for the dim network.\n"
71 "\n"
72 "The program can be started as a dim server, so that it is visible "
73 "in the dim network to other clients. If started as a client (dimctrl), "
74 "it can only interact passively with the dim network. The usual case "
75 "should be to have one server running (dimserver) and control it from "
76 "a dimctrl started.\n"
77 "\n"
78 "Usage: dimctrl [-c type] [OPTIONS]\n"
79 " or: dimctrl [OPTIONS]\n"
80 " or: dimserver [OPTIONS]\n";
81 cout << endl;
82}
83
84void PrintHelp()
85{
86 Main::PrintHelp<StateMachineDimControl>();
87
88 /* Additional help text which is printed after the configuration
89 options goes here */
90
91 /*
92 cout << "bla bla bla" << endl << endl;
93 cout << endl;
94 cout << "Environment:" << endl;
95 cout << "environment" << endl;
96 cout << endl;
97 cout << "Examples:" << endl;
98 cout << "test exam" << endl;
99 cout << endl;
100 cout << "Files:" << endl;
101 cout << "files" << endl;
102 cout << endl;
103 */
104}
105
106int main(int argc, const char* argv[])
107{
108 Configuration conf(argv[0]);
109 conf.SetPrintUsage(PrintUsage);
110 Main::SetupConfiguration(conf);
111 SetupConfiguration(conf);
112
113 if (!conf.DoParse(argc, argv, PrintHelp))
114 return 127;
115
116 if (conf.Get<bool>("force-console") && !conf.Has("console"))
117 throw runtime_error("--force-console must be used with --console/-c");
118
119#if BOOST_VERSION < 104600
120 const string fname = fs::path(conf.GetName()).filename();
121#else
122 const string fname = fs::path(conf.GetName()).filename().string();
123#endif
124
125 if (fname=="dimserver" && !conf.Get<bool>("force-console"))
126 conf.Remove("console");
127
128 if (!conf.Has("console"))
129 return RunShell<RemoteStream>(conf);
130
131 if (conf.Get<int>("console")==0)
132 return RunShell<RemoteShell>(conf);
133 else
134 return RunShell<RemoteConsole>(conf);
135}
Note: See TracBrowser for help on using the repository browser.