xref: /aosp_15_r20/external/libchrome/libchrome_tools/patches/dbus-Add-TryRegisterFallback.patch (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1From a4d8dee3905d784f40d8f480eaacae2655e68b47 Mon Sep 17 00:00:00 2001
2From: Sonny Sasaka <[email protected]>
3Date: Wed, 11 Jul 2018 20:55:58 -0700
4Subject: [PATCH] dbus: Add TryRegisterFallback
5
6The TryRegisterFallback works just like TryRegisterObjectPath,
7with addition that the registered callbacks also apply to the specified
8object path and its sub paths. This is useful to implement a "catch-all"
9handler.
10
11Currently this is needed by Bluetooth dispatcher which needs to catch
12all method calls to all objects and forward them to another D-Bus
13service.
14
15Bug:862849
16---
17 dbus/bus.cc     | 27 +++++++++++++++++++++------
18 dbus/bus.h      | 32 ++++++++++++++++++++++++++++++++
19 dbus/mock_bus.h |  5 +++++
20 3 files changed, 58 insertions(+), 6 deletions(-)
21
22diff --git a/dbus/bus.cc b/dbus/bus.cc
23index e62058e0dc34..29043609e760 100644
24--- a/dbus/bus.cc
25+++ b/dbus/bus.cc
26@@ -722,6 +722,25 @@ bool Bus::TryRegisterObjectPath(const ObjectPath& object_path,
27                                 const DBusObjectPathVTable* vtable,
28                                 void* user_data,
29                                 DBusError* error) {
30+  return TryRegisterObjectPathInternal(
31+      object_path, vtable, user_data, error,
32+      dbus_connection_try_register_object_path);
33+}
34+
35+bool Bus::TryRegisterFallback(const ObjectPath& object_path,
36+                              const DBusObjectPathVTable* vtable,
37+                              void* user_data,
38+                              DBusError* error) {
39+  return TryRegisterObjectPathInternal(object_path, vtable, user_data, error,
40+                                       dbus_connection_try_register_fallback);
41+}
42+
43+bool Bus::TryRegisterObjectPathInternal(
44+    const ObjectPath& object_path,
45+    const DBusObjectPathVTable* vtable,
46+    void* user_data,
47+    DBusError* error,
48+    TryRegisterObjectPathFunction* register_function) {
49   DCHECK(connection_);
50   AssertOnDBusThread();
51
52@@ -731,12 +750,8 @@ bool Bus::TryRegisterObjectPath(const ObjectPath& object_path,
53     return false;
54   }
55
56-  const bool success = dbus_connection_try_register_object_path(
57-      connection_,
58-      object_path.value().c_str(),
59-      vtable,
60-      user_data,
61-      error);
62+  const bool success = register_function(
63+      connection_, object_path.value().c_str(), vtable, user_data, error);
64   if (success)
65     registered_object_paths_.insert(object_path);
66   return success;
67diff --git a/dbus/bus.h b/dbus/bus.h
68index c2c2685afdc4..704a4c3a0b54 100644
69--- a/dbus/bus.h
70+++ b/dbus/bus.h
71@@ -520,6 +520,24 @@ class CHROME_DBUS_EXPORT Bus : public base::RefCountedThreadSafe<Bus> {
72                                      void* user_data,
73                                      DBusError* error);
74
75+  // Tries to register the object path and its sub paths.
76+  // Returns true on success.
77+  // Returns false if the object path is already registered.
78+  //
79+  // |message_function| in |vtable| will be called every time when a new
80+  // message sent to the object path (or hierarchically below) arrives.
81+  //
82+  // The same object path must not be added more than once.
83+  //
84+  // See also documentation of |dbus_connection_try_register_fallback| at
85+  // http://dbus.freedesktop.org/doc/api/html/group__DBusConnection.html
86+  //
87+  // BLOCKING CALL.
88+  virtual bool TryRegisterFallback(const ObjectPath& object_path,
89+                                   const DBusObjectPathVTable* vtable,
90+                                   void* user_data,
91+                                   DBusError* error);
92+
93   // Unregister the object path.
94   //
95   // BLOCKING CALL.
96@@ -590,8 +608,22 @@ class CHROME_DBUS_EXPORT Bus : public base::RefCountedThreadSafe<Bus> {
97   virtual ~Bus();
98
99  private:
100+  using TryRegisterObjectPathFunction =
101+      dbus_bool_t(DBusConnection* connection,
102+                  const char* object_path,
103+                  const DBusObjectPathVTable* vtable,
104+                  void* user_data,
105+                  DBusError* error);
106+
107   friend class base::RefCountedThreadSafe<Bus>;
108
109+  bool TryRegisterObjectPathInternal(
110+      const ObjectPath& object_path,
111+      const DBusObjectPathVTable* vtable,
112+      void* user_data,
113+      DBusError* error,
114+      TryRegisterObjectPathFunction* register_function);
115+
116   // Helper function used for RemoveObjectProxy().
117   void RemoveObjectProxyInternal(scoped_refptr<dbus::ObjectProxy> object_proxy,
118                                  const base::Closure& callback);
119diff --git a/dbus/mock_bus.h b/dbus/mock_bus.h
120index 216bc64bd068..6b3495db6014 100644
121--- a/dbus/mock_bus.h
122+++ b/dbus/mock_bus.h
123@@ -62,6 +62,11 @@ class MockBus : public Bus {
124                                            const DBusObjectPathVTable* vtable,
125                                            void* user_data,
126                                            DBusError* error));
127+  MOCK_METHOD4(TryRegisterFallback,
128+               bool(const ObjectPath& object_path,
129+                    const DBusObjectPathVTable* vtable,
130+                    void* user_data,
131+                    DBusError* error));
132   MOCK_METHOD1(UnregisterObjectPath, void(const ObjectPath& object_path));
133   MOCK_METHOD0(GetDBusTaskRunner, base::TaskRunner*());
134   MOCK_METHOD0(GetOriginTaskRunner, base::TaskRunner*());
135--
1362.18.0.203.gfac676dfb9-goog
137
138