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

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