📄 warsvrprotocolftpstat.h
字号:
/** */#ifndef WAR_SVR_PROTOCOL_FTP_STAT_H#define WAR_SVR_PROTOCOL_FTP_STAT_H/* SYSTEM INCLUDES */#ifndef WAR_TYPES_H# include "WarTypes.h"#endif#ifndef WAR_AUTO_LOCK_H# include "WarAutoLock.h"#endif#ifndef WAR_EXCEPTION_H# include "WarException.h"#endif/* PROJECT INCLUDES *//* 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 WarSvrProtocolFtpStat {public: enum StatItemE { // File transfers ST_FILETRANS_BYTES_IN, ST_FILETRANS_BYTES_OUT, ST_FILETRANS_FILES_IN, ST_FILETRANS_FILES_OUT, // File transfers that failed ST_FAILED_FILETRANS_BYTES_IN, ST_FAILED_FILETRANS_BYTES_OUT, ST_FAILED_FILETRANS_FILES_IN, ST_FAILED_FILETRANS_FILES_OUT, // Tmp transfers (tyically dir-listings) ST_TMPTRANS_BYTES_IN, ST_TMPTRANS_BYTES_OUT, ST_TMPTRANS_FILES_IN, ST_TMPTRANS_FILES_OUT, // Tmp transfers (tyically dir-listings) that failed ST_FAILED_TMPTRANS_BYTES_IN, ST_FAILED_TMPTRANS_BYTES_OUT, ST_FAILED_TMPTRANS_FILES_IN, ST_FAILED_TMPTRANS_FILES_OUT, // Control connection ST_CNTR_BYTES_IN, ST_CNTR_BYTES_OUT, // User login stats ST_LOGINS_WITH_SUCCESS, ST_LOGINS_WITH_FAIL, // Users failed logins in sequence // (reset by a successful login) ST_LOGINS_SEQ_WITH_FAIL, // CPU time used by the user in seconds/1000 ST_CPUTIME, ST_INVALID }; // LIFECYCLE /** * Default constructor. */ WarSvrProtocolFtpStat(void) { memset(&mStats, 0, sizeof(mStats)); mCookie = ++msCookie; } /** * Copy constructor. * * @param from The value to copy to this object. */ WarSvrProtocolFtpStat(const WarSvrProtocolFtpStat& from) { mCookie = ++msCookie; operator = (from); } /** * Destructor. */ ~WarSvrProtocolFtpStat(void) {} // OPERATORS WarSvrProtocolFtpStat& operator = (const WarSvrProtocolFtpStat& from) { // Prevent dead-locks by using the cookie // to ensure that locks always are // taken in the same order. if (mCookie < from.mCookie) { WarAutoLock my_lock(mLock); WarAutoLock his_lock((WarCriticalSection&)from.mLock); for(int i = 0; i < ST_INVALID; i++) mStats[i] = from.mStats[i]; } else { WarAutoLock his_lock((WarCriticalSection&)from.mLock); WarAutoLock my_lock(mLock); for(int i = 0; i < ST_INVALID; i++) mStats[i] = from.mStats[i]; } return *this; } WarSvrProtocolFtpStat& operator += (const WarSvrProtocolFtpStat& from) { // Prevent dead-locks by using the cookie // to ensure that locks always are // taken in the same order. if (mCookie < from.mCookie) { WarAutoLock my_lock(mLock); WarAutoLock his_lock((WarCriticalSection&)from.mLock); for(int i = 0; i < ST_INVALID; i++) mStats[i] += from.mStats[i]; } else { WarAutoLock his_lock((WarCriticalSection&)from.mLock); WarAutoLock my_lock(mLock); for(int i = 0; i < ST_INVALID; i++) mStats[i] += from.mStats[i]; } return *this; } // OPERATIONS // ACCESS void SetValue(const StatItemE index, const war_int64_t value) { Verify(index); WarAutoLock my_lock(mLock); mStats[index] = value; }; void AddValue(const StatItemE index, const war_int64_t value) { Verify(index); WarAutoLock my_lock(mLock); mStats[index] += value; }; // INQUIRY const war_int64_t GetValue(const StatItemE index) const { Verify(index); WarAutoLock my_lock((WarCriticalSection&)mLock); return mStats[index]; }; protected: inline void Verify(const StatItemE index) const { if ((index < 0) || (index >= ST_INVALID)) WarThrow(WarError(WAR_ERR_OUT_OF_RANGE), NULL); } war_int64_t mStats[ST_INVALID]; war_int64_t mCookie; WarCriticalSection mLock;private: static war_int64_t msCookie;};/* INLINE METHODS *//* EXTERNAL REFERENCES */#endif /* __cplusplus *//****************** END C++ spesific ******************/#endif /* WAR_SVR_PROTOCOL_FTP_STAT_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -