Skip to content
Snippets Groups Projects
Commit a0e2c4ac authored by Kateryna Kostiuk's avatar Kateryna Kostiuk
Browse files

macOS: update connections when the system wakes up

Sometimes, it is not possible to place a call after the
system returns from sleep mode. This patch ensures
that the connectivity changed is called when the system
returns from sleep mode.
Change-Id: Id9f1331b89ae37a1244ea10a8c02282c4c8a35e5
parent 010930fe
No related branches found
No related tags found
No related merge requests found
......@@ -17,14 +17,46 @@
*/
#include <CoreFoundation/CoreFoundation.h>
#include <AppKit/AppKit.h>
#include <IOKit/pwr_mgt/IOPMLib.h>
#include <SystemConfiguration/SystemConfiguration.h>
#include "connectivitymonitor.h"
#include <QDebug>
typedef void(^SystemMonitorCallback)(void);
@interface SystemMonitor: NSObject
-(void)startWithCallBack:(SystemMonitorCallback) callback;
@property (nonatomic, copy) SystemMonitorCallback callback;
@end
@implementation SystemMonitor
-(void)startWithCallBack:(SystemMonitorCallback)callback {
self.callback = callback;
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self
selector: @selector(receiveWakeNotification:)
name: NSWorkspaceDidWakeNotification object: NULL];
}
- (void)receiveWakeNotification:(NSNotification*)note
{
_callback();
}
-(void)dealloc {
[_callback release], _callback = nil;
[super dealloc];
}
@end
dispatch_queue_t scNetworkQueue;
SCNetworkReachabilityRef currentReachability;
SystemMonitor* systemMonitor;
static void ReachabilityCallback(SCNetworkReachabilityRef __unused target, SCNetworkConnectionFlags flags, void* info)
{
......@@ -36,6 +68,10 @@ ConnectivityMonitor::ConnectivityMonitor(QObject* parent)
: QObject(parent)
{
scNetworkQueue = dispatch_queue_create("scNetworkReachability", DISPATCH_QUEUE_SERIAL);
systemMonitor = [[SystemMonitor alloc] init];
[systemMonitor startWithCallBack: ^(void) {
Q_EMIT connectivityChanged();
}];
SCNetworkReachabilityRef reachabilityRef = NULL;
void (^callbackBlock)(SCNetworkReachabilityFlags) = ^(SCNetworkReachabilityFlags flags) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
......@@ -61,7 +97,6 @@ ConnectivityMonitor::~ConnectivityMonitor()
{
SCNetworkReachabilitySetCallback(currentReachability, NULL, NULL);
currentReachability = NULL;
qDebug() << "Destroying connectivity monitor";
}
bool
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment