Changeset 12964


Ignore:
Timestamp:
02/29/12 10:06:34 (13 years ago)
Author:
tbretz
Message:
Now used the common Main::execute approach to launch the program; implemented a dummy StateMachine class based on MainImp to allow this approach.
File:
1 edited

Legend:

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

    r12458 r12964  
    1 #include "Dim.h"
    2 #include "Configuration.h"
    31#include "RemoteControl.h"
     2#include "Main.h"
    43
    54using namespace std;
    65
    7 template <class T>
    8 void RunShell(Configuration &conf)
    9 {
    10     // A normal kill will call its destructor! (Very nice feature ;) )
    11     static T shell(conf.GetName().c_str(),
    12                    conf.Has("console") ? conf.Get<int>("console")!=1 : conf.Get<bool>("null"));
     6// ========================================================================
    137
    14     WindowLog &win  = shell.GetStreamIn();
    15     WindowLog &wout = shell.GetStreamOut();
    16 
    17     if (conf.Has("log"))
    18         if (!wout.OpenLogFile(conf.Get<string>("log"), conf.Get<bool>("append-log")))
    19             win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
    20 
    21     const vector<string> v1 = conf.Vec<string>("cmd");
    22     for (vector<string>::const_iterator it=v1.begin(); it!=v1.end(); it++)
    23         shell.ProcessLine(*it);
    24 
    25     const vector<string> v2 = conf.Vec<string>("exec");
    26     for (vector<string>::const_iterator it=v2.begin(); it!=v2.end(); it++)
    27         shell.Execute(*it);
    28 
    29     if (conf.Get<bool>("quit"))
    30         shell.Stop();
    31 
    32     shell.Run();
    33 }
    34 
    35 
    36 // ========================================================================
    378
    389/*
     
    5223        "\n"
    5324        "Usage: dimctrl [-c type] [OPTIONS]\n"
    54         "  or:  dimctrl [OPTIONS]\n";
     25        "  or:  dimctrl [OPTIONS]\n\n";
     26
     27    Main::PrintUsage();
    5528    cout << endl;
    56 
    5729}
    5830
    5931void PrintHelp()
    6032{
    61     /* Additional help text which is printed after the configuration
    62      options goes here */
    6333}
    6434
    65 #include "Main.h"
     35// A simple dummy state machine
     36class DimCtrl : public MainImp, public MessageImp
     37{
     38    bool fStop;
     39
     40public:
     41    DimCtrl(ostream &out=cout) : MessageImp(out), fStop(false)
     42    {
     43    }
     44
     45    int EvalOptions(Configuration &conf) { return -1; }
     46    void Stop() { fStop = true; }
     47    int Run(bool) { while (!fStop) usleep(1000); return 0; }
     48};
    6649
    6750int main(int argc, const char *argv[])
     
    7457        return -1;
    7558
    76     Dim::Setup(conf.Get<string>("dns"), conf.Get<string>("host"));
    77 
    7859    if (!conf.Has("console"))
    79         //Main<RemoteShell, DummyService>(conf);
    80         RunShell<RemoteShell>(conf);
     60        return Main::execute<RemoteConsole, DimCtrl>(conf);
    8161    else
    82         //Main<RemoteConsole, DummyService>(conf);
    83         RunShell<RemoteConsole>(conf);
    84 
     62        return Main::execute<RemoteShell, DimCtrl>(conf);
    8563
    8664    return 0;
Note: See TracChangeset for help on using the changeset viewer.