1 /* 2 * Copyright 2005-2013, Haiku, Inc. 3 * Distributed under the terms of the MIT license. 4 * 5 * Authors: 6 * Nathan Whitehorn 7 */ 8 9 10 #include "power_button_monitor.h" 11 12 #include <Messenger.h> 13 #include <Roster.h> 14 15 #include <RosterPrivate.h> 16 17 18 PowerButtonMonitor::PowerButtonMonitor() 19 { 20 fFD = open("/dev/power/button/power", O_RDONLY); 21 } 22 23 24 PowerButtonMonitor::~PowerButtonMonitor() 25 { 26 if (fFD > 0) 27 close(fFD); 28 } 29 30 31 void 32 PowerButtonMonitor::HandleEvent() 33 { 34 if (fFD <= 0) 35 return; 36 37 uint8 button_pressed; 38 read(fFD, &button_pressed, 1); 39 40 if (button_pressed) { 41 BRoster roster; 42 BRoster::Private rosterPrivate(roster); 43 44 rosterPrivate.ShutDown(false, false, false); 45 } 46 } 47