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

Last change on this file since 14641 was 14621, checked in by tbretz, 12 years ago
Switch off console mode for server.
File size: 3.6 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.Get<bool>("server");
14 return Main::execute<T, StateMachineDimControl>(conf);
15}
16
17void SetupConfiguration(Configuration &conf)
18{
19 po::options_description control("Dim control options");
20 control.add_options()
21 ("server", po_bool(false), "Start dimctrl as a dim server (console mode switched off)")
22 ("force-console",po_switch(), "Forces console mode in server-mode.")
23 // ("verbosity,v", var<uint32_t>()->implicit_value(0), "Set a new verbosity level (see MessageImp)")
24 // ("quiet,q", po_bool(false), "Suppress all output except comments (log-level>=90)")
25 ("debug", po_bool(false), "Print the labels for debugging purpose")
26 ("start", var<string>(), "Start a java script with the given name on the dimctrl-server")
27 ("batch", var<string>(), "Start a batch script with the given name at the given label (script.dim[:N]) on the dimctrl-server")
28 ("stop", po_switch(), "Stop a currently running script on the dimctrl-server")
29 ("msg", var<string>(), "Send a message to the chat server.")
30 ("user,u", var<string>(""), "A user name - just for logging purposes (default is ${USER})")
31 ;
32
33 conf.AddEnv("user", "USER");
34
35 conf.AddOptions(control);
36}
37
38/*
39 Extract usage clause(s) [if any] for SYNOPSIS.
40 Translators: "Usage" and "or" here are patterns (regular expressions) which
41 are used to match the usage synopsis in program output. An example from cp
42 (GNU coreutils) which contains both strings:
43 Usage: cp [OPTION]... [-T] SOURCE DEST
44 or: cp [OPTION]... SOURCE... DIRECTORY
45 or: cp [OPTION]... -t DIRECTORY SOURCE...
46 */
47void PrintUsage()
48{
49 cout <<
50 "The feedback control the BIAS voltages based on the calibration signal.\n"
51 "\n"
52 "The default is that the program is started without user intercation. "
53 "All actions are supposed to arrive as DimCommands. Using the -c "
54 "option, a local shell can be initialized. With h or help a short "
55 "help message about the usuage can be brought to the screen.\n"
56 "\n"
57 "Usage: feedback [-c type] [OPTIONS]\n"
58 " or: feedback [OPTIONS]\n";
59 cout << endl;
60}
61
62void PrintHelp()
63{
64 Main::PrintHelp<StateMachineDimControl>();
65
66 /* Additional help text which is printed after the configuration
67 options goes here */
68
69 /*
70 cout << "bla bla bla" << endl << endl;
71 cout << endl;
72 cout << "Environment:" << endl;
73 cout << "environment" << endl;
74 cout << endl;
75 cout << "Examples:" << endl;
76 cout << "test exam" << endl;
77 cout << endl;
78 cout << "Files:" << endl;
79 cout << "files" << endl;
80 cout << endl;
81 */
82}
83
84int main(int argc, const char* argv[])
85{
86 Configuration conf(argv[0]);
87 conf.SetPrintUsage(PrintUsage);
88 Main::SetupConfiguration(conf);
89 SetupConfiguration(conf);
90
91 if (!conf.DoParse(argc, argv, PrintHelp))
92 return 127;
93
94 if (conf.Get<bool>("force-console") && !conf.Has("console"))
95 throw runtime_error("--force-console must be used with --console/-c");
96
97 if ((!conf.Has("console") || conf.Get<bool>("server")) && !conf.Get<bool>("force-console"))
98 return RunShell<RemoteStream>(conf);
99
100 if (conf.Get<int>("console")==0)
101 return RunShell<RemoteShell>(conf);
102 else
103 return RunShell<RemoteConsole>(conf);
104}
Note: See TracBrowser for help on using the repository browser.