summaryrefslogtreecommitdiffstats
path: root/core/jni/android_server_BluetoothEventLoop.cpp
diff options
context:
space:
mode:
authorNick Pelly <npelly@google.com>2009-06-18 15:05:34 -0700
committerNick Pelly <npelly@google.com>2009-06-18 15:33:31 -0700
commit4a364130fb072bf44367e537f8d24e7e00c6ca69 (patch)
treec2b62def6449ec54789ef33479a1cfc67731f388 /core/jni/android_server_BluetoothEventLoop.cpp
parent7153739a92dda971fd865defae0747bec921d8af (diff)
downloadframeworks_base-4a364130fb072bf44367e537f8d24e7e00c6ca69.zip
frameworks_base-4a364130fb072bf44367e537f8d24e7e00c6ca69.tar.gz
frameworks_base-4a364130fb072bf44367e537f8d24e7e00c6ca69.tar.bz2
Fix runtime restarts due to sending the wrong flags to dbus.
In eventLoopMain we were correctly translating from unix events to dbus flags, but a coding typo then gave the unix events to dbus. Fix this typo. Also noticed that we were passing raw dbus flags to poll() in another area. This did not cause any immediate problem, since POLLIN | POLLPRI is harmless and we do not usually need POLLOUT. But fixed anyway.
Diffstat (limited to 'core/jni/android_server_BluetoothEventLoop.cpp')
-rw-r--r--core/jni/android_server_BluetoothEventLoop.cpp32
1 files changed, 21 insertions, 11 deletions
diff --git a/core/jni/android_server_BluetoothEventLoop.cpp b/core/jni/android_server_BluetoothEventLoop.cpp
index ff8f28a..ad24136 100644
--- a/core/jni/android_server_BluetoothEventLoop.cpp
+++ b/core/jni/android_server_BluetoothEventLoop.cpp
@@ -162,6 +162,19 @@ static const DBusObjectPathVTable agent_vtable = {
NULL, agent_event_filter, NULL, NULL, NULL, NULL
};
+static unsigned int unix_events_to_dbus_flags(short events) {
+ return (events & DBUS_WATCH_READABLE ? POLLIN : 0) |
+ (events & DBUS_WATCH_WRITABLE ? POLLOUT : 0) |
+ (events & DBUS_WATCH_ERROR ? POLLERR : 0) |
+ (events & DBUS_WATCH_HANGUP ? POLLHUP : 0);
+}
+
+static short dbus_flags_to_unix_events(unsigned int flags) {
+ return (flags & POLLIN ? DBUS_WATCH_READABLE : 0) |
+ (flags & POLLOUT ? DBUS_WATCH_WRITABLE : 0) |
+ (flags & POLLERR ? DBUS_WATCH_ERROR : 0) |
+ (flags & POLLHUP ? DBUS_WATCH_HANGUP : 0);
+}
static jboolean setUpEventLoop(native_data_t *nat) {
LOGV(__FUNCTION__);
@@ -385,8 +398,7 @@ static void handleWatchAdd(native_data_t *nat) {
read(nat->controlFdR, &newFD, sizeof(int));
read(nat->controlFdR, &flags, sizeof(unsigned int));
read(nat->controlFdR, &watch, sizeof(DBusWatch *));
- int events = (flags & DBUS_WATCH_READABLE ? POLLIN : 0)
- | (flags & DBUS_WATCH_WRITABLE ? POLLOUT : 0);
+ short events = dbus_flags_to_unix_events(flags);
for (int y = 0; y<nat->pollMemberCount; y++) {
if ((nat->pollData[y].fd == newFD) &&
@@ -430,8 +442,7 @@ static void handleWatchRemove(native_data_t *nat) {
read(nat->controlFdR, &removeFD, sizeof(int));
read(nat->controlFdR, &flags, sizeof(unsigned int));
- int events = (flags & DBUS_WATCH_READABLE ? POLLIN : 0)
- | (flags & DBUS_WATCH_WRITABLE ? POLLOUT : 0);
+ short events = dbus_flags_to_unix_events(flags);
for (int y = 0; y < nat->pollMemberCount; y++) {
if ((nat->pollData[y].fd == removeFD) &&
@@ -495,13 +506,12 @@ static void *eventLoopMain(void *ptr) {
}
}
} else {
- int event = nat->pollData[i].revents;
- int flags = (event & POLLIN ? DBUS_WATCH_READABLE : 0) |
- (event & POLLOUT ? DBUS_WATCH_WRITABLE : 0);
- dbus_watch_handle(nat->watchData[i], event);
- nat->pollData[i].revents = 0;
- // can only do one - it may have caused a 'remove'
- break;
+ short events = nat->pollData[i].revents;
+ unsigned int flags = unix_events_to_dbus_flags(events);
+ dbus_watch_handle(nat->watchData[i], flags);
+ nat->pollData[i].revents = 0;
+ // can only do one - it may have caused a 'remove'
+ break;
}
}
while (dbus_connection_dispatch(nat->conn) ==