From: Maxim Mamontov Date: Wed, 8 Dec 2010 14:03:35 +0000 (+0200) Subject: Проведен рефакторинг библиотеки поддержки ICMP, некоторые методы сделаны X-Git-Tag: 2.407-rc3~314 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/5924017d951d69132f2b8522dfa04927abc417d0?ds=sidebyside Проведен рефакторинг библиотеки поддержки ICMP, некоторые методы сделаны константными, добавлена инициализация членов класса в конструкторе --- diff --git a/stglibs/pinger.lib/pinger.cpp b/stglibs/pinger.lib/pinger.cpp index 9169b4e6..edbcd11e 100644 --- a/stglibs/pinger.lib/pinger.cpp +++ b/stglibs/pinger.lib/pinger.cpp @@ -24,10 +24,15 @@ extern volatile time_t stgTime; //----------------------------------------------------------------------------- STG_PINGER::STG_PINGER(time_t d) + : delay(d), + nonstop(false), + isRunningRecver(false), + isRunningSender(false), + sendSocket(-1), + recvSocket(-1), + pid(0) { - delay = d; pthread_mutex_init(&mutex, NULL); - pid = 0; } //----------------------------------------------------------------------------- STG_PINGER::~STG_PINGER() @@ -172,15 +177,15 @@ void STG_PINGER::RealDelIP() ipToDel.erase(ipToDel.begin(), ipToDel.end()); } //----------------------------------------------------------------------------- -int STG_PINGER::GetPingIPNum() +int STG_PINGER::GetPingIPNum() const { return pingIP.size(); } //----------------------------------------------------------------------------- -void STG_PINGER::GetAllIP(vector *) +/*void STG_PINGER::GetAllIP(vector *) const { //STG_LOCKER lock(&mutex, __FILE__, __LINE__); -} +}*/ //----------------------------------------------------------------------------- void STG_PINGER::PrintAllIP() { @@ -199,10 +204,10 @@ void STG_PINGER::PrintAllIP() } //----------------------------------------------------------------------------- -int STG_PINGER::GetIPTime(uint32_t ip, time_t * t) +int STG_PINGER::GetIPTime(uint32_t ip, time_t * t) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); - multimap::iterator treeIter; + multimap::const_iterator treeIter; treeIter = pingIP.find(ip); if (treeIter == pingIP.end()) @@ -217,12 +222,12 @@ void STG_PINGER::SetDelayTime(time_t d) delay = d; } //----------------------------------------------------------------------------- -time_t STG_PINGER::GetDelayTime() +time_t STG_PINGER::GetDelayTime() const { return delay; } //----------------------------------------------------------------------------- -string STG_PINGER::GetStrError() +string STG_PINGER::GetStrError() const { return errorStr; } @@ -385,4 +390,3 @@ void * STG_PINGER::RunRecvPing(void * d) return NULL; } //----------------------------------------------------------------------------- - diff --git a/stglibs/pinger.lib/pinger.h b/stglibs/pinger.lib/pinger.h index 4349eb07..1398332d 100644 --- a/stglibs/pinger.lib/pinger.h +++ b/stglibs/pinger.lib/pinger.h @@ -7,7 +7,7 @@ #ifndef PINGER_H #define PINGER_H -#include +#include #include #include #include @@ -94,15 +94,23 @@ public: int Stop(); void AddIP(uint32_t ip); void DelIP(uint32_t ip); - int GetPingIPNum(); - void GetAllIP(vector * ipTime); + int GetPingIPNum() const; + //void GetAllIP(vector * ipTime) const; void PrintAllIP(); - int GetIPTime(uint32_t ip, time_t * t); + int GetIPTime(uint32_t ip, time_t * t) const; void SetDelayTime(time_t delay); - time_t GetDelayTime(); - string GetStrError(); + time_t GetDelayTime() const; + string GetStrError() const; private: + uint16_t PingCheckSum(void * data, int len); + int SendPing(uint32_t ip); + uint32_t RecvPing(); + void RealAddIP(); + void RealDelIP(); + + static void * RunSendPing(void * d); + static void * RunRecvPing(void * d); int delay; bool nonstop; @@ -116,24 +124,13 @@ private: PING_MESSAGE pmSend; uint32_t pid; - uint16_t PingCheckSum(void * data, int len); - int SendPing(uint32_t ip); - uint32_t RecvPing(); - void RealAddIP(); - void RealDelIP(); - - static void * RunSendPing(void * d); - static void * RunRecvPing(void * d); - string errorStr; multimap pingIP; list ipToAdd; list ipToDel; - pthread_mutex_t mutex; + mutable pthread_mutex_t mutex; }; //----------------------------------------------------------------------------- #endif - -