mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2024-11-16 00:12:43 +00: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
@ -3,11 +3,11 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
|
||||||
IUnknown *pUnknown = NULL;
|
IUnknown *pUnknown = nullptr;
|
||||||
INetworkListManager *pNetworkListManager = NULL;
|
INetworkListManager *pNetworkListManager = nullptr;
|
||||||
IConnectionPointContainer *pCPContainer = NULL;
|
IConnectionPointContainer *pCPContainer = nullptr;
|
||||||
|
IConnectionPoint *pConnectPoint = nullptr;
|
||||||
DWORD Cookie = 0;
|
DWORD Cookie = 0;
|
||||||
IConnectionPoint *pConnectPoint = NULL;
|
|
||||||
|
|
||||||
void SubscribeToEvents()
|
void SubscribeToEvents()
|
||||||
{
|
{
|
||||||
@ -20,10 +20,12 @@ void SubscribeToEvents()
|
|||||||
Result = pUnknown->QueryInterface(IID_INetworkListManager, (void **)&pNetworkListManager);
|
Result = pUnknown->QueryInterface(IID_INetworkListManager, (void **)&pNetworkListManager);
|
||||||
if (SUCCEEDED(Result))
|
if (SUCCEEDED(Result))
|
||||||
{
|
{
|
||||||
/* VARIANT_BOOL IsConnect = VARIANT_FALSE;
|
VARIANT_BOOL IsConnect = VARIANT_FALSE;
|
||||||
Result = pNetworkListManager->IsConnectedToInternet(&IsConnect);
|
Result = pNetworkListManager->IsConnectedToInternet(&IsConnect);
|
||||||
if (SUCCEEDED(Result))
|
if (SUCCEEDED(Result)) {
|
||||||
LogPrint(eLogInfo, "NetState: IsConnect Result:", IsConnect == VARIANT_TRUE ? "TRUE" : "FALSE"); */
|
i2p::transport::transports.SetOnline (true);
|
||||||
|
LogPrint(eLogInfo, "NetState: current state: ", IsConnect == VARIANT_TRUE ? "connected" : "disconnected");
|
||||||
|
}
|
||||||
|
|
||||||
Result = pNetworkListManager->QueryInterface(IID_IConnectionPointContainer, (void **)&pCPContainer);
|
Result = pNetworkListManager->QueryInterface(IID_IConnectionPointContainer, (void **)&pCPContainer);
|
||||||
if (SUCCEEDED(Result))
|
if (SUCCEEDED(Result))
|
||||||
@ -35,6 +37,8 @@ void SubscribeToEvents()
|
|||||||
Result = pConnectPoint->Advise((IUnknown *)NetEvent, &Cookie);
|
Result = pConnectPoint->Advise((IUnknown *)NetEvent, &Cookie);
|
||||||
if (SUCCEEDED(Result))
|
if (SUCCEEDED(Result))
|
||||||
LogPrint(eLogInfo, "NetState: Successfully subscribed to NetworkListManagerEvent messages");
|
LogPrint(eLogInfo, "NetState: Successfully subscribed to NetworkListManagerEvent messages");
|
||||||
|
else
|
||||||
|
LogPrint(eLogError, "NetState: Unable to subscribe to NetworkListManagerEvent messages");
|
||||||
} else
|
} else
|
||||||
LogPrint(eLogError, "NetState: Unable to find interface connection point");
|
LogPrint(eLogError, "NetState: Unable to find interface connection point");
|
||||||
} else
|
} else
|
||||||
@ -47,13 +51,28 @@ void SubscribeToEvents()
|
|||||||
|
|
||||||
void UnSubscribeFromEvents()
|
void UnSubscribeFromEvents()
|
||||||
{
|
{
|
||||||
// TODO - DETECT EVERY STAGE STATE and call functions depending it !!!
|
try
|
||||||
|
{
|
||||||
|
if (pConnectPoint) {
|
||||||
pConnectPoint->Unadvise(Cookie);
|
pConnectPoint->Unadvise(Cookie);
|
||||||
pConnectPoint->Release();
|
pConnectPoint->Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pCPContainer)
|
||||||
pCPContainer->Release();
|
pCPContainer->Release();
|
||||||
|
|
||||||
|
if (pNetworkListManager)
|
||||||
pNetworkListManager->Release();
|
pNetworkListManager->Release();
|
||||||
|
|
||||||
|
if (pUnknown)
|
||||||
pUnknown->Release();
|
pUnknown->Release();
|
||||||
|
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
|
}
|
||||||
|
catch (std::exception& ex)
|
||||||
|
{
|
||||||
|
LogPrint (eLogError, "NetState: received exception: ", ex.what ());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // WINVER
|
#endif // WINVER
|
||||||
|
@ -42,20 +42,28 @@ public:
|
|||||||
|
|
||||||
virtual HRESULT STDMETHODCALLTYPE ConnectivityChanged(NLM_CONNECTIVITY newConnectivity)
|
virtual HRESULT STDMETHODCALLTYPE ConnectivityChanged(NLM_CONNECTIVITY newConnectivity)
|
||||||
{
|
{
|
||||||
if (newConnectivity == NLM_CONNECTIVITY_DISCONNECTED)
|
if (newConnectivity == NLM_CONNECTIVITY_DISCONNECTED) {
|
||||||
|
i2p::transport::transports.SetOnline (false);
|
||||||
LogPrint(eLogInfo, "NetState: disconnected from network");
|
LogPrint(eLogInfo, "NetState: disconnected from network");
|
||||||
|
}
|
||||||
|
|
||||||
if (((int)newConnectivity & (int)NLM_CONNECTIVITY_IPV4_INTERNET) != 0)
|
if (((int)newConnectivity & (int)NLM_CONNECTIVITY_IPV4_INTERNET) != 0) {
|
||||||
|
i2p::transport::transports.SetOnline (true);
|
||||||
LogPrint(eLogInfo, "NetState: connected to internet with IPv4 capability");
|
LogPrint(eLogInfo, "NetState: connected to internet with IPv4 capability");
|
||||||
|
}
|
||||||
|
|
||||||
if (((int)newConnectivity & (int)NLM_CONNECTIVITY_IPV6_INTERNET) != 0)
|
if (((int)newConnectivity & (int)NLM_CONNECTIVITY_IPV6_INTERNET) != 0) {
|
||||||
|
i2p::transport::transports.SetOnline (true);
|
||||||
LogPrint(eLogInfo, "NetState: connected to internet with IPv6 capability");
|
LogPrint(eLogInfo, "NetState: connected to internet with IPv6 capability");
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(((int)newConnectivity & (int)NLM_CONNECTIVITY_IPV4_INTERNET) == 0) &&
|
(((int)newConnectivity & (int)NLM_CONNECTIVITY_IPV4_INTERNET) == 0) &&
|
||||||
(((int)newConnectivity & (int)NLM_CONNECTIVITY_IPV6_INTERNET) == 0)
|
(((int)newConnectivity & (int)NLM_CONNECTIVITY_IPV6_INTERNET) == 0)
|
||||||
)
|
) {
|
||||||
|
i2p::transport::transports.SetOnline (false);
|
||||||
LogPrint(eLogInfo, "NetState: connected without internet access");
|
LogPrint(eLogInfo, "NetState: connected without internet access");
|
||||||
|
}
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user