Added the beginnings of our power management daemon. Currently does nothing except tell the roster to shut down when you press the power button (in conjuction with acpi_button, of course). Eventually will do things like display low power warnings, spin down hard disks, and display the requisite power info deskbar replicant.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11466 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
0a60ca24de
commit
d86d43eba2
@ -7,6 +7,7 @@ SubInclude OBOS_TOP src servers media ;
|
||||
SubInclude OBOS_TOP src servers media_addon ;
|
||||
SubInclude OBOS_TOP src servers midi ;
|
||||
# SubInclude OBOS_TOP src servers net ;
|
||||
SubInclude OBOS_TOP src servers power ;
|
||||
SubInclude OBOS_TOP src servers print ;
|
||||
SubInclude OBOS_TOP src servers registrar ;
|
||||
SubInclude OBOS_TOP src servers screensaver ;
|
||||
|
10
src/servers/power/Jamfile
Normal file
10
src/servers/power/Jamfile
Normal file
@ -0,0 +1,10 @@
|
||||
SubDir OBOS_TOP src servers power ;
|
||||
|
||||
AddResources power_daemon : power_daemon.rdef ;
|
||||
|
||||
Server power_daemon :
|
||||
power_daemon.cpp
|
||||
power_button_monitor.cpp
|
||||
;
|
||||
|
||||
LinkSharedOSLibs power_daemon : be ;
|
30
src/servers/power/power_button_monitor.cpp
Normal file
30
src/servers/power/power_button_monitor.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#include <Messenger.h>
|
||||
#include <Roster.h>
|
||||
|
||||
#include "power_button_monitor.h"
|
||||
|
||||
#define B_SYSTEM_SHUTDOWN 0x12d
|
||||
static const char *kRosterSignature = "application/x-vnd.Be-ROST";
|
||||
|
||||
PowerButtonMonitor::PowerButtonMonitor() : BHandler ("power_button_monitor") {
|
||||
power_button_fd = open("/dev/power/button/power",O_RDONLY);
|
||||
}
|
||||
|
||||
PowerButtonMonitor::~PowerButtonMonitor() {
|
||||
if (power_button_fd > 0)
|
||||
close(power_button_fd);
|
||||
}
|
||||
|
||||
void PowerButtonMonitor::MessageReceived(BMessage *msg) {
|
||||
if (msg->what != POLL_POWER_BUTTON_STATUS)
|
||||
return;
|
||||
|
||||
if (power_button_fd <= 0)
|
||||
return;
|
||||
|
||||
bool button_pressed;
|
||||
read(power_button_fd,&button_pressed,1);
|
||||
|
||||
if (button_pressed)
|
||||
BMessenger(kRosterSignature).SendMessage(B_SYSTEM_SHUTDOWN);
|
||||
}
|
19
src/servers/power/power_button_monitor.h
Normal file
19
src/servers/power/power_button_monitor.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef _POWER_BUTTON_MONITOR_H
|
||||
#define _POWER_BUTTON_MONITOR_H
|
||||
|
||||
#include <Handler.h>
|
||||
|
||||
#define POLL_POWER_BUTTON_STATUS 'ppbs'
|
||||
|
||||
class PowerButtonMonitor : public BHandler {
|
||||
public:
|
||||
PowerButtonMonitor();
|
||||
virtual ~PowerButtonMonitor();
|
||||
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
|
||||
private:
|
||||
int power_button_fd;
|
||||
};
|
||||
|
||||
#endif // _POWER_BUTTON_MONITOR_H
|
26
src/servers/power/power_daemon.cpp
Normal file
26
src/servers/power/power_daemon.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include <Application.h>
|
||||
#include <MessageRunner.h>
|
||||
|
||||
#include "power_button_monitor.h"
|
||||
|
||||
class PowerManagementDaemon : public BApplication {
|
||||
public:
|
||||
PowerManagementDaemon();
|
||||
virtual ~PowerManagementDaemon();
|
||||
};
|
||||
|
||||
int main(void) {
|
||||
new PowerManagementDaemon();
|
||||
be_app->Run();
|
||||
delete be_app;
|
||||
return 0;
|
||||
}
|
||||
|
||||
PowerManagementDaemon::PowerManagementDaemon() : BApplication("application/x-vnd.Haiku-powermanagement") {
|
||||
PowerButtonMonitor *pb_mon = new PowerButtonMonitor();
|
||||
AddHandler(pb_mon);
|
||||
|
||||
new BMessageRunner(BMessenger(pb_mon,this),new BMessage(POLL_POWER_BUTTON_STATUS),5e5 /* twice a second */);
|
||||
}
|
||||
|
||||
PowerManagementDaemon::~PowerManagementDaemon() {}
|
22
src/servers/power/power_daemon.rdef
Normal file
22
src/servers/power/power_daemon.rdef
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
resource(1, "BEOS:FILE_TYPES") message;
|
||||
|
||||
resource(1, "BEOS:APP_SIG") #'MIMS' "application/x-vnd.Haiku-powermanagement";
|
||||
|
||||
resource app_version
|
||||
{
|
||||
major = 0,
|
||||
middle = 0,
|
||||
minor = 1,
|
||||
|
||||
/* 0 = development 1 = alpha 2 = beta
|
||||
3 = gamma 4 = golden master 5 = final */
|
||||
variety = 0,
|
||||
|
||||
internal = 0,
|
||||
|
||||
short_info = "Power Management 0.01",
|
||||
long_info = "Haiku Power Management Daemon 0.01 Development"
|
||||
};
|
||||
|
||||
resource(1, "BEOS:APP_FLAGS") #'APPF' $"04000000";
|
Loading…
Reference in New Issue
Block a user