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

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