⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wartimerevent.h

📁 ftpserver very good sample
💻 H
字号:
/** */#ifndef WAR_TIMER_EVENT_H#define WAR_TIMER_EVENT_H/* SYSTEM INCLUDES *//* PROJECT INCLUDES */#ifndef WAR_SMART_POINTER_H#   include "WarSmartPointer.h"#endif#ifndef WAR_PTR_WRAPPER_H#   include "WarPtrWrapper.h"#endif#ifndef WAR_TIME#   include "WarTime.h"#endif#ifndef WAR_COLLECTOR_H#   include "WarCollector.h"#endif/* LOCAL INCLUDES *//* FORWARD REFERENCES */#ifdef __cplusplusextern "C" {#endif/****************** BEGIN OLD STYLE C spesific ********//****************** END OLD STYLE C spesific **********/#ifdef __cplusplus }#endif/****************** BEGIN C++ spesific ****************/#ifdef __cplusplusclass WarTimerEvent : public WarSmartPointer{public:    typedef war_uint64_t timer_delay_t;    enum TimerTypeE    {        TIMER_ONCE, /// Run one time        TIMER_LOOP_RELATIVE, // Run again, relative to end-time for last run        TIMER_LOOP_ABSOLUTE // Run again, relative to the last event time    };    // LIFECYCLE        /**    * Default constructor.    */    WarTimerEvent(const WarTime& timerWhen,        TimerTypeE timerType = TIMER_ONCE,         const timer_delay_t timerDelayMs = 0,        const bool IsFast = false)        : mTime(timerWhen),        mDelay(timerDelayMs),        mType(timerType),        mIsDead(false),        mIsFast(IsFast)    {    }        /**    * Copy constructor.    *    * @param from The value to copy to this object.    */    WarTimerEvent(const WarTimerEvent& from)    {        operator = (from);    }        /**    * Destructor.    */    virtual ~WarTimerEvent(void)    {    }        // OPERATORS        /**    * Assignment operator.    *    * @param from THe value to assign to this object.    *    * @return A reference to this object.    */    WarTimerEvent& operator=(const WarTimerEvent& from)    {        mTime = from.mTime;        mDelay = from.mDelay;        mType = from.mType;    }    bool operator < (const WarTimerEvent& from) const    {        return mTime < from.mTime;    }    bool operator == (const WarTimerEvent& from) const    {        return mTime == from.mTime;    }        // OPERATIONS    // Prevent OnTimer() from being called.    void Kill()     {        mIsDead = true;     }    void SetDelay(const timer_delay_t& from)    {        mDelay = from;    }    void SetType(const TimerTypeE type)    {        mType = type;    }    // ACCESS    // INQUIRY    const WarTime GetTime() const    {        return mTime;    }    const timer_delay_t GetDelay() const    {        return mDelay;    }    TimerTypeE GetType() const    {        return mType;    }    bool IsFast() const    {        return mIsFast;    }    war_ccstr_t GetTypeName() const    {        if ((mType < TIMER_ONCE)            || (mType > TIMER_LOOP_ABSOLUTE))            WarThrow(WarError(WAR_ERR_INVALID_CASE_VALUE), NULL);        static const char *smsg[] = {            {"TIMER_ONCE"},            {"TIMER_LOOP_RELATIVE"},            {"TIMER_LOOP_ABSOLUTE"}        };        return smsg[mType];    }    virtual std::string Explain() const    {        WarCollector<char> msg;        msg << "Generic task scheduled at "             << mTime.FormatLT()            << ". Type="            << GetTypeName()            << " Delay="            << mDelay            << " ms. Fast="            << (int)mIsFast            << war_endl;        return msg.GetValue();    }    protected:    // CALLBACK    friend class WarTimer;    friend class WarTimerEventTask;    // Called from WarTimer    void DoTimer()    {        if (!mIsDead)            OnTimer();    }    // Called from WarTimer    void SetTime(const WarTime& newTime)    {        mTime = newTime;    }    virtual void OnTimer() = 0;private:    WarTime mTime; // Time for the event    timer_delay_t mDelay; // Delay in milliseconds, used for reoccuring events    TimerTypeE mType;    bool mIsDead;    bool mIsFast; // Run directly, no thread pooling};/* INLINE METHODS *//* EXTERNAL REFERENCES */typedef WarPtrWrapper<WarTimerEvent> war_timer_event_ptr_t;#endif /* __cplusplus *//****************** END C++ spesific ******************/#endif  /* WAR_TIMER_EVENT_H_ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -