Changeset 11575 for trunk/FACT++


Ignore:
Timestamp:
07/24/11 21:00:00 (13 years ago)
Author:
tbretz
Message:
Moved common option setup to Main.h; created Main namespace
Location:
trunk/FACT++/src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/Main.h

    r11530 r11575  
    77
    88#include "LocalControl.h"
     9#include "Configuration.h"
    910
    10 void MainThread(StateMachineImp *io_service, bool dummy)
     11namespace Main
    1112{
    12     // This is necessary so that the StateMachien Thread can signal the
    13     // Readline to exit
    14     io_service->Run(dummy);
    15     Readline::Stop();
    16 }
     13    void SetupConfiguration(Configuration &conf)
     14    {
     15        const string n = conf.GetName()+".log";
    1716
    18 /*
    19 template<class S>
    20 int RunDim(Configuration &conf)
    21 {
    22     WindowLog wout;
     17        po::options_description config("Program options");
     18        config.add_options()
     19            ("dns",       var<string>("localhost"),       "Dim nameserver (overwites DIM_DNS_NODE environment variable)")
     20            ("host",      var<string>(""),                "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")
     21            ("log,l",     var<string>(n), "Write log-file")
     22            ("console,c", var<int>(),     "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
     23            ("cmd",       vars<string>(), "Execute one or more commands at startup")
     24            ("exec,e",    vars<string>(), "Execute one or more scrips at startup")
     25            ("quit",      po_switch(),    "Quit after startup");
     26        ;
    2327
    24     ReadlineColor::PrintBootMsg(wout, conf.GetName(), false);
     28        conf.AddEnv("dns",  "DIM_DNS_NODE");
     29        conf.AddEnv("host", "DIM_HOST_NODE");
    2530
    26     //log.SetWindow(stdscr);
    27     if (conf.Has("log"))
    28         if (!wout.OpenLogFile(conf.Get<string>("log")))
    29             wout << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
     31        conf.AddOptions(config);
     32    }
    3033
    31     // Start io_service.Run to use the StateMachineImp::Run() loop
    32     // Start io_service.run to only use the commandHandler command detaching
    33     AutoScheduler<S> io_service(wout);
    34     if (!io_service.EvalConfiguration(conf))
    35         return -1;
     34    void Thread(StateMachineImp *io_service, bool dummy)
     35    {
     36        // This is necessary so that the StateMachien Thread can signal the
     37        // Readline to exit
     38        io_service->Run(dummy);
     39        Readline::Stop();
     40    }
    3641
    37     io_service.Run();
    38 
    39     return 0;
    40 }
    41 */
    42 
    43 template<class T, class S>
    44 int Main(Configuration &conf, bool dummy=false)
    45 {
    46     static T shell(conf.GetName().c_str(),
     42    template<class T, class S>
     43    int execute(Configuration &conf, bool dummy=false)
     44    {
     45        static T shell(conf.GetName().c_str(),
    4746                   conf.Has("console") ? conf.Get<int>("console")!=1 : 0);
    4847
    49     WindowLog &win  = shell.GetStreamIn();
    50     WindowLog &wout = shell.GetStreamOut();
     48        WindowLog &win  = shell.GetStreamIn();
     49        WindowLog &wout = shell.GetStreamOut();
    5150
    52     const bool backlog = wout.GetBacklog();
    53     const bool null    = wout.GetNullOutput();
    54     wout.SetBacklog(false);
    55     wout.SetNullOutput(false);
    56     wout.Display(true);
     51        const bool backlog = wout.GetBacklog();
     52        const bool null    = wout.GetNullOutput();
     53        wout.SetBacklog(false);
     54        wout.SetNullOutput(false);
     55        wout.Display(true);
    5756
    58     if (conf.Has("log"))
    59         if (!wout.OpenLogFile(conf.Get<string>("log")))
    60             win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
     57        if (conf.Has("log"))
     58            if (!wout.OpenLogFile(conf.Get<string>("log")))
     59                win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
    6160
    62     S io_service(wout);
     61        S io_service(wout);
    6362
    64     const boost::filesystem::path path(conf.GetName());
     63        const boost::filesystem::path path(conf.GetName());
    6564
    66     const string pname = path.parent_path().string();
    67     const string fname = path.filename();
     65        const string pname = path.parent_path().string();
     66        const string fname = path.filename();
    6867
    69     const Time now;
    70     io_service.Write(now, "/----------------------- Program ------------------------");
    71     io_service.Write(now, "| Program:  "PACKAGE_STRING" ("+fname+")");
    72     io_service.Write(now, "| CallPath: "+pname);
    73     io_service.Write(now, "| Compiled: "__DATE__" "__TIME__);
    74     io_service.Write(now, "| Revision: "REVISION);
    75     io_service.Write(now, "| Contact:  "PACKAGE_BUGREPORT);
    76     io_service.Write(now, "| URL:      "PACKAGE_URL);
    77     io_service.Write(now, "| Start:    "+now.GetAsStr("%c"));
    78     io_service.Write(now, "\\----------------------- Options ------------------------");
    79     const multimap<string,string> mmap = conf.GetOptions();
    80     for (multimap<string,string>::const_iterator it=mmap.begin(); it!=mmap.end(); it++)
    81         io_service.Write(now, ": "+it->first+(it->second.empty()?"":" = ")+it->second);
    82     io_service.Write(now, "\\------------------- Evaluating options -----------------");
    83     const int rc = io_service.EvalOptions(conf);
    84     if (rc>=0)
    85     {
    86         ostringstream str;
    87         str << "Exit triggered by EvalOptions with rc=" << rc;
    88         io_service.Write(now, str.str(), MessageImp::kError);
    89         return rc;
    90     }
    91 
    92     const map<string,string> &wco = conf.GetWildcardOptions();
    93     if (wco.size()>0)
    94     {
    95         io_service.Write(now, "------------- Unrecognized wildcard options -------------", MessageImp::kWarn);
    96 
    97         size_t max = 0;
    98         for (map<string,string>::const_iterator it=wco.begin(); it!=wco.end(); it++)
    99             if (it->second.length()>max)
    100                 max = it->second.length();
    101 
    102         for (map<string,string>::const_iterator it=wco.begin(); it!=wco.end(); it++)
     68        const Time now;
     69        io_service.Write(now, "/----------------------- Program ------------------------");
     70        io_service.Write(now, "| Program:  "PACKAGE_STRING" ("+fname+")");
     71        io_service.Write(now, "| CallPath: "+pname);
     72        io_service.Write(now, "| Compiled: "__DATE__" "__TIME__);
     73        io_service.Write(now, "| Revision: "REVISION);
     74        io_service.Write(now, "| Contact:  "PACKAGE_BUGREPORT);
     75        io_service.Write(now, "| URL:      "PACKAGE_URL);
     76        io_service.Write(now, "| Start:    "+now.GetAsStr("%c"));
     77        io_service.Write(now, "\\----------------------- Options ------------------------");
     78        const multimap<string,string> mmap = conf.GetOptions();
     79        for (multimap<string,string>::const_iterator it=mmap.begin(); it!=mmap.end(); it++)
     80            io_service.Write(now, ": "+it->first+(it->second.empty()?"":" = ")+it->second);
     81        io_service.Write(now, "\\------------------- Evaluating options -----------------");
     82        const int rc = io_service.EvalOptions(conf);
     83        if (rc>=0)
    10384        {
    10485            ostringstream str;
    105             str.setf(ios_base::left);
    106             str << setw(max+1) << it->second << " : " << it->first;
    107             io_service.Write(now, str.str(), MessageImp::kWarn);
     86            str << "Exit triggered by EvalOptions with rc=" << rc;
     87            io_service.Write(now, str.str(), MessageImp::kError);
     88            return rc;
    10889        }
    109         io_service.Write(now, "Unrecognized options found, will exit with rc=127", MessageImp::kError);
    110         return 127;
     90
     91        const map<string,string> &wco = conf.GetWildcardOptions();
     92        if (wco.size()>0)
     93        {
     94            io_service.Write(now, "------------- Unrecognized wildcard options -------------", MessageImp::kWarn);
     95
     96            size_t max = 0;
     97            for (map<string,string>::const_iterator it=wco.begin(); it!=wco.end(); it++)
     98                if (it->second.length()>max)
     99                    max = it->second.length();
     100
     101            for (map<string,string>::const_iterator it=wco.begin(); it!=wco.end(); it++)
     102            {
     103                ostringstream str;
     104                str.setf(ios_base::left);
     105                str << setw(max+1) << it->second << " : " << it->first;
     106                io_service.Write(now, str.str(), MessageImp::kWarn);
     107            }
     108            io_service.Write(now, "Unrecognized options found, will exit with rc=127", MessageImp::kError);
     109            return 127;
     110        }
     111
     112        io_service.Message("==================== Starting main loop =================");
     113
     114        wout.SetNullOutput(null);
     115        wout.SetBacklog(backlog);
     116
     117        shell.SetReceiver(io_service);
     118
     119        //    boost::thread t(boost::bind(&AutoScheduler<S>::Run, &io_service));
     120        thread t(bind(Main::Thread, &io_service, dummy));
     121
     122        const vector<string> v1 = conf.Vec<string>("cmd");
     123        for (vector<string>::const_iterator it=v1.begin(); it!=v1.end(); it++)
     124            shell.ProcessLine(*it);
     125
     126        const vector<string> v2 = conf.Vec<string>("exec");
     127        for (vector<string>::const_iterator it=v2.begin(); it!=v2.end(); it++)
     128            shell.Execute(*it);
     129
     130        if (conf.Get<bool>("quit"))
     131            shell.Stop();
     132
     133        shell.Run();                 // Run the shell
     134        io_service.Stop();           // Signal Loop-thread to stop
     135        // io_service.Close();       // Obsolete, done by the destructor
     136        // wout << "join: " << t.timed_join(boost::posix_time::milliseconds(0)) << endl;
     137
     138        // Wait until the StateMachine has finished its thread
     139        // before returning and destroying the dim objects which might
     140        // still be in use.
     141        t.join();
     142
     143        return 0;
    111144    }
    112 
    113     io_service.Message("==================== Starting main loop =================");
    114 
    115     wout.SetNullOutput(null);
    116     wout.SetBacklog(backlog);
    117 
    118     shell.SetReceiver(io_service);
    119 
    120 //    boost::thread t(boost::bind(&AutoScheduler<S>::Run, &io_service));
    121     thread t(bind(MainThread, &io_service, dummy));
    122 
    123     const vector<string> v1 = conf.Vec<string>("cmd");
    124     for (vector<string>::const_iterator it=v1.begin(); it!=v1.end(); it++)
    125         shell.ProcessLine(*it);
    126 
    127     const vector<string> v2 = conf.Vec<string>("exec");
    128     for (vector<string>::const_iterator it=v2.begin(); it!=v2.end(); it++)
    129         shell.Execute(*it);
    130 
    131     if (conf.Get<bool>("quit"))
    132         shell.Stop();
    133 
    134     shell.Run();                 // Run the shell
    135     io_service.Stop();           // Signal Loop-thread to stop
    136     // io_service.Close();       // Obsolete, done by the destructor
    137     // wout << "join: " << t.timed_join(boost::posix_time::milliseconds(0)) << endl;
    138 
    139     // Wait until the StateMachine has finished its thread
    140     // before returning and destroying the dim objects which might
    141     // still be in use.
    142     t.join();
    143 
    144     return 0;
    145145}
    146146
  • trunk/FACT++/src/biasctrl.cc

    r11574 r11575  
    551551// ------------------------------------------------------------------------
    552552
    553 void RunThread(StateMachineImp *io_service)
    554 {
    555     // This is necessary so that the StateMachien Thread can signal the
    556     // Readline to exit
    557     io_service->Run();
    558     Readline::Stop();
    559 }
    560 
    561 /*
    562 template<class S, class T>
    563 int RunDim(Configuration &conf)
    564 {
    565     WindowLog wout;
    566 
    567     ReadlineColor::PrintBootMsg(wout, conf.GetName(), false);
    568 
    569 
    570     if (conf.Has("log"))
    571         if (!wout.OpenLogFile(conf.Get<string>("log")))
    572             wout << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
    573 
    574     // Start io_service.Run to use the StateMachineImp::Run() loop
    575     // Start io_service.run to only use the commandHandler command detaching
    576     StateMachineBias<S, T> io_service(wout);
    577     if (!io_service.EvalConfiguration(conf))
    578         return -1;
    579 
    580     io_service.Run();
    581 
    582     return 0;
    583 }
    584 */
    585 
    586553#include "Main.h"
    587554
     
    589556int RunShell(Configuration &conf)
    590557{
    591     return Main<T, StateMachineBias<S, R>>(conf);
    592 /*
    593     static T shell(conf.GetName().c_str(), conf.Get<int>("console")!=1);
    594 
    595     WindowLog &win  = shell.GetStreamIn();
    596     WindowLog &wout = shell.GetStreamOut();
    597 
    598     if (conf.Has("log"))
    599         if (!wout.OpenLogFile(conf.Get<string>("log")))
    600             win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
    601 
    602     StateMachineBias<S, R> io_service(wout);
    603     if (!io_service.EvalConfiguration(conf))
    604         return -1;
    605 
    606     shell.SetReceiver(io_service);
    607 
    608     boost::thread t(bind(RunThread, &io_service));
    609     // boost::thread t(bind(&StateMachineBias<S>::Run, &io_service));
    610 
    611     if (conf.Has("cmd"))
    612     {
    613         const vector<string> v = conf.Get<vector<string>>("cmd");
    614         for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
    615             shell.ProcessLine(*it);
    616     }
    617 
    618     if (conf.Has("exec"))
    619     {
    620         const vector<string> v = conf.Get<vector<string>>("exec");
    621         for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
    622             shell.Execute(*it);
    623     }
    624 
    625     if (conf.Get<bool>("quit"))
    626         shell.Stop();
    627 
    628     shell.Run();                 // Run the shell
    629     io_service.Stop();           // Signal Loop-thread to stop
    630     // io_service.Close();       // Obsolete, done by the destructor
    631 
    632     // Wait until the StateMachine has finished its thread
    633     // before returning and destroying the dim objects which might
    634     // still be in use.
    635     t.join();
    636 
    637     return 0;*/
     558    return Main::execute<T, StateMachineBias<S, R>>(conf);
    638559}
    639560
    640561void SetupConfiguration(Configuration &conf)
    641562{
    642     const string n = conf.GetName()+".log";
    643 
    644     po::options_description config("Program options");
    645     config.add_options()
    646         ("dns",       var<string>("localhost"),       "Dim nameserver (overwites DIM_DNS_NODE environment variable)")
    647         ("host",      var<string>(""),                "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")
    648         ("log,l",     var<string>(n), "Write log-file")
    649         ("no-dim,d",  po_bool(),      "Disable dim services")
    650         ("console,c", var<int>(),     "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
    651         ("cmd",       vars<string>(), "Execute one or more commands at startup")
    652         ("exec,e",    vars<string>(), "Execute one or more scrips at startup")
    653         ("quit",      po_switch(),    "Quit after startup");
    654         ;
    655 
    656     po::options_description control("FTM control options");
     563    po::options_description control("BIAS control options");
    657564    control.add_options()
     565        ("no-dim,d",      po_bool(),  "Disable dim services")
    658566        ("addr,a",        var<string>("ttysS0"),  "Device address of USB port to bias-power supply")
    659567        ("quiet,q",       po_bool(),  "Disable printing contents of all received messages (except dynamic data) in clear text.")
    660568        ;
    661569
    662     conf.AddEnv("dns",  "DIM_DNS_NODE");
    663     conf.AddEnv("host", "DIM_HOST_NODE");
    664 
    665     conf.AddOptions(config);
    666570    conf.AddOptions(control);
    667571}
     
    715619    Configuration conf(argv[0]);
    716620    conf.SetPrintUsage(PrintUsage);
     621    Main::SetupConfiguration(conf);
    717622    SetupConfiguration(conf);
    718623
  • trunk/FACT++/src/datalogger.cc

    r11574 r11575  
    23942394int RunShell(Configuration &conf)
    23952395{
    2396     return Main<T, DataLogger>(conf, true);
     2396    return Main::execute<T, DataLogger>(conf, true);
    23972397}
    23982398
     
    24452445void SetupConfiguration(Configuration &conf)
    24462446{
    2447     const string n = conf.GetName()+".log";
    2448 
    2449     po::options_description configp("Program options");
    2450     configp.add_options()
    2451         ("dns",       var<string>("localhost"),       "Dim nameserver (overwites DIM_DNS_NODE environment variable)")
    2452         ("host",      var<string>(""),                "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")
    2453         ("log,l",     var<string>(n), "Write log-file")
    2454         ("console,c", var<int>(),     "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
    2455         ("cmd",       vars<string>(), "Execute one or more commands at startup")
    2456         ("exec,e",    vars<string>(), "Execute one or more scrips at startup")
    2457         ("quit",      po_switch(),    "Quit after startup");
    2458         ;
    2459 
    24602447    po::options_description configs("DataLogger options");
    24612448    configs.add_options()
     
    24712458        ;
    24722459
    2473     conf.AddEnv("dns",  "DIM_DNS_NODE");
    2474     conf.AddEnv("host", "DIM_HOST_NODE");
    2475 
    2476     conf.AddOptions(configp);
    24772460    conf.AddOptions(configs);
    24782461}
     
    24822465    Configuration conf(argv[0]);
    24832466    conf.SetPrintUsage(PrintUsage);
     2467    Main::SetupConfiguration(conf);
    24842468    SetupConfiguration(conf);
    24852469
  • trunk/FACT++/src/dimctrl.cc

    r11574 r11575  
    3434
    3535// ========================================================================
    36 void SetupConfiguration(Configuration &conf)
    37 {
    38     const string n = conf.GetName()+".log";
    39 
    40     po::options_description config("Program options");
    41     config.add_options()
    42         ("dns",       var<string>("localhost"),       "Dim nameserver (overwites DIM_DNS_NODE environment variable)")
    43         ("host",      var<string>(""),                "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")
    44         ("log,l",     var<string>(n), "Write log-file")
    45         ("console,c", var<int>(0),    "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
    46         ("cmd",       vars<string>(), "Execute one or more commands at startup")
    47         ("exec,e",    vars<string>(), "Execute one or more scrips at startup")
    48         ("quit",      po_switch(),    "Quit after startup");
    49         ;
    50 
    51     conf.AddEnv("dns",  "DIM_DNS_NODE");
    52     conf.AddEnv("host", "DIM_HOST_NODE");
    53 
    54     conf.AddOptions(config);
    55 }
    5636
    5737/*
     
    8262}
    8363
     64#include "Main.h"
     65
    8466int main(int argc, const char *argv[])
    8567{
    8668    Configuration conf(argv[0]);
    8769    conf.SetPrintUsage(PrintUsage);
    88     SetupConfiguration(conf);
     70    Main::SetupConfiguration(conf);
    8971
    9072    po::variables_map vm;
  • trunk/FACT++/src/drivectrl.cc

    r11574 r11575  
    938938void SetupConfiguration(Configuration &conf)
    939939{
    940     const string n = conf.GetName()+".log";
    941 
    942     po::options_description config("Program options");
    943     config.add_options()
    944         ("dns",       var<string>("localhost"),       "Dim nameserver (overwites DIM_DNS_NODE environment variable)")
    945         ("host",      var<string>(""),                "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")
    946         ("log,l",     var<string>(n), "Write log-file")
    947         ("no-dim,d",  po_switch(),    "Disable dim services")
    948         ("console,c", var<int>(),     "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
    949         ("cmd",       vars<string>(), "Execute one or more commands at startup")
    950         ("exec,e",    vars<string>(), "Execute one or more scrips at startup")
    951         ("quit",      po_switch(),    "Quit after startup");
    952         ;
    953 
    954940    po::options_description control("FTM control options");
    955941    control.add_options()
     942        ("no-dim,d",  po_switch(),    "Disable dim services")
    956943        ("addr,a",  var<string>("localhost:7404"),  "Network address of FTM")
    957944        ("quiet,q", po_bool(),  "Disable printing contents of all received messages (except dynamic data) in clear text.")
    958945        ;
    959946
    960     conf.AddEnv("dns",  "DIM_DNS_NODE");
    961     conf.AddEnv("host", "DIM_HOST_NODE");
    962 
    963     conf.AddOptions(config);
    964947    conf.AddOptions(control);
    965948}
     
    1013996    Configuration conf(argv[0]);
    1014997    conf.SetPrintUsage(PrintUsage);
     998    Main::SetupConfiguration(conf);
    1015999    SetupConfiguration(conf);
    10161000
  • trunk/FACT++/src/fadctrl.cc

    r11574 r11575  
    19741974#include "Main.h"
    19751975
    1976 /*
    1977 void RunThread(StateMachineImp *io_service)
    1978 {
    1979     // This is necessary so that the StateMachien Thread can signal the
    1980     // Readline to exit
    1981     io_service->Run();
    1982     Readline::Stop();
    1983 }
    1984 */
    1985 /*
    1986 template<class S>
    1987 int RunDim(Configuration &conf)
    1988 {
    1989     WindowLog wout;
    1990 
    1991     ReadlineColor::PrintBootMsg(wout, conf.GetName(), false);
    1992 
    1993     if (conf.Has("log"))
    1994         if (!wout.OpenLogFile(conf.Get<string>("log")))
    1995             wout << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
    1996 
    1997     // Start io_service.Run to use the StateMachineImp::Run() loop
    1998     // Start io_service.run to only use the commandHandler command detaching
    1999     StateMachineFAD<S> io_service(wout);
    2000     if (!io_service.EvalConfiguration(conf))
    2001         return -1;
    2002 
    2003     io_service.Run();
    2004 
    2005     return 0;
    2006 }
    2007 */
    2008 
    20091976template<class T, class S>
    20101977int RunShell(Configuration &conf)
    20111978{
    2012     return Main<T, StateMachineFAD<S>>(conf);
    2013 /*
    2014     static T shell(conf.GetName().c_str(), conf.Get<int>("console")!=1);
    2015 
    2016     WindowLog &win  = shell.GetStreamIn();
    2017     WindowLog &wout = shell.GetStreamOut();
    2018 
    2019     if (conf.Has("log"))
    2020         if (!wout.OpenLogFile(conf.Get<string>("log")))
    2021             win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
    2022 
    2023     StateMachineFAD<S> io_service(wout);
    2024     if (!io_service.EvalConfiguration(conf))
    2025         return -1;
    2026 
    2027     shell.SetReceiver(io_service);
    2028 
    2029     boost::thread t(bind(RunThread, &io_service));
    2030     //boost::thread t(bind(&StateMachineFAD<S>::Run, &io_service));
    2031 
    2032     if (conf.Has("cmd"))
    2033     {
    2034         const vector<string> v = conf.Get<vector<string>>("cmd");
    2035         for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
    2036             shell.ProcessLine(*it);
    2037     }
    2038 
    2039     if (conf.Has("exec"))
    2040     {
    2041         const vector<string> v = conf.Get<vector<string>>("exec");
    2042         for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
    2043             shell.Execute(*it);
    2044     }
    2045 
    2046     if (conf.Get<bool>("quit"))
    2047         shell.Stop();
    2048 
    2049     shell.Run();                 // Run the shell
    2050     io_service.Stop();           // Signal Loop-thread to stop
    2051 
    2052     // Wait until the StateMachine has finished its thread
    2053     // before returning and destroying the dim objects which might
    2054     // still be in use.
    2055     t.join();
    2056 
    2057     return 0;
    2058     */
     1979    return Main::execute<T, StateMachineFAD<S>>(conf);
    20591980}
    20601981
    20611982void SetupConfiguration(Configuration &conf)
    20621983{
    2063     const string n = conf.GetName()+".log";
    2064 
    2065     po::options_description config("Program options");
    2066     config.add_options()
    2067         ("dns",       var<string>("localhost"),       "Dim nameserver (overwites DIM_DNS_NODE environment variable)")
    2068         ("host",      var<string>(""),                "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")
    2069         ("log,l",     var<string>(n), "Write log-file")
    2070 //        ("no-dim,d",  po_switch(),    "Disable dim services")
    2071         ("console,c", var<int>(),     "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
    2072         ("cmd",       vars<string>(), "Execute one or more commands at startup")
    2073         ("exec,e",    vars<string>(), "Execute one or more scrips at startup")
    2074         ("quit",      po_switch(),    "Quit after startup");
    2075         ;
    2076 
    20771984    po::options_description control("FAD control options");
    20781985    control.add_options()
     
    21282035    conf.AddEnv("host", "DIM_HOST_NODE");
    21292036
    2130     conf.AddOptions(config);
    21312037    conf.AddOptions(control);
    21322038    conf.AddOptions(connect);
     
    21602066    Configuration conf(argv[0]);
    21612067    conf.SetPrintUsage(PrintUsage);
     2068    Main::SetupConfiguration(conf);
    21622069    SetupConfiguration(conf);
    21632070
  • trunk/FACT++/src/fscctrl.cc

    r11574 r11575  
    520520#include "Main.h"
    521521
    522 /*
    523 void RunThread(StateMachineImp *io_service)
    524 {
    525     // This is necessary so that the StateMachien Thread can signal the
    526     // Readline to exit
    527     io_service->Run();
    528     Readline::Stop();
    529 }
    530 */
    531 /*
    532 template<class S, class T>
    533 int RunDim(Configuration &conf)
    534 {
    535     WindowLog wout;
    536 
    537     ReadlineColor::PrintBootMsg(wout, conf.GetName(), false);
    538 
    539 
    540     if (conf.Has("log"))
    541         if (!wout.OpenLogFile(conf.Get<string>("log")))
    542             wout << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
    543 
    544     // Start io_service.Run to use the StateMachineImp::Run() loop
    545     // Start io_service.run to only use the commandHandler command detaching
    546     StateMachineFSC<S, T> io_service(wout);
    547     if (!io_service.EvalConfiguration(conf))
    548         return -1;
    549 
    550     io_service.Run();
    551 
    552     return 0;
    553 }
    554 */
    555 
    556522template<class T, class S, class R>
    557523int RunShell(Configuration &conf)
    558524{
    559     return Main<T, StateMachineFSC<S, R>>(conf);
    560 /*
    561     static T shell(conf.GetName().c_str(), conf.Get<int>("console")!=1);
    562 
    563     WindowLog &win  = shell.GetStreamIn();
    564     WindowLog &wout = shell.GetStreamOut();
    565 
    566     if (conf.Has("log"))
    567         if (!wout.OpenLogFile(conf.Get<string>("log")))
    568             win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
    569 
    570     StateMachineFSC<S, R> io_service(wout);
    571     if (!io_service.EvalConfiguration(conf))
    572         return -1;
    573 
    574     shell.SetReceiver(io_service);
    575 
    576     boost::thread t(boost::bind(RunThread, &io_service));
    577     // boost::thread t(boost::bind(&StateMachineFSC<S>::Run, &io_service));
    578 
    579     if (conf.Has("cmd"))
    580     {
    581         const vector<string> v = conf.Get<vector<string>>("cmd");
    582         for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
    583             shell.ProcessLine(*it);
    584     }
    585 
    586     if (conf.Has("exec"))
    587     {
    588         const vector<string> v = conf.Get<vector<string>>("exec");
    589         for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
    590             shell.Execute(*it);
    591     }
    592 
    593     if (conf.Get<bool>("quit"))
    594         shell.Stop();
    595 
    596     shell.Run();                 // Run the shell
    597     io_service.Stop();           // Signal Loop-thread to stop
    598     // io_service.Close();       // Obsolete, done by the destructor
    599 
    600     // Wait until the StateMachine has finished its thread
    601     // before returning and destroying the dim objects which might
    602     // still be in use.
    603     t.join();
    604 
    605     return 0;
    606 */
     525    return Main::execute<T, StateMachineFSC<S, R>>(conf);
    607526}
    608527
    609528void SetupConfiguration(Configuration &conf)
    610529{
    611     const string n = conf.GetName()+".log";
    612 
    613     po::options_description config("Program options");
    614     config.add_options()
    615         ("dns",       var<string>("localhost"),       "Dim nameserver (overwites DIM_DNS_NODE environment variable)")
    616         ("host",      var<string>(""),                "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")
    617         ("log,l",     var<string>(n), "Write log-file")
    618         ("no-dim,d",  po_bool(),      "Disable dim services")
    619         ("console,c", var<int>(),     "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
    620         ("cmd",       vars<string>(), "Execute one or more commands at startup")
    621         ("exec,e",    vars<string>(), "Execute one or more scrips at startup")
    622         ("quit,q",    po_switch(),    "Quit after startup");
    623         ;
    624 
    625530    po::options_description control("FTM control options");
    626531    control.add_options()
     
    629534        ;
    630535
    631     conf.AddEnv("dns",  "DIM_DNS_NODE");
    632     conf.AddEnv("host", "DIM_HOST_NODE");
    633 
    634     conf.AddOptions(config);
    635536    conf.AddOptions(control);
    636537}
     
    684585    Configuration conf(argv[0]);
    685586    conf.SetPrintUsage(PrintUsage);
     587    Main::SetupConfiguration(conf);
    686588    SetupConfiguration(conf);
    687589
  • trunk/FACT++/src/ftmctrl.cc

    r11574 r11575  
    23312331#include "Main.h"
    23322332
    2333 /*
    2334 void RunThread(StateMachineImp *io_service)
    2335 {
    2336     // This is necessary so that the StateMachien Thread can signal the
    2337     // Readline to exit
    2338     io_service->Run();
    2339     Readline::Stop();
    2340 }
    2341 */
    2342 /*
    2343 template<class S, class T>
    2344 int RunDim(Configuration &conf)
    2345 {
    2346     WindowLog wout;
    2347 
    2348     ReadlineColor::PrintBootMsg(wout, conf.GetName(), false);
    2349 
    2350     if (conf.Has("log"))
    2351         if (!wout.OpenLogFile(conf.Get<string>("log")))
    2352             wout << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
    2353 
    2354     // Start io_service.Run to use the StateMachineImp::Run() loop
    2355     // Start io_service.run to only use the commandHandler command detaching
    2356     StateMachineFTM<S, T> io_service(wout);
    2357     if (!io_service.EvalConfiguration(conf))
    2358         return -1;
    2359 
    2360     io_service.Run();
    2361 
    2362     return 0;
    2363 }
    2364 */
    2365 
    23662333template<class T, class S, class R>
    23672334int RunShell(Configuration &conf)
    23682335{
    2369     return Main<T, StateMachineFTM<S, R>>(conf);
    2370 /*
    2371     static T shell(conf.GetName().c_str(), conf.Get<int>("console")!=1);
    2372 
    2373     WindowLog &win  = shell.GetStreamIn();
    2374     WindowLog &wout = shell.GetStreamOut();
    2375 
    2376     if (conf.Has("log"))
    2377         if (!wout.OpenLogFile(conf.Get<string>("log")))
    2378             win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
    2379 
    2380     StateMachineFTM<S, R> io_service(wout);
    2381     if (!io_service.EvalConfiguration(conf))
    2382         return -1;
    2383 
    2384     shell.SetReceiver(io_service);
    2385 
    2386     boost::thread t(bind(RunThread, &io_service));
    2387     // boost::thread t(bind(&StateMachineFTM<S>::Run, &io_service));
    2388 
    2389     if (conf.Has("cmd"))
    2390     {
    2391         const vector<string> v = conf.Get<vector<string>>("cmd");
    2392         for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
    2393             shell.ProcessLine(*it);
    2394     }
    2395 
    2396     if (conf.Has("exec"))
    2397     {
    2398         const vector<string> v = conf.Get<vector<string>>("exec");
    2399         for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
    2400             shell.Execute(*it);
    2401     }
    2402 
    2403     if (conf.Get<bool>("quit"))
    2404         shell.Stop();
    2405 
    2406     shell.Run();                 // Run the shell
    2407     io_service.Stop();           // Signal Loop-thread to stop
    2408     // io_service.Close();       // Obsolete, done by the destructor
    2409 
    2410     // Wait until the StateMachine has finished its thread
    2411     // before returning and destroying the dim objects which might
    2412     // still be in use.
    2413     t.join();
    2414 
    2415     return 0;
    2416     */
     2336    return Main::execute<T, StateMachineFTM<S, R>>(conf);
    24172337}
    24182338
    24192339void SetupConfiguration(Configuration &conf)
    24202340{
    2421     const string n = conf.GetName()+".log";
    2422 
    2423     po::options_description config("Program options");
    2424     config.add_options()
    2425         ("dns",       var<string>("localhost"),       "Dim nameserver (overwites DIM_DNS_NODE environment variable)")
    2426         ("host",      var<string>(""),                "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")
    2427         ("no-dim,d",  po_bool(),      "Disable dim services")
    2428         ("console,c", var<int>(),     "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
    2429         ("cmd",       vars<string>(), "Execute one or more commands at startup")
    2430         ("exec,e",    vars<string>(), "Execute one or more scrips at startup")
    2431         ("quit",      po_switch(),    "Quit after startup");
    2432         ;
    2433 
    24342341    po::options_description control("Control options");
    24352342    control.add_options()
     2343        ("no-dim",        po_bool(),  "Disable dim services")
    24362344        ("addr,a",        var<string>("localhost:5000"),  "Network address of FTM")
    24372345        ("quiet,q",       po_bool(),  "Disable printing contents of all received messages (except dynamic data) in clear text.")
     
    24812389        ;
    24822390
    2483     conf.AddEnv("dns",  "DIM_DNS_NODE");
    2484     conf.AddEnv("host", "DIM_HOST_NODE");
    2485 
    2486     conf.AddOptions(config);
    24872391    conf.AddOptions(control);
    24882392    conf.AddOptions(runtype);
     
    25372441    Configuration conf(argv[0]);
    25382442    conf.SetPrintUsage(PrintUsage);
     2443    Main::SetupConfiguration(conf);
    25392444    SetupConfiguration(conf);
    25402445
  • trunk/FACT++/src/mcp.cc

    r11574 r11575  
    422422#include "Main.h"
    423423
    424 /*
    425 void RunThread(StateMachineImp *io_service)
    426 {
    427     // This is necessary so that the StateMachien Thread can signal the
    428     // Readline to exit
    429     io_service->Run();
    430     Readline::Stop();
    431 }
    432 */
    433 /*
    434 template<class S, class T>
    435 int RunDim(Configuration &conf)
    436 {
    437     WindowLog wout;
    438 
    439     ReadlineColor::PrintBootMsg(wout, conf.GetName(), false);
    440 
    441 
    442     if (conf.Has("log"))
    443         if (!wout.OpenLogFile(conf.Get<string>("log")))
    444             wout << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
    445 
    446     // Start io_service.Run to use the StateMachineImp::Run() loop
    447     // Start io_service.run to only use the commandHandler command detaching
    448     StateMachineMCP<S, T> io_service(wout);
    449     if (!io_service.EvalConfiguration(conf))
    450         return -1;
    451 
    452     io_service.Run();
    453 
    454     return 0;
    455 }
    456 */
    457 
    458424template<class T>
    459425int RunShell(Configuration &conf)
    460426{
    461     return Main<T, StateMachineMCP>(conf);
    462 /*
    463     static T shell(conf.GetName().c_str(), conf.Get<int>("console")!=1);
    464 
    465     WindowLog &win  = shell.GetStreamIn();
    466     WindowLog &wout = shell.GetStreamOut();
    467 
    468     if (conf.Has("log"))
    469         if (!wout.OpenLogFile(conf.Get<string>("log")))
    470             win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
    471 
    472     StateMachineMCP<S, R> io_service(wout);
    473     if (!io_service.EvalConfiguration(conf))
    474         return -1;
    475 
    476     shell.SetReceiver(io_service);
    477 
    478     boost::thread t(bind(RunThread, &io_service));
    479     // boost::thread t(bind(&StateMachineMCP<S>::Run, &io_service));
    480 
    481     if (conf.Has("cmd"))
    482     {
    483         const vector<string> v = conf.Get<vector<string>>("cmd");
    484         for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
    485             shell.ProcessLine(*it);
    486     }
    487 
    488     if (conf.Has("exec"))
    489     {
    490         const vector<string> v = conf.Get<vector<string>>("exec");
    491         for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
    492             shell.Execute(*it);
    493     }
    494 
    495     if (conf.Get<bool>("quit"))
    496         shell.Stop();
    497 
    498     shell.Run();                 // Run the shell
    499     io_service.Stop();           // Signal Loop-thread to stop
    500     // io_service.Close();       // Obsolete, done by the destructor
    501 
    502     // Wait until the StateMachine has finished its thread
    503     // before returning and destroying the dim objects which might
    504     // still be in use.
    505     t.join();
    506 
    507     return 0;
    508 */
    509 }
    510 
    511 void SetupConfiguration(Configuration &conf)
    512 {
    513     const string n = conf.GetName()+".log";
    514 
    515     po::options_description config("Program options");
    516     config.add_options()
    517         ("dns",       var<string>("localhost"),       "Dim nameserver (overwites DIM_DNS_NODE environment variable)")
    518         ("host",      var<string>(""),                "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")
    519         ("log,l",     var<string>(n), "Write log-file")
    520 //        ("no-dim,d",  po_bool(),      "Disable dim services")
    521         ("console,c", var<int>(),     "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
    522         ("cmd",       vars<string>(), "Execute one or more commands at startup")
    523         ("exec,e",    vars<string>(), "Execute one or more scrips at startup")
    524         ("quit,q",    po_switch(),    "Quit after startup");
    525         ;
    526 /*
    527     po::options_description control("FTM control options");
    528     control.add_options()
    529         ("addr,a",        var<string>("localhost:5000"),  "Network address of FTM")
    530         ("quiet,q",       po_bool(),  "Disable printing contents of all received messages (except dynamic data) in clear text.")
    531         ;
    532 */
    533     conf.AddEnv("dns",  "DIM_DNS_NODE");
    534     conf.AddEnv("host", "DIM_HOST_NODE");
    535 
    536     conf.AddOptions(config);
    537 //    conf.AddOptions(control);
     427    return Main::execute<T, StateMachineMCP>(conf);
    538428}
    539429
     
    586476    Configuration conf(argv[0]);
    587477    conf.SetPrintUsage(PrintUsage);
    588     SetupConfiguration(conf);
     478    Main::SetupConfiguration(conf);
    589479
    590480    po::variables_map vm;
  • 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.