Ignore:
Timestamp:
05/11/11 19:04:19 (14 years ago)
Author:
tbretz
Message:
Adapted to the internal structure of all other programs.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/sendcommand.cc

    r10624 r10670  
    22#include <dic.hxx>
    33
     4#include "FACT.h"
     5#include "Dim.h"
    46#include "Configuration.h"
    57
    68using namespace std;
    79
    8 
    9 
    1010void SetupConfiguration(Configuration &conf)
    1111{
    12     const string n = conf.GetName()+".log";
    13 
    14     //po::options_description config("Program options");
    1512    po::options_description config("Configuration");
    1613    config.add_options()
    17         ("dns",       var<string>("localhost"),  "Dim nameserver host name (Overwites DIM_DNS_NODE environment variable)")
    18         ("log,l",     var<string>(n), "Write log-file")
    19         //("no-dim,d",  po_switch(),    "Disable dim services")
    20         //("console,c", var<int>(),     "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
    21         ("dbname",    var<string>(),      "database name for scheduling preview")
     14        ("dns",               var<string>("localhost"),  "Dim nameserver host name (Overwites DIM_DNS_NODE environment variable)")
     15        ("schedule-database", var<string>(),  "Database name for scheduling preview")
    2216        ;
    2317
     18    po::positional_options_description p;
     19    p.add("schedule-database", 1); // The first positional options
     20
    2421    conf.AddEnv("dns", "DIM_DNS_NODE");
    25 
    2622    conf.AddOptions(config);
     23    conf.SetArgumentPositions(p);
    2724}
    2825
     26void PrintUsage()
     27{
     28    cout <<
     29        "The triggerschedule triggers the scheduler.\n"
     30        "\n"
     31        "The default is that the program is started without user intercation. "
     32        "All actions are supposed to arrive as DimCommands. Using the -c "
     33        "option, a local shell can be initialized. With h or help a short "
     34        "help message about the usuage can be brought to the screen.\n"
     35        "\n"
     36        "Usage: triggerschedule [-c type] [OPTIONS] <schedule-database>\n"
     37        "  or:  triggerschedule [OPTIONS] <schedule-database>\n";
     38    cout << endl;
     39}
    2940
     41void PrintHelp()
     42{
     43    cout <<
     44        "\n"
     45        "The method sendCommand(...) will wait for the command to "
     46        "be actualy sent to the server and return a completion code "
     47        "of:\n"
     48        " 1 - if it was successfully sent.\n"
     49        " 0 - if it couldn't be delivered.\n "
     50        << endl;
     51    /* Additional help text which is printed after the configuration
     52     options goes here */
     53}
    3054
    3155int main(int argc, const char* argv[])
    3256{
    3357    Configuration conf(argv[0]);
     58    conf.SetPrintUsage(PrintUsage);
    3459    SetupConfiguration(conf);
    3560
     
    5378    }
    5479
    55     const char* dbname;
    56     if (conf.Has("dbname"))
    57         dbname = conf.Get<string>("dbname").c_str();
    58     else
     80    if (conf.HasPrint())
     81        return -1;
     82
     83    if (conf.HasVersion())
    5984    {
    60         cout << "Please provide which database you want to use for scheduling using --dbname=<dbname>." << endl;
     85        FACT::PrintVersion(argv[0]);
    6186        return -1;
    6287    }
    6388
     89    if (conf.HasHelp())
     90    {
     91        PrintHelp();
     92        return -1;
     93    }
    6494
    65     if (conf.HasHelp() || conf.HasPrint())
     95    if (!conf.Has("schedule-database"))
     96    {
     97        cout << "Please provide which database you want to use for scheduling using --schedule-database=<dbname>." << endl;
    6698        return -1;
     99    }
    67100
    68     // To allow overwriting of DIM_DNS_NODE set 0 to 1
    69     setenv("DIM_DNS_NODE", conf.Get<string>("dns").c_str(), 1);
     101    const char* dbname = conf.Get<string>("schedule-database").c_str();
    70102
    71 //int main ()
    72 //{
     103    Dim::Setup(conf.Get<string>("dns"));
    73104
    74     int value;
     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;
    75110
    76     value = DimClient::sendCommand("SCHEDULER/SCHEDULE", dbname);
    77     //value = DimClient::sendCommand("SCHEDULER/SCHEDULE", NULL, 0);
    78 
    79     cout << "\n";
    80     cout << " The method sendCommand(...) will wait for the command to be actualy sent to the Server and return a completion code of : " << endl;
    81     cout << "                                   1 - if it was successfully sent  " << endl;
    82     cout << "                                   0 - if it couldn't be delivered. " << endl;
    83 
    84     cout << "\n";
    85     cout << " The completion code is now:       " << value << endl;
    86 
    87     return 0;
    88 
     111    return rc;
    89112}
Note: See TracChangeset for help on using the changeset viewer.