2020-05-22 13:18:41 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013-2020, The PurpleI2P Project
|
|
|
|
*
|
|
|
|
* This file is part of Purple i2pd project and licensed under BSD3
|
|
|
|
*
|
|
|
|
* See full license text in LICENSE file at top of project tree
|
|
|
|
*/
|
|
|
|
|
2020-04-12 03:00:06 +00:00
|
|
|
#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"
|
|
|
|
|
2024-05-09 13:57:21 +00:00
|
|
|
class CNetworkListManagerEvent final : public INetworkListManagerEvents
|
2020-04-12 03:00:06 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CNetworkListManagerEvent() : m_ref(1) { }
|
2024-05-09 13:57:21 +00:00
|
|
|
~CNetworkListManagerEvent() { }
|
2020-04-12 03:00:06 +00:00
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject)
|
|
|
|
{
|
|
|
|
if (IsEqualIID(riid, IID_IUnknown)) {
|
|
|
|
*ppvObject = (IUnknown *)this;
|
|
|
|
} else if (IsEqualIID(riid ,IID_INetworkListManagerEvents)) {
|
|
|
|
*ppvObject = (INetworkListManagerEvents *)this;
|
|
|
|
} else {
|
2023-03-03 19:02:54 +00:00
|
|
|
return E_NOINTERFACE;
|
2020-04-12 03:00:06 +00:00
|
|
|
}
|
2020-10-03 20:32:02 +00:00
|
|
|
AddRef();
|
2023-03-03 19:02:54 +00:00
|
|
|
return S_OK;
|
2020-04-12 03:00:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2020-10-03 20:32:02 +00:00
|
|
|
#endif
|