FACT++  1.0
triggerschedule.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <dic.hxx>
3 
4 #include "Dim.h"
5 #include "Configuration.h"
6 
7 using namespace std;
8 
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>(), "Database name for scheduling")
15  ;
16 
17  po::positional_options_description p;
18  p.add("schedule-database-name", 1); // The first positional options
19 
20  conf.AddEnv("dns", "DIM_DNS_NODE");
21  conf.AddOptions(config);
22  conf.SetArgumentPositions(p);
23 }
24 
25 void PrintUsage()
26 {
27  cout <<
28  "The triggerschedule triggers the scheduler.\n"
29  "\n"
30  "The default is that the program is started without user intercation. "
31  "All actions are supposed to arrive as DimCommands. Using the -c "
32  "option, a local shell can be initialized. With h or help a short "
33  "help message about the usuage can be brought to the screen.\n"
34  "\n"
35  "Usage: triggerschedule [-c type] [OPTIONS] <schedule-database-name>\n"
36  " or: triggerschedule [OPTIONS] <schedule-database-name>\n";
37  cout << endl;
38 }
39 
40 void PrintHelp()
41 {
42  cout <<
43  "\n"
44  "The method sendCommand(...) will wait for the command to "
45  "be actualy sent to the server and return a completion code "
46  "of:\n"
47  " 0 - if it was successfully sent.\n"
48  " 1 - if it couldn't be delivered.\n "
49  << endl;
50  /* Additional help text which is printed after the configuration
51  options goes here */
52 }
53 
54 int main(int argc, const char* argv[])
55 {
56  Configuration conf(argv[0]);
58  SetupConfiguration(conf);
59 
60  if (!conf.DoParse(argc, argv, PrintHelp))
61  return -1;
62 
63  const string dbname = conf.Get<string>("schedule-database-name");
64 
65  Dim::Setup(conf.Get<string>("dns"));
66 
67  const int rc = DimClient::sendCommand("SCHEDULER/SCHEDULE", dbname.c_str());
68  if (!rc)
69  cerr << "Sending failed!" << endl;
70  else
71  cout << "Command issued successfully." << endl;
72 
73  return !rc;
74 }
void PrintHelp()
static int sendCommand(const char *name, int data)
Definition: diccpp.cxx:1098
void SetPrintUsage(const std::function< void(void)> &func)
T Get(const std::string &var)
STL namespace.
void AddEnv(const std::string &conf, const std::string &env)
void SetArgumentPositions(const po::positional_options_description &desc)
void Setup(const std::string &dns="", const std::string &host="")
Definition: DimSetup.cc:160
void PrintUsage()
void AddOptions(const po::options_description &opt, bool visible=true)
Definition: Configuration.h:92
int main(int argc, const char *argv[])
Commandline parsing, resource file parsing and database access.
Definition: Configuration.h:9
void SetupConfiguration(Configuration &conf)
bool DoParse(int argc, const char **argv, const std::function< void()> &func=std::function< void()>())