diff --git a/Library/MeasureNet.cpp b/Library/MeasureNet.cpp index eb90a64e..547103cb 100644 --- a/Library/MeasureNet.cpp +++ b/Library/MeasureNet.cpp @@ -35,8 +35,11 @@ extern CRainmeter* Rainmeter; ** The constructor. This is the base class for the net-meters. ** */ -CMeasureNet::CMeasureNet(CMeterWindow* meterWindow, const WCHAR* name) : CMeasure(meterWindow, name), +CMeasureNet::CMeasureNet(CMeterWindow* meterWindow, const WCHAR* name, NET type) : CMeasure(meterWindow, name), + m_Net(type), m_Interface(), + m_Octets(), + m_FirstTime(true), m_Cumulative(false) { } @@ -408,25 +411,68 @@ ULONG64 CMeasureNet::GetNetStatsValue(NET net) } /* -** Read the options specified in the ini file. Base implementation for In/Out/Total. +** Updates the current value. ** */ -void CMeasureNet::ReadOptions(CConfigParser& parser, const WCHAR* section, NET net) +void CMeasureNet::UpdateValue() { + if (c_Table == NULL) return; + + if (m_Cumulative) + { + m_Value = (double)(__int64)GetNetStatsValue(m_Net); + } + else + { + ULONG64 value = 0; + + if (!m_FirstTime) + { + value = GetNetOctets(m_Net); + if (value > m_Octets) + { + ULONG64 tmpValue = value; + value -= m_Octets; + m_Octets = tmpValue; + } + else + { + m_Octets = value; + value = 0; + } + } + else + { + m_Octets = GetNetOctets(m_Net); + m_FirstTime = false; + } + + m_Value = (double)(__int64)value; + } +} + +/* +** Read the options specified in the ini file. +** +*/ +void CMeasureNet::ReadOptions(CConfigParser& parser, const WCHAR* section) +{ + CMeasure::ReadOptions(parser, section); + double value; const WCHAR* netName = NULL; - if (net == NET_IN) + if (m_Net == NET_IN) { netName = L"NetInSpeed"; value = Rainmeter->GetGlobalOptions().netInSpeed; } - else if (net == NET_OUT) + else if (m_Net == NET_OUT) { netName = L"NetOutSpeed"; value = Rainmeter->GetGlobalOptions().netOutSpeed; } - else + else // if (m_Net == NET_TOTAL) { netName = L"NetTotalSpeed"; value = Rainmeter->GetGlobalOptions().netInSpeed + Rainmeter->GetGlobalOptions().netOutSpeed; diff --git a/Library/MeasureNet.h b/Library/MeasureNet.h index 746367fe..9155a525 100644 --- a/Library/MeasureNet.h +++ b/Library/MeasureNet.h @@ -30,16 +30,6 @@ typedef VOID (NETIOAPI_API_ * FPFREEMIBTABLE)(PVOID Memory); class CMeasureNet : public CMeasure { public: - enum NET - { - NET_IN, - NET_OUT, - NET_TOTAL - }; - - CMeasureNet(CMeterWindow* meterWindow, const WCHAR* name); - virtual ~CMeasureNet(); - virtual UINT GetTypeID() { return TypeID(); } static void UpdateIFTable(); @@ -53,12 +43,28 @@ public: static void FinalizeNewApi(); protected: - void ReadOptions(CConfigParser& parser, const WCHAR* section, CMeasureNet::NET net); + enum NET + { + NET_IN, + NET_OUT, + NET_TOTAL + }; + CMeasureNet(CMeterWindow* meterWindow, const WCHAR* name, NET type); + virtual ~CMeasureNet(); + + virtual void ReadOptions(CConfigParser& parser, const WCHAR* section); + virtual void UpdateValue(); + +private: ULONG64 GetNetOctets(NET net); ULONG64 GetNetStatsValue(NET net); + NET m_Net; UINT m_Interface; + + ULONG64 m_Octets; + bool m_FirstTime; bool m_Cumulative; static std::vector c_OldStatValues; diff --git a/Library/MeasureNetIn.cpp b/Library/MeasureNetIn.cpp index a39a7fde..5a430ef3 100644 --- a/Library/MeasureNetIn.cpp +++ b/Library/MeasureNetIn.cpp @@ -23,9 +23,7 @@ ** The constructor ** */ -CMeasureNetIn::CMeasureNetIn(CMeterWindow* meterWindow, const WCHAR* name) : CMeasureNet(meterWindow, name), - m_FirstTime(true), - m_InOctets() +CMeasureNetIn::CMeasureNetIn(CMeterWindow* meterWindow, const WCHAR* name) : CMeasureNet(meterWindow, name, NET_IN) { } @@ -35,56 +33,4 @@ CMeasureNetIn::CMeasureNetIn(CMeterWindow* meterWindow, const WCHAR* name) : CMe */ CMeasureNetIn::~CMeasureNetIn() { -} - -/* -** Updates the current net in value. -** -*/ -void CMeasureNetIn::UpdateValue() -{ - if (c_Table == NULL) return; - - if (m_Cumulative) - { - m_Value = (double)(__int64)GetNetStatsValue(NET_IN); - } - else - { - ULONG64 value = 0; - - if (!m_FirstTime) - { - value = GetNetOctets(NET_IN); - if (value > m_InOctets) - { - ULONG64 tmpValue = value; - value -= m_InOctets; - m_InOctets = tmpValue; - } - else - { - m_InOctets = value; - value = 0; - } - } - else - { - m_InOctets = GetNetOctets(NET_IN); - m_FirstTime = false; - } - - m_Value = (double)(__int64)value; - } -} - -/* -** Read the options specified in the ini file. -** -*/ -void CMeasureNetIn::ReadOptions(CConfigParser& parser, const WCHAR* section) -{ - CMeasure::ReadOptions(parser, section); - CMeasureNet::ReadOptions(parser, section, NET_IN); -} - +} \ No newline at end of file diff --git a/Library/MeasureNetIn.h b/Library/MeasureNetIn.h index 39515f19..d63c4bbd 100644 --- a/Library/MeasureNetIn.h +++ b/Library/MeasureNetIn.h @@ -16,8 +16,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef __METERNET_H__ -#define __METERNET_H__ +#ifndef __MEASURENETIN_H__ +#define __MEASURENETIN_H__ #include "MeasureNet.h" @@ -26,14 +26,6 @@ class CMeasureNetIn : public CMeasureNet public: CMeasureNetIn(CMeterWindow* meterWindow, const WCHAR* name); virtual ~CMeasureNetIn(); - -protected: - virtual void ReadOptions(CConfigParser& parser, const WCHAR* section); - virtual void UpdateValue(); - -private: - bool m_FirstTime; - ULONG64 m_InOctets; }; #endif diff --git a/Library/MeasureNetOut.cpp b/Library/MeasureNetOut.cpp index b3a7e546..153e770a 100644 --- a/Library/MeasureNetOut.cpp +++ b/Library/MeasureNetOut.cpp @@ -23,9 +23,7 @@ ** The constructor ** */ -CMeasureNetOut::CMeasureNetOut(CMeterWindow* meterWindow, const WCHAR* name) : CMeasureNet(meterWindow, name), - m_FirstTime(true), - m_OutOctets() +CMeasureNetOut::CMeasureNetOut(CMeterWindow* meterWindow, const WCHAR* name) : CMeasureNet(meterWindow, name, NET_OUT) { } @@ -36,54 +34,3 @@ CMeasureNetOut::CMeasureNetOut(CMeterWindow* meterWindow, const WCHAR* name) : C CMeasureNetOut::~CMeasureNetOut() { } - -/* -** Updates the current net out value. -** -*/ -void CMeasureNetOut::UpdateValue() -{ - if (c_Table == NULL) return; - - if (m_Cumulative) - { - m_Value = (double)(__int64)GetNetStatsValue(NET_OUT); - } - else - { - ULONG64 value = 0; - - if (!m_FirstTime) - { - value = GetNetOctets(NET_OUT); - if (value > m_OutOctets) - { - ULONG64 tmpValue = value; - value -= m_OutOctets; - m_OutOctets = tmpValue; - } - else - { - m_OutOctets = value; - value = 0; - } - } - else - { - m_OutOctets = GetNetOctets(NET_OUT); - m_FirstTime = false; - } - - m_Value = (double)(__int64)value; - } -} - -/* -** Read the options specified in the ini file. -** -*/ -void CMeasureNetOut::ReadOptions(CConfigParser& parser, const WCHAR* section) -{ - CMeasure::ReadOptions(parser, section); - CMeasureNet::ReadOptions(parser, section, NET_OUT); -} diff --git a/Library/MeasureNetOut.h b/Library/MeasureNetOut.h index 804b9f50..ce4bfc00 100644 --- a/Library/MeasureNetOut.h +++ b/Library/MeasureNetOut.h @@ -16,8 +16,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef __METERNETOUT_H__ -#define __METERNETOUT_H__ +#ifndef __MEASURENETOUT_H__ +#define __MEASURENETOUT_H__ #include "MeasureNet.h" @@ -26,14 +26,6 @@ class CMeasureNetOut : public CMeasureNet public: CMeasureNetOut(CMeterWindow* meterWindow, const WCHAR* name); virtual ~CMeasureNetOut(); - -protected: - virtual void ReadOptions(CConfigParser& parser, const WCHAR* section); - virtual void UpdateValue(); - -private: - bool m_FirstTime; - ULONG64 m_OutOctets; }; #endif diff --git a/Library/MeasureNetTotal.cpp b/Library/MeasureNetTotal.cpp index 9606e75a..7521be53 100644 --- a/Library/MeasureNetTotal.cpp +++ b/Library/MeasureNetTotal.cpp @@ -23,9 +23,7 @@ ** The constructor ** */ -CMeasureNetTotal::CMeasureNetTotal(CMeterWindow* meterWindow, const WCHAR* name) : CMeasureNet(meterWindow, name), - m_FirstTime(true), - m_TotalOctets() +CMeasureNetTotal::CMeasureNetTotal(CMeterWindow* meterWindow, const WCHAR* name) : CMeasureNet(meterWindow, name, NET_TOTAL) { } @@ -36,54 +34,3 @@ CMeasureNetTotal::CMeasureNetTotal(CMeterWindow* meterWindow, const WCHAR* name) CMeasureNetTotal::~CMeasureNetTotal() { } - -/* -** Updates the current net total value. -** -*/ -void CMeasureNetTotal::UpdateValue() -{ - if (c_Table == NULL) return; - - if (m_Cumulative) - { - m_Value = (double)(__int64)GetNetStatsValue(NET_TOTAL); - } - else - { - ULONG64 value = 0; - - if (!m_FirstTime) - { - value = GetNetOctets(NET_TOTAL); - if (value > m_TotalOctets) - { - ULONG64 tmpValue = value; - value -= m_TotalOctets; - m_TotalOctets = tmpValue; - } - else - { - m_TotalOctets = value; - value = 0; - } - } - else - { - m_TotalOctets = GetNetOctets(NET_TOTAL); - m_FirstTime = false; - } - - m_Value = (double)(__int64)value; - } -} - -/* -** Read the options specified in the ini file. -** -*/ -void CMeasureNetTotal::ReadOptions(CConfigParser& parser, const WCHAR* section) -{ - CMeasure::ReadOptions(parser, section); - CMeasureNet::ReadOptions(parser, section, NET_TOTAL); -} diff --git a/Library/MeasureNetTotal.h b/Library/MeasureNetTotal.h index 92f6db5d..2b298d69 100644 --- a/Library/MeasureNetTotal.h +++ b/Library/MeasureNetTotal.h @@ -16,8 +16,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef __METERNETTOTAL_H__ -#define __METERNETTOTAL_H__ +#ifndef __MEASURENETTOTAL_H__ +#define __MEASURENETTOTAL_H__ #include "MeasureNet.h" @@ -26,14 +26,6 @@ class CMeasureNetTotal : public CMeasureNet public: CMeasureNetTotal(CMeterWindow* meterWindow, const WCHAR* name); virtual ~CMeasureNetTotal(); - -protected: - virtual void ReadOptions(CConfigParser& parser, const WCHAR* section); - virtual void UpdateValue(); - -private: - bool m_FirstTime; - ULONG64 m_TotalOctets; }; #endif