From 8d3dc52ac04fbde50649d8a46d9d370fe4701674 Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Thu, 11 Jul 2019 10:58:31 -0700 Subject: [PATCH 1/3] mac sleep monitor checkpoint --- interface/src/Application.cpp | 16 ++++++++++ interface/src/MacHelper.cpp | 57 +++++++++++++++++++++++++++++++++++ interface/src/MacHelper.h | 21 +++++++++++++ 3 files changed, 94 insertions(+) create mode 100755 interface/src/MacHelper.cpp create mode 100755 interface/src/MacHelper.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index b59fd223ba..a098f965d8 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -257,6 +257,10 @@ extern "C" { } #endif +#ifdef Q_OS_MAC +#include "MacHelper.h" +#endif + #if defined(Q_OS_ANDROID) #include #include "AndroidHelper.h" @@ -960,6 +964,9 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); +#ifdef Q_OS_MAC + DependencyManager::set(); +#endif QString setBookmarkValue = getCmdOption(argc, constArgv, "--setBookmark"); if (!setBookmarkValue.isEmpty()) { @@ -2829,17 +2836,20 @@ void Application::cleanupBeforeQuit() { } Application::~Application() { + qCInfo(interfaceapp) << "HRS FIXME Quit 1"; // remove avatars from physics engine auto avatarManager = DependencyManager::get(); avatarManager->clearOtherAvatars(); auto myCharacterController = getMyAvatar()->getCharacterController(); myCharacterController->clearDetailedMotionStates(); + qCInfo(interfaceapp) << "HRS FIXME Quit 2"; PhysicsEngine::Transaction transaction; avatarManager->buildPhysicsTransaction(transaction); _physicsEngine->processTransaction(transaction); avatarManager->handleProcessedPhysicsTransaction(transaction); avatarManager->deleteAllAvatars(); + qCInfo(interfaceapp) << "HRS FIXME Quit 3"; _physicsEngine->setCharacterController(nullptr); @@ -2850,9 +2860,15 @@ Application::~Application() { // shutdown graphics engine _graphicsEngine.shutdown(); + qCInfo(interfaceapp) << "HRS FIXME Quit 4"; _gameWorkload.shutdown(); + qCInfo(interfaceapp) << "HRS FIXME Quit 5"; DependencyManager::destroy(); + qCInfo(interfaceapp) << "HRS FIXME Quit 6"; +#ifdef Q_OS_MAC + DependencyManager::destroy(); +#endif _entityClipboard->eraseAllOctreeElements(); _entityClipboard.reset(); diff --git a/interface/src/MacHelper.cpp b/interface/src/MacHelper.cpp new file mode 100755 index 0000000000..f6b76649cd --- /dev/null +++ b/interface/src/MacHelper.cpp @@ -0,0 +1,57 @@ +// +// MacHelper.h +// interface/src +// +// Created by Howard Stearns +// Copyright 2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "InterfaceLogging.h" +#include "MacHelper.h" + +#ifdef Q_OS_MAC +#include +#include + +io_connect_t root_port; +IONotificationPortRef notifyPortRef; +io_object_t notifierObject; +void* refCon; + +void sleepHandler(void* refCon, io_service_t service, natural_t messageType, void* messageArgument) { + qCInfo(interfaceapp) << "HRS FIXME sleepHandler."; + if (messageType == kIOMessageSystemHasPoweredOn) { + qCInfo(interfaceapp) << "HRS FIXME Waking up from sleep or hybernation."; + } +} +#endif + +MacHelper::MacHelper() { + qCInfo(interfaceapp) << "HRS FIXME Start MacHelper."; +#ifdef Q_OS_MAC + root_port = IORegisterForSystemPower(refCon, ¬ifyPortRef, sleepHandler, ¬ifierObject); + if (root_port == 0) { + qCWarning(interfaceapp) << "IORegisterForSystemPower failed"; + } else { + qCDebug(interfaceapp) << "HRS FIXME IORegisterForSystemPower OK"; + } + CFRunLoopAddSource(CFRunLoopGetCurrent(), + IONotificationPortGetRunLoopSource(notifyPortRef), + kCFRunLoopCommonModes); +#endif +} + +MacHelper::~MacHelper() { + qCInfo(interfaceapp) << "HRS FIXME End MacHelper."; +#ifdef Q_OS_MAC + CFRunLoopRemoveSource(CFRunLoopGetCurrent(), + IONotificationPortGetRunLoopSource(notifyPortRef), + kCFRunLoopCommonModes); + IODeregisterForSystemPower(¬ifierObject); + IOServiceClose(root_port); + IONotificationPortDestroy(notifyPortRef); +#endif +} diff --git a/interface/src/MacHelper.h b/interface/src/MacHelper.h new file mode 100755 index 0000000000..52ad4d3e55 --- /dev/null +++ b/interface/src/MacHelper.h @@ -0,0 +1,21 @@ +// +// MacHelper.h +// interface/src +// +// Created by Howard Stearns +// Copyright 2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#pragma once + +#include "DependencyManager.h" + +class MacHelper : public Dependency { +public: + MacHelper(); + ~MacHelper(); +}; + From cc7214fca3176de2b39fd16789eca0773ff0ec5f Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Thu, 11 Jul 2019 16:56:35 -0700 Subject: [PATCH 2/3] cleanup --- interface/src/Application.cpp | 6 ------ interface/src/MacHelper.cpp | 27 ++++++++++++++------------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 449e27b689..67333da9b7 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2836,20 +2836,17 @@ void Application::cleanupBeforeQuit() { } Application::~Application() { - qCInfo(interfaceapp) << "HRS FIXME Quit 1"; // remove avatars from physics engine auto avatarManager = DependencyManager::get(); avatarManager->clearOtherAvatars(); auto myCharacterController = getMyAvatar()->getCharacterController(); myCharacterController->clearDetailedMotionStates(); - qCInfo(interfaceapp) << "HRS FIXME Quit 2"; PhysicsEngine::Transaction transaction; avatarManager->buildPhysicsTransaction(transaction); _physicsEngine->processTransaction(transaction); avatarManager->handleProcessedPhysicsTransaction(transaction); avatarManager->deleteAllAvatars(); - qCInfo(interfaceapp) << "HRS FIXME Quit 3"; _physicsEngine->setCharacterController(nullptr); @@ -2860,12 +2857,9 @@ Application::~Application() { // shutdown graphics engine _graphicsEngine.shutdown(); - qCInfo(interfaceapp) << "HRS FIXME Quit 4"; _gameWorkload.shutdown(); - qCInfo(interfaceapp) << "HRS FIXME Quit 5"; DependencyManager::destroy(); - qCInfo(interfaceapp) << "HRS FIXME Quit 6"; #ifdef Q_OS_MAC DependencyManager::destroy(); #endif diff --git a/interface/src/MacHelper.cpp b/interface/src/MacHelper.cpp index f6b76649cd..b3513afdc9 100755 --- a/interface/src/MacHelper.cpp +++ b/interface/src/MacHelper.cpp @@ -11,32 +11,34 @@ #include "InterfaceLogging.h" #include "MacHelper.h" +#include #ifdef Q_OS_MAC -#include #include - -io_connect_t root_port; -IONotificationPortRef notifyPortRef; -io_object_t notifierObject; -void* refCon; +#include -void sleepHandler(void* refCon, io_service_t service, natural_t messageType, void* messageArgument) { - qCInfo(interfaceapp) << "HRS FIXME sleepHandler."; +// These type definitions come from IOKit, which includes a definition of Duration that conflicts with ours. +// So... we include these definitions here rather than in the .h, as the .h is included in Application.cpp which +// uses Duration. +static io_connect_t root_port; +static IONotificationPortRef notifyPortRef; +static io_object_t notifierObject; +static void* refCon; + +static void sleepHandler(void* refCon, io_service_t service, natural_t messageType, void* messageArgument) { if (messageType == kIOMessageSystemHasPoweredOn) { - qCInfo(interfaceapp) << "HRS FIXME Waking up from sleep or hybernation."; + qCInfo(interfaceapp) << "Waking up from sleep or hybernation."; + QMetaObject::invokeMethod(DependencyManager::get().data(), "noteAwakening", Qt::QueuedConnection); } } #endif MacHelper::MacHelper() { - qCInfo(interfaceapp) << "HRS FIXME Start MacHelper."; #ifdef Q_OS_MAC root_port = IORegisterForSystemPower(refCon, ¬ifyPortRef, sleepHandler, ¬ifierObject); if (root_port == 0) { qCWarning(interfaceapp) << "IORegisterForSystemPower failed"; - } else { - qCDebug(interfaceapp) << "HRS FIXME IORegisterForSystemPower OK"; + return; } CFRunLoopAddSource(CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(notifyPortRef), @@ -45,7 +47,6 @@ MacHelper::MacHelper() { } MacHelper::~MacHelper() { - qCInfo(interfaceapp) << "HRS FIXME End MacHelper."; #ifdef Q_OS_MAC CFRunLoopRemoveSource(CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(notifyPortRef), From 7ce6dd71d55174ea4faf76cdf8a9c99cbe7a78cb Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Fri, 12 Jul 2019 10:48:05 -0700 Subject: [PATCH 3/3] fix comment --- interface/src/MacHelper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/MacHelper.cpp b/interface/src/MacHelper.cpp index b3513afdc9..8527f02918 100755 --- a/interface/src/MacHelper.cpp +++ b/interface/src/MacHelper.cpp @@ -17,7 +17,7 @@ #include #include -// These type definitions come from IOKit, which includes a definition of Duration that conflicts with ours. +// The type definitions in these variables come from IOKit, which includes a definition of Duration that conflicts with ours. // So... we include these definitions here rather than in the .h, as the .h is included in Application.cpp which // uses Duration. static io_connect_t root_port;