mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
[windows] update flag on connectivity state changes, CRLF > LF
Signed-off-by: R4SAS <r4sas@i2pmail.org>
This commit is contained in:
parent
90914bb2de
commit
152e579f7e
2 changed files with 162 additions and 135 deletions
|
@ -1,77 +1,85 @@
|
|||
#ifndef WIN_32_NETSTATE_H__
|
||||
#define WIN_32_NETSTATE_H__
|
||||
|
||||
#if WINVER != 0x0501 // supported since Vista
|
||||
#include <netlistmgr.h>
|
||||
#include <ocidl.h>
|
||||
#include "Log.h"
|
||||
#include "Transports.h"
|
||||
|
||||
class CNetworkListManagerEvent : public INetworkListManagerEvents
|
||||
{
|
||||
public:
|
||||
CNetworkListManagerEvent() : m_ref(1) { }
|
||||
~CNetworkListManagerEvent() { }
|
||||
|
||||
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject)
|
||||
{
|
||||
HRESULT Result = S_OK;
|
||||
if (IsEqualIID(riid, IID_IUnknown)) {
|
||||
*ppvObject = (IUnknown *)this;
|
||||
} else if (IsEqualIID(riid ,IID_INetworkListManagerEvents)) {
|
||||
*ppvObject = (INetworkListManagerEvents *)this;
|
||||
} else {
|
||||
Result = E_NOINTERFACE;
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
ULONG STDMETHODCALLTYPE AddRef()
|
||||
{
|
||||
return (ULONG)InterlockedIncrement(&m_ref);
|
||||
}
|
||||
|
||||
ULONG STDMETHODCALLTYPE Release()
|
||||
{
|
||||
LONG Result = InterlockedDecrement(&m_ref);
|
||||
if (Result == 0)
|
||||
delete this;
|
||||
return (ULONG)Result;
|
||||
}
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE ConnectivityChanged(NLM_CONNECTIVITY newConnectivity)
|
||||
{
|
||||
if (newConnectivity == NLM_CONNECTIVITY_DISCONNECTED)
|
||||
LogPrint(eLogInfo, "NetState: disconnected from network");
|
||||
|
||||
if (((int)newConnectivity & (int)NLM_CONNECTIVITY_IPV4_INTERNET) != 0)
|
||||
LogPrint(eLogInfo, "NetState: connected to internet with IPv4 capability");
|
||||
|
||||
if (((int)newConnectivity & (int)NLM_CONNECTIVITY_IPV6_INTERNET) != 0)
|
||||
LogPrint(eLogInfo, "NetState: connected to internet with IPv6 capability");
|
||||
|
||||
if (
|
||||
(((int)newConnectivity & (int)NLM_CONNECTIVITY_IPV4_INTERNET) == 0) &&
|
||||
(((int)newConnectivity & (int)NLM_CONNECTIVITY_IPV6_INTERNET) == 0)
|
||||
)
|
||||
LogPrint(eLogInfo, "NetState: connected without internet access");
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
LONG m_ref;
|
||||
};
|
||||
|
||||
void SubscribeToEvents();
|
||||
void UnSubscribeFromEvents();
|
||||
|
||||
#else // WINVER == 0x0501
|
||||
|
||||
void SubscribeToEvents() { }
|
||||
void UnSubscribeFromEvents() { }
|
||||
|
||||
#endif // WINVER
|
||||
#ifndef WIN_32_NETSTATE_H__
|
||||
#define WIN_32_NETSTATE_H__
|
||||
|
||||
#if WINVER != 0x0501 // supported since Vista
|
||||
#include <netlistmgr.h>
|
||||
#include <ocidl.h>
|
||||
#include "Log.h"
|
||||
#include "Transports.h"
|
||||
|
||||
class CNetworkListManagerEvent : public INetworkListManagerEvents
|
||||
{
|
||||
public:
|
||||
CNetworkListManagerEvent() : m_ref(1) { }
|
||||
~CNetworkListManagerEvent() { }
|
||||
|
||||
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject)
|
||||
{
|
||||
HRESULT Result = S_OK;
|
||||
if (IsEqualIID(riid, IID_IUnknown)) {
|
||||
*ppvObject = (IUnknown *)this;
|
||||
} else if (IsEqualIID(riid ,IID_INetworkListManagerEvents)) {
|
||||
*ppvObject = (INetworkListManagerEvents *)this;
|
||||
} else {
|
||||
Result = E_NOINTERFACE;
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
ULONG STDMETHODCALLTYPE AddRef()
|
||||
{
|
||||
return (ULONG)InterlockedIncrement(&m_ref);
|
||||
}
|
||||
|
||||
ULONG STDMETHODCALLTYPE Release()
|
||||
{
|
||||
LONG Result = InterlockedDecrement(&m_ref);
|
||||
if (Result == 0)
|
||||
delete this;
|
||||
return (ULONG)Result;
|
||||
}
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE ConnectivityChanged(NLM_CONNECTIVITY newConnectivity)
|
||||
{
|
||||
if (newConnectivity == NLM_CONNECTIVITY_DISCONNECTED) {
|
||||
i2p::transport::transports.SetOnline (false);
|
||||
LogPrint(eLogInfo, "NetState: disconnected from network");
|
||||
}
|
||||
|
||||
if (((int)newConnectivity & (int)NLM_CONNECTIVITY_IPV4_INTERNET) != 0) {
|
||||
i2p::transport::transports.SetOnline (true);
|
||||
LogPrint(eLogInfo, "NetState: connected to internet with IPv4 capability");
|
||||
}
|
||||
|
||||
if (((int)newConnectivity & (int)NLM_CONNECTIVITY_IPV6_INTERNET) != 0) {
|
||||
i2p::transport::transports.SetOnline (true);
|
||||
LogPrint(eLogInfo, "NetState: connected to internet with IPv6 capability");
|
||||
}
|
||||
|
||||
if (
|
||||
(((int)newConnectivity & (int)NLM_CONNECTIVITY_IPV4_INTERNET) == 0) &&
|
||||
(((int)newConnectivity & (int)NLM_CONNECTIVITY_IPV6_INTERNET) == 0)
|
||||
) {
|
||||
i2p::transport::transports.SetOnline (false);
|
||||
LogPrint(eLogInfo, "NetState: connected without internet access");
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
LONG m_ref;
|
||||
};
|
||||
|
||||
void SubscribeToEvents();
|
||||
void UnSubscribeFromEvents();
|
||||
|
||||
#else // WINVER == 0x0501
|
||||
|
||||
void SubscribeToEvents() { }
|
||||
void UnSubscribeFromEvents() { }
|
||||
|
||||
#endif // WINVER
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue