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

Last change on this file since 10789 was 10765, checked in by tbretz, 13 years ago
Made it compatible with older boost versions.
File size: 2.8 KB
Line 
1#include <iostream>
2#include <dic.hxx>
3
4#include "FACT.h"
5#include "Dim.h"
6#include "Configuration.h"
7
8using namespace std;
9
10void SetupConfiguration(Configuration &conf)
11{
12 po::options_description config("Configuration");
13 config.add_options()
14 ("dns", var<string>("localhost"), "Dim nameserver host name (Overwites DIM_DNS_NODE environment variable)")
15 ("schedule-database", 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", 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>\n"
41 " or: triggerschedule [OPTIONS] <schedule-database>\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 " 1 - if it was successfully sent.\n"
53 " 0 - 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.HasPrint())
87 return -1;
88
89 if (conf.HasVersion())
90 {
91 FACT::PrintVersion(argv[0]);
92 return -1;
93 }
94
95 if (conf.HasHelp())
96 {
97 PrintHelp();
98 return -1;
99 }
100
101 const char* dbname = conf.Get<string>("schedule-database").c_str();
102
103 Dim::Setup(conf.Get<string>("dns"));
104
105 const int rc = DimClient::sendCommand("SCHEDULER/SCHEDULE", dbname);
106 if (!rc)
107 cerr << "Sending failed!" << endl;
108 else
109 cout << "Command issued successfully." << endl;
110
111 return rc;
112}
Note: See TracBrowser for help on using the repository browser.