source: trunk/FACT++/src/triggerschedule.cc @ 11021

Last change on this file since 11021 was 11021, checked in by tbretz, 8 years ago
Changed name from schedule-database to schedule-database-name
File size: 2.8 KB
Line 
1#include <iostream>
2#include <dic.hxx>
3
4#include "Dim.h"
5#include "Configuration.h"
6
7using namespace std;
8
9void SetupConfiguration(Configuration &conf)
10{
11    po::options_description config("Configuration");
12    config.add_options()
13        ("dns",                    var<string>("localhost"),  "Dim nameserver host name (Overwites DIM_DNS_NODE environment variable)")
14        ("schedule-database-name", var<string>("")
15#if BOOST_VERSION >= 104200
16         ->required()
17#endif
18                                                      , "Database name for scheduling preview")
19        ;
20
21    po::positional_options_description p;
22    p.add("schedule-database-name", 1); // The first positional options
23
24    conf.AddEnv("dns", "DIM_DNS_NODE");
25    conf.AddOptions(config);
26    conf.SetArgumentPositions(p);
27}
28
29void PrintUsage()
30{
31    cout <<
32        "The triggerschedule triggers the scheduler.\n"
33        "\n"
34        "The default is that the program is started without user intercation. "
35        "All actions are supposed to arrive as DimCommands. Using the -c "
36        "option, a local shell can be initialized. With h or help a short "
37        "help message about the usuage can be brought to the screen.\n"
38        "\n"
39        "Usage: triggerschedule [-c type] [OPTIONS] <schedule-database-name>\n"
40        "  or:  triggerschedule [OPTIONS] <schedule-database-name>\n";
41    cout << endl;
42}
43
44void PrintHelp()
45{
46    cout <<
47        "\n"
48        "The method sendCommand(...) will wait for the command to "
49        "be actualy sent to the server and return a completion code "
50        "of:\n"
51        " 0 - if it was successfully sent.\n"
52        " 1 - if it couldn't be delivered.\n "
53        << endl;
54    /* Additional help text which is printed after the configuration
55     options goes here */
56}
57
58int main(int argc, const char* argv[])
59{
60    Configuration conf(argv[0]);
61    conf.SetPrintUsage(PrintUsage);
62    SetupConfiguration(conf);
63
64    po::variables_map vm;
65    try
66    {
67        vm = conf.Parse(argc, argv);
68    }
69#if BOOST_VERSION > 104000
70    catch (po::multiple_occurrences &e)
71    {
72        cout << "Error: " << e.what() << " of '" << e.get_option_name() << "' option." << endl;
73        cout << endl;
74        return -1;
75    }
76#endif
77    catch (std::exception &e)
78    {
79        cout << "Error: " << e.what() << endl;
80        cout << endl;
81
82        return -1;
83    }
84
85    if (conf.HasVersion() || conf.HasPrint())
86        return -1;
87
88    if (conf.HasHelp())
89    {
90        PrintHelp();
91        return -1;
92    }
93
94    const string dbname = conf.Get<string>("schedule-database");
95
96    Dim::Setup(conf.Get<string>("dns"));
97
98    const int rc = DimClient::sendCommand("SCHEDULER/SCHEDULE", dbname.c_str());
99    if (!rc)
100        cerr << "Sending failed!" << endl;
101    else
102        cout << "Command issued successfully." << endl;
103
104    return !rc;
105}
Note: See TracBrowser for help on using the repository browser.