mac sleep monitor checkpoint

This commit is contained in:
howard-stearns 2019-07-11 10:58:31 -07:00
parent 4c145386e5
commit 8d3dc52ac0
3 changed files with 94 additions and 0 deletions

View file

@ -257,6 +257,10 @@ extern "C" {
}
#endif
#ifdef Q_OS_MAC
#include "MacHelper.h"
#endif
#if defined(Q_OS_ANDROID)
#include <android/log.h>
#include "AndroidHelper.h"
@ -960,6 +964,9 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) {
DependencyManager::set<KeyboardScriptingInterface>();
DependencyManager::set<GrabManager>();
DependencyManager::set<AvatarPackager>();
#ifdef Q_OS_MAC
DependencyManager::set<MacHelper>();
#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>();
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<Preferences>();
qCInfo(interfaceapp) << "HRS FIXME Quit 6";
#ifdef Q_OS_MAC
DependencyManager::destroy<MacHelper>();
#endif
_entityClipboard->eraseAllOctreeElements();
_entityClipboard.reset();

57
interface/src/MacHelper.cpp Executable file
View file

@ -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 <IOKit/pwr_mgt/IOPMLib.h>
#include <IOKit/IOMessage.h>
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, &notifyPortRef, sleepHandler, &notifierObject);
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(&notifierObject);
IOServiceClose(root_port);
IONotificationPortDestroy(notifyPortRef);
#endif
}

21
interface/src/MacHelper.h Executable file
View file

@ -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();
};