1 #include <Messenger.h> 2 #include <Roster.h> 3 4 #include "power_button_monitor.h" 5 6 #define B_SYSTEM_SHUTDOWN 0x12d 7 static const char *kRosterSignature = "application/x-vnd.Be-ROST"; 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 bool button_pressed; 26 read(power_button_fd,&button_pressed,1); 27 28 if (button_pressed) 29 BMessenger(kRosterSignature).SendMessage(B_SYSTEM_SHUTDOWN); 30 } 31