VirtualBox

source: vbox/trunk/src/VBox/Main/include/HostPower.h@ 96910

Last change on this file since 96910 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 KB
Line 
1/* $Id: HostPower.h 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 *
4 * VirtualBox interface to host's power notification service
5 */
6
7/*
8 * Copyright (C) 2006-2022 Oracle and/or its affiliates.
9 *
10 * This file is part of VirtualBox base platform packages, as
11 * available from https://www.virtualbox.org.
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation, in version 3 of the
16 * License.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see <https://www.gnu.org/licenses>.
25 *
26 * SPDX-License-Identifier: GPL-3.0-only
27 */
28
29#ifndef MAIN_INCLUDED_HostPower_h
30#define MAIN_INCLUDED_HostPower_h
31#ifndef RT_WITHOUT_PRAGMA_ONCE
32# pragma once
33#endif
34
35#ifdef RT_OS_DARWIN /* first, so we can undef pVM in iprt/cdefs.h */
36# include <IOKit/pwr_mgt/IOPMLib.h>
37# include <Carbon/Carbon.h>
38#endif
39
40#include "VirtualBoxBase.h"
41
42#include <vector>
43
44#ifdef RT_OS_LINUX
45# include <VBox/dbus.h>
46#endif
47
48class HostPowerService
49{
50 public:
51 HostPowerService(VirtualBox *aVirtualBox);
52 virtual ~HostPowerService();
53 void notify(Reason_T aReason);
54
55 protected:
56 VirtualBox *mVirtualBox;
57 std::vector<ComPtr<IInternalSessionControl> > mSessionControls;
58};
59
60# if defined(RT_OS_WINDOWS) || defined(DOXYGEN_RUNNING)
61/**
62 * The Windows hosted Power Service.
63 */
64class HostPowerServiceWin : public HostPowerService
65{
66public:
67
68 HostPowerServiceWin(VirtualBox *aVirtualBox);
69 virtual ~HostPowerServiceWin();
70
71private:
72
73 static DECLCALLBACK(int) NotificationThread(RTTHREAD ThreadSelf, void *pInstance);
74 static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
75
76 HWND mHwnd;
77 RTTHREAD mThread;
78};
79# endif
80# if defined(RT_OS_LINUX) || defined(DOXYGEN_RUNNING)
81/**
82 * The Linux hosted Power Service.
83 */
84class HostPowerServiceLinux : public HostPowerService
85{
86public:
87
88 HostPowerServiceLinux(VirtualBox *aVirtualBox);
89 virtual ~HostPowerServiceLinux();
90
91private:
92
93 static DECLCALLBACK(int) powerChangeNotificationThread(RTTHREAD ThreadSelf, void *pInstance);
94
95 /* Private member vars */
96 /** Our message thread. */
97 RTTHREAD mThread;
98 /** Our (private) connection to the DBus. Closing this will cause the
99 * message thread to exit. */
100 DBusConnection *mpConnection;
101};
102
103# endif
104# if defined(RT_OS_DARWIN) || defined(DOXYGEN_RUNNING)
105/**
106 * The Darwin hosted Power Service.
107 */
108class HostPowerServiceDarwin : public HostPowerService
109{
110public:
111
112 HostPowerServiceDarwin(VirtualBox *aVirtualBox);
113 virtual ~HostPowerServiceDarwin();
114
115private:
116
117 static DECLCALLBACK(int) powerChangeNotificationThread(RTTHREAD ThreadSelf, void *pInstance);
118 static void powerChangeNotificationHandler(void *pvData, io_service_t service, natural_t messageType, void *pMessageArgument);
119 static void lowPowerHandler(void *pvData);
120
121 void checkBatteryCriticalLevel(bool *pfCriticalChanged = NULL);
122
123 /* Private member vars */
124 RTTHREAD mThread; /* Our message thread. */
125
126 io_connect_t mRootPort; /* A reference to the Root Power Domain IOService */
127 IONotificationPortRef mNotifyPort; /* Notification port allocated by IORegisterForSystemPower */
128 io_object_t mNotifierObject; /* Notifier object, used to deregister later */
129 CFRunLoopRef mRunLoop; /* A reference to the local thread run loop */
130
131 bool mCritical; /* Indicate if the battery was in the critical state last checked */
132};
133# endif
134
135#endif /* !MAIN_INCLUDED_HostPower_h */
136/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette