Add more debug prints to network reachability monitor
This commit is contained in:
parent
8c4eb6c05f
commit
09efd684ca
@ -37,6 +37,13 @@ NetworkReachabilityMonitor::NetworkReachabilityMonitor(QObject *parent)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NetworkReachabilityMonitor::~NetworkReachabilityMonitor()
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_IOS
|
||||||
|
teardownIOS();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
NymeaConnection::BearerTypes NetworkReachabilityMonitor::availableBearerTypes() const
|
NymeaConnection::BearerTypes NetworkReachabilityMonitor::availableBearerTypes() const
|
||||||
{
|
{
|
||||||
return m_availableBearerTypes;
|
return m_availableBearerTypes;
|
||||||
|
|||||||
@ -16,6 +16,7 @@ class NetworkReachabilityMonitor : public QObject
|
|||||||
Q_PROPERTY(NymeaConnection::BearerTypes availableBearerTypes READ availableBearerTypes NOTIFY availableBearerTypesChanged)
|
Q_PROPERTY(NymeaConnection::BearerTypes availableBearerTypes READ availableBearerTypes NOTIFY availableBearerTypesChanged)
|
||||||
public:
|
public:
|
||||||
explicit NetworkReachabilityMonitor(QObject *parent = nullptr);
|
explicit NetworkReachabilityMonitor(QObject *parent = nullptr);
|
||||||
|
~NetworkReachabilityMonitor();
|
||||||
|
|
||||||
NymeaConnection::BearerTypes availableBearerTypes() const;
|
NymeaConnection::BearerTypes availableBearerTypes() const;
|
||||||
|
|
||||||
@ -34,7 +35,8 @@ private:
|
|||||||
|
|
||||||
#ifdef Q_OS_IOS
|
#ifdef Q_OS_IOS
|
||||||
void setupIOS();
|
void setupIOS();
|
||||||
SCNetworkReachabilityRef _reachabilityRef;
|
void teardownIOS();
|
||||||
|
SCNetworkReachabilityRef m_reachabilityRef;
|
||||||
static NymeaConnection::BearerType flagsToBearerType(SCNetworkReachabilityFlags flags);
|
static NymeaConnection::BearerType flagsToBearerType(SCNetworkReachabilityFlags flags);
|
||||||
static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info);
|
static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -10,7 +10,8 @@
|
|||||||
#import <netinet/in.h>
|
#import <netinet/in.h>
|
||||||
#import <CoreFoundation/CoreFoundation.h>
|
#import <CoreFoundation/CoreFoundation.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QLoggingCategory>
|
||||||
|
Q_DECLARE_LOGGING_CATEGORY(dcNymeaConnection)
|
||||||
|
|
||||||
void NetworkReachabilityMonitor::ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info)
|
void NetworkReachabilityMonitor::ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info)
|
||||||
{
|
{
|
||||||
@ -19,9 +20,9 @@ void NetworkReachabilityMonitor::ReachabilityCallback(SCNetworkReachabilityRef t
|
|||||||
|
|
||||||
NetworkReachabilityMonitor* thiz = (__bridge NetworkReachabilityMonitor *)info;
|
NetworkReachabilityMonitor* thiz = (__bridge NetworkReachabilityMonitor *)info;
|
||||||
// Post a notification to notify the client that the network reachability changed.
|
// Post a notification to notify the client that the network reachability changed.
|
||||||
qCritical() << "******* network reachability changed";
|
|
||||||
NymeaConnection::BearerTypes old = thiz->m_availableBearerTypes;
|
NymeaConnection::BearerTypes old = thiz->m_availableBearerTypes;
|
||||||
thiz->m_availableBearerTypes = flagsToBearerType(flags);
|
thiz->m_availableBearerTypes = flagsToBearerType(flags);
|
||||||
|
qCDebug(dcNymeaConnection()) << "Network reachability changed. Old bearers:" << old << "New bearers:" << thiz->m_availableBearerTypes << "(Flags:" << flags << ")";
|
||||||
if (thiz->m_availableBearerTypes != old) {
|
if (thiz->m_availableBearerTypes != old) {
|
||||||
emit thiz->availableBearerTypesChanged();
|
emit thiz->availableBearerTypesChanged();
|
||||||
}
|
}
|
||||||
@ -35,32 +36,29 @@ void NetworkReachabilityMonitor::setupIOS()
|
|||||||
zeroAddress.sin_len = sizeof(zeroAddress);
|
zeroAddress.sin_len = sizeof(zeroAddress);
|
||||||
zeroAddress.sin_family = AF_INET;
|
zeroAddress.sin_family = AF_INET;
|
||||||
|
|
||||||
SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr *)&zeroAddress);
|
m_reachabilityRef = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr *)&zeroAddress);
|
||||||
if (reachability != NULL) {
|
if (m_reachabilityRef == NULL) {
|
||||||
_reachabilityRef = reachability;
|
qCCritical(dcNymeaConnection()) << "Error setting up reachability monitor";
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCNetworkReachabilityContext context = {0, (__bridge void *)(this), NULL, NULL, NULL};
|
SCNetworkReachabilityContext context = {0, (__bridge void *)(this), NULL, NULL, NULL};
|
||||||
qCritical() << "Registering callback";
|
if (SCNetworkReachabilitySetCallback(m_reachabilityRef, ReachabilityCallback, &context)) {
|
||||||
if (SCNetworkReachabilitySetCallback(_reachabilityRef, ReachabilityCallback, &context)) {
|
if (SCNetworkReachabilityScheduleWithRunLoop(m_reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode)) {
|
||||||
qCritical() << "Callback registered";
|
|
||||||
if (SCNetworkReachabilityScheduleWithRunLoop(_reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode)) {
|
|
||||||
qCritical() << "******* reachability callback set up";
|
|
||||||
} else {
|
} else {
|
||||||
qCritical() << "******** Error setting up reachability callback";
|
qCCritical(dcNymeaConnection()) << "Error setting up reachability callback";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SCNetworkReachabilityFlags flags;
|
SCNetworkReachabilityFlags flags;
|
||||||
|
if (SCNetworkReachabilityGetFlags(m_reachabilityRef, &flags)) {
|
||||||
if (SCNetworkReachabilityGetFlags(_reachabilityRef, &flags)) {
|
|
||||||
m_availableBearerTypes = flagsToBearerType(flags);
|
m_availableBearerTypes = flagsToBearerType(flags);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: unregister
|
void NetworkReachabilityMonitor::teardownIOS()
|
||||||
// SCNetworkReachabilityUnscheduleFromRunLoop(_reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
|
{
|
||||||
|
SCNetworkReachabilityUnscheduleFromRunLoop(m_reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
NymeaConnection::BearerType NetworkReachabilityMonitor::flagsToBearerType(SCNetworkReachabilityFlags flags)
|
NymeaConnection::BearerType NetworkReachabilityMonitor::flagsToBearerType(SCNetworkReachabilityFlags flags)
|
||||||
|
|||||||
Reference in New Issue
Block a user