Changeset 13843 for trunk/FACT++
- Timestamp:
- 05/23/12 19:32:19 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/DimState.h
r13842 r13843 24 24 string msg; 25 25 26 v oid Subscribe(StateMachineImp &imp)26 virtual void Subscribe(StateMachineImp &imp) 27 27 { 28 28 imp.Subscribe(service.c_str()) … … 52 52 bool online() const { return info.second>-4; } 53 53 54 const string &name() const { return server; } 54 virtual State description() const { return State(-5, ""); } 55 }; 56 57 ostream &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 84 class DimDescribedState : public DimState 85 { 86 vector<State> states; 87 88 public: 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 } 55 118 }; 56 119 … … 63 126 { 64 127 DimState::Handler(evt); 65 info.second = evt.GetSize()==4 ? evt.GetInt() : 0; 128 129 info.second = evt.GetSize()==4 ? evt.GetInt() : -4; 66 130 } 67 131 … … 74 138 out << "V" << info.second/100 << 'r' << info.second%100; 75 139 return out.str(); 140 } 141 142 State description() const 143 { 144 return State(state(), version()); 76 145 } 77 146 }; … … 115 184 func->second(evt); 116 185 } 186 187 State description() const 188 { 189 return State(state(), "Current label"); 190 } 191 117 192 }; 118 193
Note:
See TracChangeset
for help on using the changeset viewer.