Ignore:
Timestamp:
05/23/12 19:32:19 (12 years ago)
Author:
tbretz
Message:
Implemented subscription to descriptions so that the DimServiceInfoList will be obsolete in this context.
File:
1 edited

Legend:

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

    r13842 r13843  
    2424    string msg;
    2525
    26     void Subscribe(StateMachineImp &imp)
     26    virtual void Subscribe(StateMachineImp &imp)
    2727    {
    2828        imp.Subscribe(service.c_str())
     
    5252    bool online() const { return info.second>-4; }
    5353
    54     const string &name() const { return server; }
     54    virtual State description() const { return State(-5, ""); }
     55};
     56
     57ostream &operator<<(ostream& out, const DimState &s)
     58{
     59    const State rc = s.description();
     60
     61    out << s.time().GetAsStr("%H:%M:%S.%f").substr(0, 12) << " - ";
     62    out << kBold << s.server;
     63
     64    if (s.state()==-4)
     65        return out << ": Offline";
     66
     67    if (rc.index==-5)
     68        return out;
     69
     70    out << ": ";
     71
     72    if (rc.index==-2)
     73        out << s.state();
     74    else
     75        out << rc.name << "[" << rc.index << "]";
     76
     77    if (!rc.comment.empty())
     78        out << " - " << kBlue << rc.comment;
     79
     80    return out;
     81}
     82
     83
     84class DimDescribedState : public DimState
     85{
     86    vector<State> states;
     87
     88public:
     89    DimDescribedState(const string &n) : DimState(n)
     90    {
     91    }
     92
     93    virtual void Subscribe(StateMachineImp &imp)
     94    {
     95        imp.Subscribe((server+"/STATE_LIST").c_str())
     96            (imp.Wrap(bind(&DimDescribedState::HandleDesc, this, placeholders::_1)));
     97
     98        DimState::Subscribe(imp);
     99    }
     100
     101    void HandleDesc(const EventImp &evt)
     102    {
     103        if (evt.GetSize()>0)
     104        {
     105            states = State::SplitStates(evt.GetString());
     106            states.push_back(State(-4, "Offline"));
     107        }
     108    }
     109
     110    State description() const
     111    {
     112        for (auto it=states.begin(); it!=states.end(); it++)
     113            if (it->index==state())
     114                return *it;
     115
     116        return State(-5, "n/a");
     117    }
    55118};
    56119
     
    63126    {
    64127        DimState::Handler(evt);
    65         info.second = evt.GetSize()==4 ? evt.GetInt() : 0;
     128
     129        info.second = evt.GetSize()==4 ? evt.GetInt() : -4;
    66130    }
    67131
     
    74138        out << "V" << info.second/100 << 'r' << info.second%100;
    75139        return out.str();
     140    }
     141
     142    State description() const
     143    {
     144        return State(state(), version());
    76145    }
    77146};
     
    115184        func->second(evt);
    116185    }
     186
     187    State description() const
     188    {
     189        return State(state(), "Current label");
     190    }
     191
    117192};
    118193
Note: See TracChangeset for help on using the changeset viewer.