power_daemon: checks the device descriptors are valid
* acpi_lid is in fact optionally available.
This commit is contained in:
committed by
Jérôme Duval
parent
cb7df3b1da
commit
5641f2eae3
@@ -9,14 +9,17 @@
|
|||||||
#define _LID_MONITOR_H
|
#define _LID_MONITOR_H
|
||||||
|
|
||||||
|
|
||||||
class LidMonitor {
|
#include "power_monitor.h"
|
||||||
|
|
||||||
|
|
||||||
|
class LidMonitor : public PowerMonitor {
|
||||||
public:
|
public:
|
||||||
LidMonitor();
|
LidMonitor();
|
||||||
~LidMonitor();
|
virtual ~LidMonitor();
|
||||||
|
|
||||||
void HandleEvent();
|
virtual void HandleEvent();
|
||||||
|
|
||||||
int FD() const { return fFD; }
|
virtual int FD() const { return fFD; }
|
||||||
private:
|
private:
|
||||||
int fFD;
|
int fFD;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,14 +9,17 @@
|
|||||||
#define _POWER_BUTTON_MONITOR_H
|
#define _POWER_BUTTON_MONITOR_H
|
||||||
|
|
||||||
|
|
||||||
class PowerButtonMonitor {
|
#include "power_monitor.h"
|
||||||
|
|
||||||
|
|
||||||
|
class PowerButtonMonitor : public PowerMonitor {
|
||||||
public:
|
public:
|
||||||
PowerButtonMonitor();
|
PowerButtonMonitor();
|
||||||
~PowerButtonMonitor();
|
virtual ~PowerButtonMonitor();
|
||||||
|
|
||||||
void HandleEvent();
|
virtual void HandleEvent();
|
||||||
|
|
||||||
int FD() const { return fFD; }
|
virtual int FD() const { return fFD; }
|
||||||
private:
|
private:
|
||||||
int fFD;
|
int fFD;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ private:
|
|||||||
static status_t _EventLooper(void *arg);
|
static status_t _EventLooper(void *arg);
|
||||||
|
|
||||||
thread_id fEventThread;
|
thread_id fEventThread;
|
||||||
PowerButtonMonitor* fPowerButtonMonitor;
|
PowerMonitor* fPowerMonitors[2];
|
||||||
LidMonitor* fLidMonitor;
|
uint32 fMonitorCount;
|
||||||
|
|
||||||
bool fQuitRequested;
|
bool fQuitRequested;
|
||||||
};
|
};
|
||||||
@@ -41,11 +41,21 @@ main(void)
|
|||||||
PowerManagementDaemon::PowerManagementDaemon()
|
PowerManagementDaemon::PowerManagementDaemon()
|
||||||
:
|
:
|
||||||
BApplication("application/x-vnd.Haiku-powermanagement"),
|
BApplication("application/x-vnd.Haiku-powermanagement"),
|
||||||
fPowerButtonMonitor(NULL),
|
fMonitorCount(0),
|
||||||
fQuitRequested(false)
|
fQuitRequested(false)
|
||||||
{
|
{
|
||||||
fPowerButtonMonitor = new PowerButtonMonitor;
|
PowerMonitor* powerButtonMonitor = new PowerButtonMonitor;
|
||||||
fLidMonitor = new LidMonitor;
|
if (powerButtonMonitor->FD() > 0)
|
||||||
|
fPowerMonitors[fMonitorCount++] = powerButtonMonitor;
|
||||||
|
else
|
||||||
|
delete powerButtonMonitor;
|
||||||
|
|
||||||
|
PowerMonitor* lidMonitor = new LidMonitor;
|
||||||
|
if (lidMonitor->FD() > 0)
|
||||||
|
fPowerMonitors[fMonitorCount++] = lidMonitor;
|
||||||
|
else
|
||||||
|
delete lidMonitor;
|
||||||
|
|
||||||
fEventThread = spawn_thread(_EventLooper, "_power_daemon_event_loop_",
|
fEventThread = spawn_thread(_EventLooper, "_power_daemon_event_loop_",
|
||||||
B_NORMAL_PRIORITY, this);
|
B_NORMAL_PRIORITY, this);
|
||||||
if (fEventThread < B_OK)
|
if (fEventThread < B_OK)
|
||||||
@@ -61,8 +71,8 @@ PowerManagementDaemon::PowerManagementDaemon()
|
|||||||
PowerManagementDaemon::~PowerManagementDaemon()
|
PowerManagementDaemon::~PowerManagementDaemon()
|
||||||
{
|
{
|
||||||
fQuitRequested = true;
|
fQuitRequested = true;
|
||||||
delete fPowerButtonMonitor;
|
for (uint32 i = 0; i < fMonitorCount; i++)
|
||||||
delete fLidMonitor;
|
delete fPowerMonitors[i];
|
||||||
status_t status;
|
status_t status;
|
||||||
wait_for_thread(fEventThread, &status);
|
wait_for_thread(fEventThread, &status);
|
||||||
}
|
}
|
||||||
@@ -80,17 +90,23 @@ PowerManagementDaemon::_EventLooper(void* arg)
|
|||||||
void
|
void
|
||||||
PowerManagementDaemon::_EventLoop()
|
PowerManagementDaemon::_EventLoop()
|
||||||
{
|
{
|
||||||
|
if (fMonitorCount == 0)
|
||||||
|
return;
|
||||||
|
object_wait_info info[fMonitorCount];
|
||||||
|
for (uint32 i = 0; i < fMonitorCount; i++) {
|
||||||
|
info[i].object = fPowerMonitors[i]->FD();
|
||||||
|
info[i].type = B_OBJECT_TYPE_FD;
|
||||||
|
info[i].events = B_EVENT_READ;
|
||||||
|
}
|
||||||
while (!fQuitRequested) {
|
while (!fQuitRequested) {
|
||||||
object_wait_info info[] = {
|
if (wait_for_objects(info, fMonitorCount) < B_OK)
|
||||||
{ fPowerButtonMonitor->FD(), B_OBJECT_TYPE_FD, B_EVENT_READ },
|
|
||||||
{ fLidMonitor->FD(), B_OBJECT_TYPE_FD, B_EVENT_READ }
|
|
||||||
};
|
|
||||||
|
|
||||||
if (wait_for_objects_etc(info, 2, 0, 1000000LL) < B_OK)
|
|
||||||
continue;
|
continue;
|
||||||
if (info[0].events & B_EVENT_READ)
|
// handle events and reset events
|
||||||
fPowerButtonMonitor->HandleEvent();
|
for (uint32 i = 0; i < fMonitorCount; i++) {
|
||||||
if (info[1].events & B_EVENT_READ)
|
if (info[i].events & B_EVENT_READ)
|
||||||
fLidMonitor->HandleEvent();
|
fPowerMonitors[i]->HandleEvent();
|
||||||
|
else
|
||||||
|
info[i].events = B_EVENT_READ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013, Haiku, Inc.
|
||||||
|
* Distributed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Jérôme Duval, [email protected].
|
||||||
|
*/
|
||||||
|
#ifndef _POWER_MONITOR_H
|
||||||
|
#define _POWER_MONITOR_H
|
||||||
|
|
||||||
|
|
||||||
|
class PowerMonitor {
|
||||||
|
public:
|
||||||
|
virtual ~PowerMonitor() {};
|
||||||
|
|
||||||
|
virtual void HandleEvent() = 0;
|
||||||
|
|
||||||
|
virtual int FD() const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _POWER_MONITOR_H
|
||||||
Reference in New Issue
Block a user