power_daemon: code cleanup, added copyright header.
This commit is contained in:
@@ -1,29 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* 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 <Messenger.h>
|
||||||
#include <Roster.h>
|
#include <Roster.h>
|
||||||
|
|
||||||
#include <RosterPrivate.h>
|
#include <RosterPrivate.h>
|
||||||
|
|
||||||
#include "power_button_monitor.h"
|
|
||||||
|
|
||||||
|
PowerButtonMonitor::PowerButtonMonitor()
|
||||||
PowerButtonMonitor::PowerButtonMonitor() : BHandler ("power_button_monitor") {
|
:
|
||||||
power_button_fd = open("/dev/power/button/power",O_RDONLY);
|
BHandler ("power_button_monitor")
|
||||||
|
{
|
||||||
|
fPowerButtonFD = open("/dev/power/button/power", O_RDONLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
PowerButtonMonitor::~PowerButtonMonitor() {
|
|
||||||
if (power_button_fd > 0)
|
PowerButtonMonitor::~PowerButtonMonitor()
|
||||||
close(power_button_fd);
|
{
|
||||||
|
if (fPowerButtonFD > 0)
|
||||||
|
close(fPowerButtonFD);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerButtonMonitor::MessageReceived(BMessage *msg) {
|
|
||||||
|
void
|
||||||
|
PowerButtonMonitor::MessageReceived(BMessage *msg)
|
||||||
|
{
|
||||||
if (msg->what != POLL_POWER_BUTTON_STATUS)
|
if (msg->what != POLL_POWER_BUTTON_STATUS)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (power_button_fd <= 0)
|
if (fPowerButtonFD <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uint8 button_pressed;
|
uint8 button_pressed;
|
||||||
read(power_button_fd,&button_pressed,1);
|
read(fPowerButtonFD, &button_pressed, 1);
|
||||||
|
|
||||||
if (button_pressed) {
|
if (button_pressed) {
|
||||||
BRoster roster;
|
BRoster 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
|
#ifndef _POWER_BUTTON_MONITOR_H
|
||||||
#define _POWER_BUTTON_MONITOR_H
|
#define _POWER_BUTTON_MONITOR_H
|
||||||
|
|
||||||
|
|
||||||
#include <Handler.h>
|
#include <Handler.h>
|
||||||
|
|
||||||
|
|
||||||
#define POLL_POWER_BUTTON_STATUS 'ppbs'
|
#define POLL_POWER_BUTTON_STATUS 'ppbs'
|
||||||
|
|
||||||
|
|
||||||
class PowerButtonMonitor : public BHandler {
|
class PowerButtonMonitor : public BHandler {
|
||||||
public:
|
public:
|
||||||
PowerButtonMonitor();
|
PowerButtonMonitor();
|
||||||
virtual ~PowerButtonMonitor();
|
virtual ~PowerButtonMonitor();
|
||||||
|
|
||||||
virtual void MessageReceived(BMessage *msg);
|
virtual void MessageReceived(BMessage *msg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int power_button_fd;
|
int fPowerButtonFD;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // _POWER_BUTTON_MONITOR_H
|
#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 <Application.h>
|
||||||
#include <MessageRunner.h>
|
#include <MessageRunner.h>
|
||||||
|
|
||||||
#include "power_button_monitor.h"
|
|
||||||
|
|
||||||
class PowerManagementDaemon : public BApplication {
|
class PowerManagementDaemon : public BApplication {
|
||||||
public:
|
public:
|
||||||
@@ -9,18 +19,29 @@ class PowerManagementDaemon : public BApplication {
|
|||||||
virtual ~PowerManagementDaemon();
|
virtual ~PowerManagementDaemon();
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(void) {
|
|
||||||
|
int
|
||||||
|
main(void)
|
||||||
|
{
|
||||||
new PowerManagementDaemon();
|
new PowerManagementDaemon();
|
||||||
be_app->Run();
|
be_app->Run();
|
||||||
delete be_app;
|
delete be_app;
|
||||||
return 0;
|
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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user