rainmeter-studio/Library/MeasureNet.h

207 lines
5.9 KiB
C
Raw Normal View History

2009-02-10 18:37:48 +00:00
/*
Copyright (C) 2001 Kimmo Pekkola
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __MEASURENET_H__
#define __MEASURENET_H__
#include "Measure.h"
2011-02-07 08:10:47 +00:00
#include <Iphlpapi.h>
2009-02-10 18:37:48 +00:00
//
// Medium the Ndis Driver is running on (OID_GEN_MEDIA_SUPPORTED/ OID_GEN_MEDIA_IN_USE).
//
typedef enum _NDIS_MEDIUM
{
NdisMedium802_3,
NdisMedium802_5,
NdisMediumFddi,
NdisMediumWan,
NdisMediumLocalTalk,
NdisMediumDix, // defined for convenience, not a real medium
NdisMediumArcnetRaw,
NdisMediumArcnet878_2,
NdisMediumAtm,
NdisMediumWirelessWan,
NdisMediumIrda,
NdisMediumBpc,
NdisMediumCoWan,
NdisMedium1394,
NdisMediumInfiniBand,
#if ((NTDDI_VERSION >= NTDDI_LONGHORN) || NDIS_SUPPORT_NDIS6)
NdisMediumTunnel,
NdisMediumNative802_11,
NdisMediumLoopback,
#endif // (NTDDI_VERSION >= NTDDI_LONGHORN)
NdisMediumMax // Not a real medium, defined as an upper-bound
} NDIS_MEDIUM, *PNDIS_MEDIUM;
//
// Physical Medium Type definitions. Used with OID_GEN_PHYSICAL_MEDIUM.
//
typedef enum _NDIS_PHYSICAL_MEDIUM
{
NdisPhysicalMediumUnspecified,
NdisPhysicalMediumWirelessLan,
NdisPhysicalMediumCableModem,
NdisPhysicalMediumPhoneLine,
NdisPhysicalMediumPowerLine,
NdisPhysicalMediumDSL, // includes ADSL and UADSL (G.Lite)
NdisPhysicalMediumFibreChannel,
NdisPhysicalMedium1394,
NdisPhysicalMediumWirelessWan,
NdisPhysicalMediumNative802_11,
NdisPhysicalMediumBluetooth,
NdisPhysicalMediumInfiniband,
NdisPhysicalMediumWiMax,
NdisPhysicalMediumUWB,
NdisPhysicalMedium802_3,
NdisPhysicalMedium802_5,
NdisPhysicalMediumIrda,
NdisPhysicalMediumWiredWAN,
NdisPhysicalMediumWiredCoWan,
NdisPhysicalMediumOther,
NdisPhysicalMediumMax // Not a real physical type, defined as an upper-bound
} NDIS_PHYSICAL_MEDIUM, *PNDIS_PHYSICAL_MEDIUM;
typedef struct _MIB_IF_ROW2 {
//
// Key structure. Sorted by preference.
//
NET_LUID InterfaceLuid;
NET_IFINDEX InterfaceIndex;
//
// Read-Only fields.
//
GUID InterfaceGuid;
WCHAR Alias[IF_MAX_STRING_SIZE + 1];
WCHAR Description[IF_MAX_STRING_SIZE + 1];
ULONG PhysicalAddressLength;
UCHAR PhysicalAddress[IF_MAX_PHYS_ADDRESS_LENGTH];
UCHAR PermanentPhysicalAddress[IF_MAX_PHYS_ADDRESS_LENGTH];
ULONG Mtu;
IFTYPE Type; // Interface Type.
TUNNEL_TYPE TunnelType; // Tunnel Type, if Type = IF_TUNNEL.
NDIS_MEDIUM MediaType;
NDIS_PHYSICAL_MEDIUM PhysicalMediumType;
NET_IF_ACCESS_TYPE AccessType;
NET_IF_DIRECTION_TYPE DirectionType;
struct {
BOOLEAN HardwareInterface : 1;
BOOLEAN FilterInterface : 1;
BOOLEAN ConnectorPresent : 1;
BOOLEAN NotAuthenticated : 1;
BOOLEAN NotMediaConnected : 1;
BOOLEAN Paused : 1;
BOOLEAN LowPower : 1;
BOOLEAN EndPointInterface : 1;
} InterfaceAndOperStatusFlags;
IF_OPER_STATUS OperStatus;
NET_IF_ADMIN_STATUS AdminStatus;
NET_IF_MEDIA_CONNECT_STATE MediaConnectState;
NET_IF_NETWORK_GUID NetworkGuid;
NET_IF_CONNECTION_TYPE ConnectionType;
//
// Statistics.
//
ULONG64 TransmitLinkSpeed;
ULONG64 ReceiveLinkSpeed;
ULONG64 InOctets;
ULONG64 InUcastPkts;
ULONG64 InNUcastPkts;
ULONG64 InDiscards;
ULONG64 InErrors;
ULONG64 InUnknownProtos;
ULONG64 InUcastOctets;
ULONG64 InMulticastOctets;
ULONG64 InBroadcastOctets;
ULONG64 OutOctets;
ULONG64 OutUcastPkts;
ULONG64 OutNUcastPkts;
ULONG64 OutDiscards;
ULONG64 OutErrors;
ULONG64 OutUcastOctets;
ULONG64 OutMulticastOctets;
ULONG64 OutBroadcastOctets;
ULONG64 OutQLen;
} MIB_IF_ROW2, *PMIB_IF_ROW2;
typedef struct _MIB_IF_TABLE2 {
ULONG NumEntries;
MIB_IF_ROW2 Table[ANY_SIZE];
} MIB_IF_TABLE2, *PMIB_IF_TABLE2;
typedef enum _MIB_IF_TABLE_LEVEL {
MibIfTableNormal,
MibIfTableRaw
} MIB_IF_TABLE_LEVEL, *PMIB_IF_TABLE_LEVEL;
typedef NETIO_STATUS (NETIOAPI_API_ * FPGETIFTABLE2EX)(MIB_IF_TABLE_LEVEL Level, PMIB_IF_TABLE2* Table);
typedef VOID (NETIOAPI_API_ * FPFREEMIBTABLE)(PVOID Memory);
2009-02-10 18:37:48 +00:00
class CMeasureNet : public CMeasure
{
public:
enum NET {
NET_IN,
NET_OUT,
NET_TOTAL
};
CMeasureNet(CMeterWindow* meterWindow);
virtual ~CMeasureNet();
virtual bool Update();
static void UpdateIFTable();
static void UpdateStats();
static void ResetStats();
static void ReadStats(const std::wstring& iniFile);
static void WriteStats(const std::wstring& iniFile);
static void InitializeNewApi();
static void FinalizeNewApi();
2009-02-10 18:37:48 +00:00
protected:
void ReadConfig(CConfigParser& parser, const WCHAR* section, CMeasureNet::NET net);
ULONG64 GetNetOctets(NET net);
ULONG64 GetNetStatsValue(NET net);
2009-02-10 18:37:48 +00:00
double m_CurrentTraffic;
double m_TrafficValue;
UINT m_Interface;
bool m_Cumulative;
std::wstring m_TrafficAction;
static std::vector<ULONG64> c_OldStatValues;
static std::vector<ULONG64> c_StatValues;
static BYTE* c_Table;
2009-02-10 18:37:48 +00:00
static UINT c_NumOfTables;
static FPGETIFTABLE2EX c_GetIfTable2Ex;
static FPFREEMIBTABLE c_FreeMibTable;
static bool c_UseNewApi;
2009-02-10 18:37:48 +00:00
};
#endif