2 * Copyright 2005-2014, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
11 #include "power_button_monitor.h"
15 #include <Directory.h>
16 #include <Messenger.h>
20 #include <RosterPrivate.h>
23 static const char* kBasePath
= "/dev/power/button";
26 PowerButtonMonitor::PowerButtonMonitor()
31 if (dir
.SetTo(kBasePath
) != B_OK
)
35 while (dir
.GetNextRef(&ref
) == B_OK
) {
36 if (strncmp(ref
.name
, "power", 5) == 0) {
38 path
.SetToFormat("%s/%s", kBasePath
, ref
.name
);
39 int fd
= open(path
.String(), O_RDONLY
);
47 PowerButtonMonitor::~PowerButtonMonitor()
49 for (std::set
<int>::iterator it
= fFDs
.begin(); it
!= fFDs
.end(); ++it
)
55 PowerButtonMonitor::HandleEvent(int fd
)
58 if (read(fd
, &button_pressed
, 1) != 1)
63 BRoster::Private
rosterPrivate(roster
);
65 rosterPrivate
.ShutDown(false, false, false);