Files
amnezia-client/client/platforms/macos/macosnetworkwatcher.h
T

52 lines
1.4 KiB
Objective-C
Raw Normal View History

2021-10-23 04:26:47 -07:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef MACOSNETWORKWATCHER_H
#define MACOSNETWORKWATCHER_H
2023-07-15 14:19:48 -07:00
#import <Network/Network.h>
#include "../ios/iosnetworkwatcher.h"
2021-10-23 04:26:47 -07:00
#include "networkwatcherimpl.h"
2025-04-03 22:12:54 +03:00
#include <IOKit/pwr_mgt/IOPMLib.h>
#include <IOKit/IOMessage.h>
2023-07-15 14:19:48 -07:00
class QString;
2025-04-03 22:12:54 +03:00
// Inspired by https://ladydebug.com/blog/2020/05/21/programmatically-capture-energy-saver-event-on-mac/
class PowerNotificationsListener
{
public:
void registerForNotifications();
private:
static void sleepWakeupCallBack(void *refParam, io_service_t service, natural_t messageType, void *messageArgument);
private:
IONotificationPortRef notifyPortRef = nullptr; // notification port allocated by IORegisterForSystemPower
io_object_t notifierObj = IO_OBJECT_NULL; // notifier object, used to deregister later
io_connect_t rootPowerDomain = IO_OBJECT_NULL; // a reference to the Root Power Domain IOService
};
2023-07-15 14:19:48 -07:00
class MacOSNetworkWatcher final : public IOSNetworkWatcher {
2021-10-23 04:26:47 -07:00
public:
MacOSNetworkWatcher(QObject* parent);
~MacOSNetworkWatcher();
void start() override;
void checkInterface();
2023-07-15 14:19:48 -07:00
void controllerStateChanged();
2021-10-23 04:26:47 -07:00
private:
void* m_delegate = nullptr;
2025-04-03 22:12:54 +03:00
PowerNotificationsListener m_powerlistener;
2021-10-23 04:26:47 -07:00
};
#endif // MACOSNETWORKWATCHER_H