Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 5 | #ifndef UPDATE_ENGINE_REAL_DBUS_WRAPPER_H_ |
| 6 | #define UPDATE_ENGINE_REAL_DBUS_WRAPPER_H_ |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 7 | |
| 8 | // A mockable interface for DBus. |
| 9 | |
Daniel Erat | 65f1da0 | 2014-06-27 22:05:38 -0700 | [diff] [blame] | 10 | #include <base/macros.h> |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 11 | #include <dbus/dbus-glib.h> |
Alex Vakulenko | 44cab30 | 2014-07-23 13:12:15 -0700 | [diff] [blame] | 12 | #include <dbus/dbus-glib-lowlevel.h> |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 13 | |
| 14 | #include "update_engine/dbus_wrapper_interface.h" |
| 15 | |
| 16 | namespace chromeos_update_engine { |
| 17 | |
| 18 | class RealDBusWrapper : public DBusWrapperInterface { |
| 19 | virtual DBusGProxy* ProxyNewForName(DBusGConnection* connection, |
| 20 | const char* name, |
| 21 | const char* path, |
Daniel Erat | 65f1da0 | 2014-06-27 22:05:38 -0700 | [diff] [blame] | 22 | const char* interface) OVERRIDE { |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 23 | return dbus_g_proxy_new_for_name(connection, |
| 24 | name, |
| 25 | path, |
| 26 | interface); |
| 27 | } |
| 28 | |
Daniel Erat | 65f1da0 | 2014-06-27 22:05:38 -0700 | [diff] [blame] | 29 | virtual void ProxyUnref(DBusGProxy* proxy) OVERRIDE { |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 30 | g_object_unref(proxy); |
| 31 | } |
| 32 | |
Daniel Erat | 65f1da0 | 2014-06-27 22:05:38 -0700 | [diff] [blame] | 33 | virtual DBusGConnection* BusGet(DBusBusType type, GError** error) OVERRIDE { |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 34 | return dbus_g_bus_get(type, error); |
| 35 | } |
| 36 | |
| 37 | virtual gboolean ProxyCall_0_1(DBusGProxy* proxy, |
| 38 | const char* method, |
| 39 | GError** error, |
Daniel Erat | 65f1da0 | 2014-06-27 22:05:38 -0700 | [diff] [blame] | 40 | GHashTable** out1) OVERRIDE { |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 41 | return dbus_g_proxy_call(proxy, method, error, G_TYPE_INVALID, |
| 42 | dbus_g_type_get_map("GHashTable", |
| 43 | G_TYPE_STRING, |
| 44 | G_TYPE_VALUE), |
| 45 | out1, G_TYPE_INVALID); |
| 46 | } |
| 47 | |
Daniel Erat | 65f1da0 | 2014-06-27 22:05:38 -0700 | [diff] [blame] | 48 | virtual gboolean ProxyCall_1_0(DBusGProxy* proxy, |
| 49 | const char* method, |
| 50 | GError** error, |
| 51 | gint in1) OVERRIDE { |
| 52 | return dbus_g_proxy_call(proxy, method, error, |
| 53 | G_TYPE_INT, in1, |
| 54 | G_TYPE_INVALID, G_TYPE_INVALID); |
| 55 | } |
| 56 | |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 57 | virtual gboolean ProxyCall_3_0(DBusGProxy* proxy, |
| 58 | const char* method, |
| 59 | GError** error, |
| 60 | const char* in1, |
| 61 | const char* in2, |
Daniel Erat | 65f1da0 | 2014-06-27 22:05:38 -0700 | [diff] [blame] | 62 | const char* in3) OVERRIDE { |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 63 | return dbus_g_proxy_call( |
| 64 | proxy, method, error, |
| 65 | G_TYPE_STRING, in1, G_TYPE_STRING, in2, G_TYPE_STRING, in3, |
| 66 | G_TYPE_INVALID, G_TYPE_INVALID); |
| 67 | } |
| 68 | |
Gilad Arnold | beb39e9 | 2014-03-11 11:34:50 -0700 | [diff] [blame] | 69 | virtual void ProxyAddSignal_2(DBusGProxy* proxy, |
| 70 | const char* signal_name, |
| 71 | GType type1, |
Daniel Erat | 65f1da0 | 2014-06-27 22:05:38 -0700 | [diff] [blame] | 72 | GType type2) OVERRIDE { |
Gilad Arnold | beb39e9 | 2014-03-11 11:34:50 -0700 | [diff] [blame] | 73 | dbus_g_proxy_add_signal(proxy, signal_name, type1, type2, G_TYPE_INVALID); |
| 74 | } |
| 75 | |
| 76 | virtual void ProxyConnectSignal(DBusGProxy* proxy, |
| 77 | const char* signal_name, |
| 78 | GCallback handler, |
| 79 | void* data, |
Daniel Erat | 65f1da0 | 2014-06-27 22:05:38 -0700 | [diff] [blame] | 80 | GClosureNotify free_data_func) OVERRIDE { |
Gilad Arnold | beb39e9 | 2014-03-11 11:34:50 -0700 | [diff] [blame] | 81 | dbus_g_proxy_connect_signal(proxy, signal_name, handler, data, |
| 82 | free_data_func); |
| 83 | } |
| 84 | |
| 85 | virtual void ProxyDisconnectSignal(DBusGProxy* proxy, |
| 86 | const char* signal_name, |
| 87 | GCallback handler, |
Daniel Erat | 65f1da0 | 2014-06-27 22:05:38 -0700 | [diff] [blame] | 88 | void* data) OVERRIDE { |
Gilad Arnold | beb39e9 | 2014-03-11 11:34:50 -0700 | [diff] [blame] | 89 | dbus_g_proxy_disconnect_signal(proxy, signal_name, handler, data); |
| 90 | } |
| 91 | |
Daniel Erat | 65f1da0 | 2014-06-27 22:05:38 -0700 | [diff] [blame] | 92 | virtual DBusConnection* ConnectionGetConnection( |
| 93 | DBusGConnection* gbus) OVERRIDE { |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 94 | return dbus_g_connection_get_connection(gbus); |
| 95 | } |
| 96 | |
| 97 | virtual void DBusBusAddMatch(DBusConnection* connection, |
| 98 | const char* rule, |
Daniel Erat | 65f1da0 | 2014-06-27 22:05:38 -0700 | [diff] [blame] | 99 | DBusError* error) OVERRIDE { |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 100 | dbus_bus_add_match(connection, rule, error); |
| 101 | } |
| 102 | |
| 103 | virtual dbus_bool_t DBusConnectionAddFilter( |
| 104 | DBusConnection* connection, |
| 105 | DBusHandleMessageFunction function, |
| 106 | void* user_data, |
Daniel Erat | 65f1da0 | 2014-06-27 22:05:38 -0700 | [diff] [blame] | 107 | DBusFreeFunction free_data_function) OVERRIDE { |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 108 | return dbus_connection_add_filter(connection, |
| 109 | function, |
| 110 | user_data, |
| 111 | free_data_function); |
| 112 | } |
| 113 | |
| 114 | virtual void DBusConnectionRemoveFilter(DBusConnection* connection, |
| 115 | DBusHandleMessageFunction function, |
Daniel Erat | 65f1da0 | 2014-06-27 22:05:38 -0700 | [diff] [blame] | 116 | void* user_data) OVERRIDE { |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 117 | dbus_connection_remove_filter(connection, function, user_data); |
| 118 | } |
| 119 | |
| 120 | dbus_bool_t DBusMessageIsSignal(DBusMessage* message, |
| 121 | const char* interface, |
Daniel Erat | 65f1da0 | 2014-06-27 22:05:38 -0700 | [diff] [blame] | 122 | const char* signal_name) OVERRIDE { |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 123 | return dbus_message_is_signal(message, interface, signal_name); |
| 124 | } |
| 125 | |
| 126 | virtual dbus_bool_t DBusMessageGetArgs_3(DBusMessage* message, |
| 127 | DBusError* error, |
| 128 | char** out1, |
| 129 | char** out2, |
Daniel Erat | 65f1da0 | 2014-06-27 22:05:38 -0700 | [diff] [blame] | 130 | char** out3) OVERRIDE { |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 131 | return dbus_message_get_args(message, error, |
| 132 | DBUS_TYPE_STRING, out1, |
| 133 | DBUS_TYPE_STRING, out2, |
| 134 | DBUS_TYPE_STRING, out3, |
| 135 | G_TYPE_INVALID); |
| 136 | } |
| 137 | }; |
| 138 | |
| 139 | } // namespace chromeos_update_engine |
| 140 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 141 | #endif // UPDATE_ENGINE_REAL_DBUS_WRAPPER_H_ |