power_daemon: code cleanup, added copyright header.
This commit is contained in:
parent
ab3b931b14
commit
28fd553722
@ -1,30 +1,47 @@
|
||||
/*
|
||||
* Copyright 2005-2013, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
* Authors:
|
||||
* Nathan Whitehorn
|
||||
*/
|
||||
|
||||
|
||||
#include "power_button_monitor.h"
|
||||
|
||||
#include <Messenger.h>
|
||||
#include <Roster.h>
|
||||
|
||||
#include <RosterPrivate.h>
|
||||
|
||||
#include "power_button_monitor.h"
|
||||
|
||||
|
||||
PowerButtonMonitor::PowerButtonMonitor() : BHandler ("power_button_monitor") {
|
||||
power_button_fd = open("/dev/power/button/power",O_RDONLY);
|
||||
PowerButtonMonitor::PowerButtonMonitor()
|
||||
:
|
||||
BHandler ("power_button_monitor")
|
||||
{
|
||||
fPowerButtonFD = open("/dev/power/button/power", O_RDONLY);
|
||||
}
|
||||
|
||||
PowerButtonMonitor::~PowerButtonMonitor() {
|
||||
if (power_button_fd > 0)
|
||||
close(power_button_fd);
|
||||
|
||||
PowerButtonMonitor::~PowerButtonMonitor()
|
||||
{
|
||||
if (fPowerButtonFD > 0)
|
||||
close(fPowerButtonFD);
|
||||
}
|
||||
|
||||
void PowerButtonMonitor::MessageReceived(BMessage *msg) {
|
||||
|
||||
void
|
||||
PowerButtonMonitor::MessageReceived(BMessage *msg)
|
||||
{
|
||||
if (msg->what != POLL_POWER_BUTTON_STATUS)
|
||||
return;
|
||||
|
||||
if (power_button_fd <= 0)
|
||||
|
||||
if (fPowerButtonFD <= 0)
|
||||
return;
|
||||
|
||||
|
||||
uint8 button_pressed;
|
||||
read(power_button_fd,&button_pressed,1);
|
||||
|
||||
read(fPowerButtonFD, &button_pressed, 1);
|
||||
|
||||
if (button_pressed) {
|
||||
BRoster roster;
|
||||
BRoster::Private rosterPrivate(roster);
|
||||
|
@ -1,19 +1,30 @@
|
||||
/*
|
||||
* Copyright 2005-2013, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
* Authors:
|
||||
* Nathan Whitehorn
|
||||
*/
|
||||
#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;
|
||||
public:
|
||||
PowerButtonMonitor();
|
||||
virtual ~PowerButtonMonitor();
|
||||
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
|
||||
private:
|
||||
int fPowerButtonFD;
|
||||
};
|
||||
|
||||
|
||||
#endif // _POWER_BUTTON_MONITOR_H
|
||||
|
@ -1,7 +1,17 @@
|
||||
/*
|
||||
* Copyright 2005-2013, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
* Authors:
|
||||
* Nathan Whitehorn
|
||||
*/
|
||||
|
||||
|
||||
#include "power_button_monitor.h"
|
||||
|
||||
#include <Application.h>
|
||||
#include <MessageRunner.h>
|
||||
|
||||
#include "power_button_monitor.h"
|
||||
|
||||
class PowerManagementDaemon : public BApplication {
|
||||
public:
|
||||
@ -9,18 +19,29 @@ class PowerManagementDaemon : public BApplication {
|
||||
virtual ~PowerManagementDaemon();
|
||||
};
|
||||
|
||||
int main(void) {
|
||||
|
||||
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()
|
||||
:
|
||||
BApplication("application/x-vnd.Haiku-powermanagement")
|
||||
{
|
||||
PowerButtonMonitor *powerButtonMonitor = new PowerButtonMonitor();
|
||||
AddHandler(powerButtonMonitor);
|
||||
|
||||
new BMessageRunner(BMessenger(powerButtonMonitor,this),
|
||||
new BMessage(POLL_POWER_BUTTON_STATUS), 5e5 /* twice a second */);
|
||||
}
|
||||
|
||||
PowerManagementDaemon::~PowerManagementDaemon() {}
|
||||
|
||||
PowerManagementDaemon::~PowerManagementDaemon()
|
||||
{
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user