TimerService.h
См. документацию.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00024
00025 #ifndef TimerService_H_
00026 #define TimerService_H_
00027
00028 #include <list>
00029 #include <functional>
00030 #include <omnithread.h>
00031 #include <string>
00032 #include "UniSetTypes.h"
00033 #include "UniSetObject.h"
00034 #include "TimerService_i.hh"
00035 #include "PassiveTimer.h"
00036
00037 #include "ThreadCreator.h"
00038
00039
00097 class TimerService:
00098 public POA_TimerService_i,
00099 public UniSetObject
00100 {
00101 public:
00102
00103 TimerService( UniSetTypes::ObjectId id, const std::string confNodeName="LocalTimerService");
00104 ~TimerService();
00105
00107 virtual void askTimer( const TimerService_i::Timer& ti, const UniSetTypes::ConsumerInfo& ci);
00108 void printList();
00109
00110 protected:
00111 TimerService(const std::string confNodeName="LocalTimerService");
00112
00114 struct TimerInfo
00115 {
00116 TimerInfo():id(0), curTimeMS(0){};
00117 TimerInfo(CORBA::Short id, CORBA::Long timeMS, const UniSetTypes::ConsumerInfo& cinf,
00118 CORBA::Short cnt, unsigned int askLifeTime, UniSetTypes::Message::Priority p):
00119 cinf(cinf),
00120 ref(0),
00121 id(id),
00122 curTimeMS(timeMS),
00123 priority(p),
00124 curTick(cnt-1),
00125 not_ping(false)
00126 {
00127 tmr.setTiming(timeMS);
00128 lifetmr.setTiming(askLifeTime*1000);
00129 };
00130
00131 inline void reset()
00132 {
00133 curTimeMS = tmr.getInterval();
00134 tmr.reset();
00135 }
00136
00137 UniSetTypes::ConsumerInfo cinf;
00138 UniSetObject_i_var ref;
00139 UniSetTypes::TimerId id;
00140 timeout_t curTimeMS;
00141 UniSetTypes::Message::Priority priority;
00147 CORBA::Short curTick;
00148
00149
00150 bool operator < ( const TimerInfo& ti ) const
00151 {
00152 return curTimeMS > ti.curTimeMS;
00153 }
00154
00155 PassiveTimer tmr;
00156 PassiveTimer lifetmr;
00157 bool not_ping;
00158 };
00159
00160 typedef std::list<TimerInfo> TimersList;
00161
00163 virtual bool send(TimerInfo& ti);
00164
00166 virtual bool disactivateObject();
00167 virtual bool activateObject();
00168 virtual void sigterm( int signo );
00169
00170
00171 unsigned int MaxCountTimers;
00172 unsigned int AskLifeTimeSEC;
00174 void init(const std::string& confnode);
00175 void work();
00176
00177 private:
00178
00179 bool terminate;
00180 bool isSleep;
00181
00182 UniSetTimer* sleepTimer;
00183 class Timer_eq: public std::unary_function<TimerInfo, bool>
00184 {
00185 public:
00186 Timer_eq(const UniSetTypes::ConsumerInfo& coi, CORBA::Short t):tid(t),ci(coi){}
00187
00188 inline bool operator()(const TimerInfo& ti) const
00189 {
00190 return ( ti.cinf.id == ci.id && ti.cinf.node == ci.node && ti.id == tid );
00191 }
00192
00193 protected:
00194 UniSetTypes::TimerId tid;
00195 UniSetTypes::ConsumerInfo ci;
00196 };
00197
00198 TimersList tlst;
00200 UniSetTypes::uniset_mutex lstMutex;
00201 int execute_pid;
00202 ThreadCreator<TimerService>* exthread;
00203 };
00204
00205 #endif