| 1 | #include "Dim.h"
|
|---|
| 2 | #include "Configuration.h"
|
|---|
| 3 | #include "RemoteControl.h"
|
|---|
| 4 |
|
|---|
| 5 | using namespace std;
|
|---|
| 6 |
|
|---|
| 7 | template <class T>
|
|---|
| 8 | void RunShell(Configuration &conf)
|
|---|
| 9 | {
|
|---|
| 10 | // A normal kill will call its destructor! (Very nice feature ;) )
|
|---|
| 11 | static T shell(conf.GetName().c_str(),
|
|---|
| 12 | conf.Has("console") ? conf.Get<int>("console")!=1 : conf.Get<bool>("null"));
|
|---|
| 13 |
|
|---|
| 14 | WindowLog &win = shell.GetStreamIn();
|
|---|
| 15 | WindowLog &wout = shell.GetStreamOut();
|
|---|
| 16 |
|
|---|
| 17 | if (conf.Has("log"))
|
|---|
| 18 | if (!wout.OpenLogFile(conf.Get<string>("log"), conf.Get<bool>("append-log")))
|
|---|
| 19 | win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
|
|---|
| 20 |
|
|---|
| 21 | const vector<string> v1 = conf.Vec<string>("cmd");
|
|---|
| 22 | for (vector<string>::const_iterator it=v1.begin(); it!=v1.end(); it++)
|
|---|
| 23 | shell.ProcessLine(*it);
|
|---|
| 24 |
|
|---|
| 25 | const vector<string> v2 = conf.Vec<string>("exec");
|
|---|
| 26 | for (vector<string>::const_iterator it=v2.begin(); it!=v2.end(); it++)
|
|---|
| 27 | shell.Execute(*it);
|
|---|
| 28 |
|
|---|
| 29 | if (conf.Get<bool>("quit"))
|
|---|
| 30 | shell.Stop();
|
|---|
| 31 |
|
|---|
| 32 | shell.Run();
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 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 | */
|
|---|
| 47 | void PrintUsage()
|
|---|
| 48 | {
|
|---|
| 49 | cout << "\n"
|
|---|
| 50 | "The console connects to all available Dim Servers and allows to "
|
|---|
| 51 | "easily access all of their commands.\n"
|
|---|
| 52 | "\n"
|
|---|
| 53 | "Usage: dimctrl [-c type] [OPTIONS]\n"
|
|---|
| 54 | " or: dimctrl [OPTIONS]\n";
|
|---|
| 55 | cout << endl;
|
|---|
| 56 |
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | void PrintHelp()
|
|---|
| 60 | {
|
|---|
| 61 | /* Additional help text which is printed after the configuration
|
|---|
| 62 | options goes here */
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | #include "Main.h"
|
|---|
| 66 |
|
|---|
| 67 | int main(int argc, const char *argv[])
|
|---|
| 68 | {
|
|---|
| 69 | Configuration conf(argv[0]);
|
|---|
| 70 | conf.SetPrintUsage(PrintUsage);
|
|---|
| 71 | Main::SetupConfiguration(conf);
|
|---|
| 72 |
|
|---|
| 73 | if (!conf.DoParse(argc, argv, PrintHelp))
|
|---|
| 74 | return -1;
|
|---|
| 75 |
|
|---|
| 76 | Dim::Setup(conf.Get<string>("dns"), conf.Get<string>("host"));
|
|---|
| 77 |
|
|---|
| 78 | if (!conf.Has("console"))
|
|---|
| 79 | //Main<RemoteShell, DummyService>(conf);
|
|---|
| 80 | RunShell<RemoteShell>(conf);
|
|---|
| 81 | else
|
|---|
| 82 | //Main<RemoteConsole, DummyService>(conf);
|
|---|
| 83 | RunShell<RemoteConsole>(conf);
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 | return 0;
|
|---|
| 87 | }
|
|---|