Bug 927459: Move helpers to DBusWatcher, r=qdot
authorThomas Zimmermann <tdz@users.sourceforge.net>
Fri, 25 Oct 2013 09:31:04 +0200
changeset 165986 6921551afb423f3f184dd940135a493d7e766957
parent 165985 83060920aaf5b4b5b59e39e7d6d663174fdcf695
child 165987 ac3b5c47d520b7cb06dcaad3c32336027ae98fdc
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs927459
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 927459: Move helpers to DBusWatcher, r=qdot PollFdComparator, DBusEventTypes and flag conversion are only used by DBusWatcher. This patch moves them into DBusWatcher's namespace.
ipc/dbus/DBusThread.cpp
--- a/ipc/dbus/DBusThread.cpp
+++ b/ipc/dbus/DBusThread.cpp
@@ -64,55 +64,19 @@
 #define LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "GonkDBus", args);
 #else
 #define BTDEBUG true
 #define LOG(args...) if (BTDEBUG) printf(args);
 #endif
 
 #define DEFAULT_INITIAL_POLLFD_COUNT 8
 
-// Functions for converting between unix events in the poll struct,
-// and their dbus definitions
-
-enum DBusEventTypes {
-  DBUS_EVENT_LOOP_EXIT = 1,
-  DBUS_EVENT_LOOP_ADD = 2,
-  DBUS_EVENT_LOOP_REMOVE = 3,
-  DBUS_EVENT_LOOP_WAKEUP = 4
-};
-
-static unsigned int UnixEventsToDBusFlags(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 DBusFlagsToUnixEvents(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);
-}
-
 namespace mozilla {
 namespace ipc {
 
-struct PollFdComparator {
-  bool Equals(const pollfd& a, const pollfd& b) const {
-    return ((a.fd == b.fd) &&
-            (a.events == b.events));
-  }
-  bool LessThan(const pollfd& a, const pollfd&b) const {
-    return false;
-  }
-};
-
 class DBusWatcher : public RawDBusConnection
 {
 public:
   DBusWatcher()
   { }
 
   ~DBusWatcher()
   { }
@@ -138,16 +102,35 @@ public:
   nsTArray<DBusWatch*> mWatchData;
 
   // Sockets for receiving dbus control information (watch
   // add/removes, loop shutdown, etc...)
   ScopedClose mControlFdR;
   ScopedClose mControlFdW;
 
 private:
+  struct PollFdComparator {
+    bool Equals(const pollfd& a, const pollfd& b) const {
+      return ((a.fd == b.fd) && (a.events == b.events));
+    }
+    bool LessThan(const pollfd& a, const pollfd&b) const {
+      return false;
+    }
+  };
+
+  enum DBusEventTypes {
+    DBUS_EVENT_LOOP_EXIT = 1,
+    DBUS_EVENT_LOOP_ADD = 2,
+    DBUS_EVENT_LOOP_REMOVE = 3,
+    DBUS_EVENT_LOOP_WAKEUP = 4
+  };
+
+  static unsigned int UnixEventsToDBusFlags(short events);
+  static short        DBusFlagsToUnixEvents(unsigned int flags);
+
   static dbus_bool_t AddWatchFunction(DBusWatch* aWatch, void* aData);
   static void        RemoveWatchFunction(DBusWatch* aWatch, void* aData);
   static void        ToggleWatchFunction(DBusWatch* aWatch, void* aData);
   static void        DBusWakeupFunction(void* aData);
 
   bool SetUp();
 };
 
@@ -429,16 +412,36 @@ DBusWatcher::HandleWatchRemove()
   }
   mPollData.RemoveElementAt(index);
 
   // DBusWatch pointers are maintained by DBus, so we won't leak by
   // removing.
   mWatchData.RemoveElementAt(index);
 }
 
+// Flag conversion
+
+unsigned int
+DBusWatcher::UnixEventsToDBusFlags(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);
+}
+
+short
+DBusWatcher::DBusFlagsToUnixEvents(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);
+}
+
 // DBus utility functions, used as function pointers in DBus setup
 
 dbus_bool_t
 DBusWatcher::AddWatchFunction(DBusWatch* aWatch, void* aData)
 {
   MOZ_ASSERT(aData);
   DBusWatcher* dbusWatcher = static_cast<DBusWatcher*>(aData);
   return dbusWatcher->AddWatch(aWatch);