Ignore:
Timestamp:
07/24/11 21:00:00 (13 years ago)
Author:
tbretz
Message:
Moved common option setup to Main.h; created Main namespace
File:
1 edited

Legend:

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

    r11574 r11575  
    710710// ------------------------------------------------------------------------
    711711#include "Main.h"
    712 /*
    713 void RunThread(StateMachineImp *io_service)
    714 {
    715     // This is necessary so that the StateMachien Thread can signal the
    716     // Readline to exit
    717     io_service->Run();
    718     Readline::Stop();
    719 }
    720 */
    721 /*
    722 template<class S>
    723 int RunDim(Configuration &conf)
    724 {
    725     WindowLog wout;
    726 
    727     ReadlineColor::PrintBootMsg(wout, conf.GetName(), false);
    728 
    729     //log.SetWindow(stdscr);
    730     if (conf.Has("log"))
    731         if (!wout.OpenLogFile(conf.Get<string>("log")))
    732             wout << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
    733 
    734     // Start io_service.Run to use the StateMachineImp::Run() loop
    735     // Start io_service.run to only use the commandHandler command detaching
    736     AutoScheduler<S> io_service(wout);
    737     if (!io_service.EvalConfiguration(conf))
    738         return -1;
    739 
    740     io_service.Run();
    741 
    742     return 0;
    743 }
    744 */
    745712
    746713template<class T, class S>
    747714int RunShell(Configuration &conf)
    748715{
    749     return Main<T, AutoScheduler<S>>(conf);
    750     /*
    751     static T shell(conf.GetName().c_str(), conf.Get<int>("console")!=1);
    752 
    753     WindowLog &win  = shell.GetStreamIn();
    754     WindowLog &wout = shell.GetStreamOut();
    755 
    756     if (conf.Has("log"))
    757         if (!wout.OpenLogFile(conf.Get<string>("log")))
    758             win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
    759 
    760     AutoScheduler<S> io_service(wout);
    761     if (!io_service.EvalConfiguration(conf))
    762         return -1;
    763 
    764     shell.SetReceiver(io_service);
    765 
    766 //    boost::thread t(boost::bind(&AutoScheduler<S>::Run, &io_service));
    767     boost::thread t(boost::bind(RunThread, &io_service));
    768 
    769     if (conf.Has("cmd"))
    770     {
    771         const vector<string> v = conf.Get<vector<string>>("cmd");
    772         for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
    773             shell.ProcessLine(*it);
    774     }
    775 
    776     if (conf.Has("exec"))
    777     {
    778         const vector<string> v = conf.Get<vector<string>>("exec");
    779         for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
    780             shell.Execute(*it);
    781     }
    782 
    783     if (conf.Get<bool>("quit"))
    784         shell.Stop();
    785 
    786     shell.Run();                 // Run the shell
    787     io_service.Stop();           // Signal Loop-thread to stop
    788     // io_service.Close();       // Obsolete, done by the destructor
    789     // wout << "join: " << t.timed_join(boost::posix_time::milliseconds(0)) << endl;
    790 
    791     // Wait until the StateMachine has finished its thread
    792     // before returning and destroying the dim objects which might
    793     // still be in use.
    794     t.join();
    795 
    796     return 0;
    797 */
     716    return Main::execute<T, AutoScheduler<S>>(conf);
    798717}
    799718
    800719void SetupConfiguration(Configuration &conf)
    801720{
    802     const string n = conf.GetName()+".log";
    803 
    804     //po::options_description config("Program options");
    805     po::options_description config("Configuration");
    806     config.add_options()
    807         ("dns",       var<string>("localhost"),       "Dim nameserver (overwites DIM_DNS_NODE environment variable)")
    808         ("host",      var<string>(""),                "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")
    809         ("log,l",     var<string>(n), "Write log-file")
    810         ("no-dim,d",  po_switch(),    "Disable dim services")
    811         ("console,c", var<int>(),     "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
    812         ("cmd",       vars<string>(), "Execute one or more commands at startup")
    813         ("exec,e",    vars<string>(), "Execute one or more scrips at startup")
    814         ("quit",      po_switch(),    "Quit after startup");
    815 
    816721    po::options_description control("Scheduler options");
    817722    control.add_options()
     723        ("no-dim",    po_switch(),    "Disable dim services")
    818724        ("schedule-database", var<string>()
    819725#if BOOST_VERSION >= 104200
     
    843749    p.add("schedule", 1); // The first positional options
    844750
    845     conf.AddEnv("dns",  "DIM_DNS_NODE");
    846     conf.AddEnv("host", "DIM_HOST_NODE");
    847 
    848     conf.AddOptions(config);
    849751    conf.AddOptions(control);
    850752    conf.SetArgumentPositions(p);
     
    876778    Configuration conf(argv[0]);
    877779    conf.SetPrintUsage(PrintUsage);
     780    Main::SetupConfiguration(conf);
    878781    SetupConfiguration(conf);
    879782
Note: See TracChangeset for help on using the changeset viewer.