From 8d3dc52ac04fbde50649d8a46d9d370fe4701674 Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Thu, 11 Jul 2019 10:58:31 -0700 Subject: [PATCH] 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(); +}; +