1 #include <Messenger.h> 2 #include <Roster.h> 3 4 #include <RosterPrivate.h> 5 6 #include "power_button_monitor.h" 7 8 9 PowerButtonMonitor::PowerButtonMonitor() : BHandler ("power_button_monitor") { 10 power_button_fd = open("/dev/power/button/power",O_RDONLY); 11 } 12 13 PowerButtonMonitor::~PowerButtonMonitor() { 14 if (power_button_fd > 0) 15 close(power_button_fd); 16 } 17 18 void PowerButtonMonitor::MessageReceived(BMessage *msg) { 19 if (msg->what != POLL_POWER_BUTTON_STATUS) 20 return; 21 22 if (power_button_fd <= 0) 23 return; 24 25 uint8 button_pressed; 26 read(power_button_fd,&button_pressed,1); 27 28 if (button_pressed) { 29 BRoster roster; 30 BRoster::Private rosterPrivate(roster); 31 32 rosterPrivate.ShutDown(false, false, false); 33 } 34 } 35