|
|
@ -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
|
|
|
|