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

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