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 { |
Alex Vakulenko | a839bc3 | 2014-08-14 12:55:41 -0700 | [diff] [blame] | 19 | DBusGProxy* ProxyNewForName(DBusGConnection* connection, |
| 20 | const char* name, |
| 21 | const char* path, |
| 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 | |
Alex Vakulenko | a839bc3 | 2014-08-14 12:55:41 -0700 | [diff] [blame] | 29 | void ProxyUnref(DBusGProxy* proxy) override { |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 30 | g_object_unref(proxy); |
| 31 | } |
| 32 | |
Alex Vakulenko | a839bc3 | 2014-08-14 12:55:41 -0700 | [diff] [blame] | 33 | 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 | |
Alex Vakulenko | a839bc3 | 2014-08-14 12:55:41 -0700 | [diff] [blame] | 37 | gboolean ProxyCall_0_1(DBusGProxy* proxy, |
| 38 | const char* method, |
| 39 | GError** error, |
| 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 | |
Alex Vakulenko | a839bc3 | 2014-08-14 12:55:41 -0700 | [diff] [blame] | 48 | gboolean ProxyCall_1_0(DBusGProxy* proxy, |
| 49 | const char* method, |
| 50 | GError** error, |
| 51 | gint in1) override { |
Daniel Erat | 65f1da0 | 2014-06-27 22:05:38 -0700 | [diff] [blame] | 52 | return dbus_g_proxy_call(proxy, method, error, |
| 53 | G_TYPE_INT, in1, |
| 54 | G_TYPE_INVALID, G_TYPE_INVALID); |
| 55 | } |
| 56 | |
Alex Vakulenko | a839bc3 | 2014-08-14 12:55:41 -0700 | [diff] [blame] | 57 | gboolean ProxyCall_3_0(DBusGProxy* proxy, |
| 58 | const char* method, |
| 59 | GError** error, |
| 60 | const char* in1, |
| 61 | const char* in2, |
| 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 | |
Alex Vakulenko | a839bc3 | 2014-08-14 12:55:41 -0700 | [diff] [blame] | 69 | void ProxyAddSignal_2(DBusGProxy* proxy, |
| 70 | const char* signal_name, |
| 71 | GType type1, |
| 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 | |
Alex Vakulenko | a839bc3 | 2014-08-14 12:55:41 -0700 | [diff] [blame] | 76 | void ProxyConnectSignal(DBusGProxy* proxy, |
| 77 | const char* signal_name, |
| 78 | GCallback handler, |
| 79 | void* data, |
| 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 | |
Alex Vakulenko | a839bc3 | 2014-08-14 12:55:41 -0700 | [diff] [blame] | 85 | void ProxyDisconnectSignal(DBusGProxy* proxy, |
| 86 | const char* signal_name, |
| 87 | GCallback handler, |
| 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 | |
Alex Vakulenko | a839bc3 | 2014-08-14 12:55:41 -0700 | [diff] [blame] | 92 | DBusConnection* ConnectionGetConnection(DBusGConnection* gbus) override { |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 93 | return dbus_g_connection_get_connection(gbus); |
| 94 | } |
| 95 | |
Alex Vakulenko | a839bc3 | 2014-08-14 12:55:41 -0700 | [diff] [blame] | 96 | void DBusBusAddMatch(DBusConnection* connection, |
| 97 | const char* rule, |
| 98 | DBusError* error) override { |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 99 | dbus_bus_add_match(connection, rule, error); |
| 100 | } |
| 101 | |
Alex Vakulenko | a839bc3 | 2014-08-14 12:55:41 -0700 | [diff] [blame] | 102 | dbus_bool_t DBusConnectionAddFilter( |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 103 | DBusConnection* connection, |
| 104 | DBusHandleMessageFunction function, |
| 105 | void* user_data, |
Alex Vakulenko | a839bc3 | 2014-08-14 12:55:41 -0700 | [diff] [blame] | 106 | DBusFreeFunction free_data_function) override { |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 107 | return dbus_connection_add_filter(connection, |
| 108 | function, |
| 109 | user_data, |
| 110 | free_data_function); |
| 111 | } |
| 112 | |
Alex Vakulenko | a839bc3 | 2014-08-14 12:55:41 -0700 | [diff] [blame] | 113 | void DBusConnectionRemoveFilter(DBusConnection* connection, |
| 114 | DBusHandleMessageFunction function, |
| 115 | void* user_data) override { |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 116 | dbus_connection_remove_filter(connection, function, user_data); |
| 117 | } |
| 118 | |
| 119 | dbus_bool_t DBusMessageIsSignal(DBusMessage* message, |
| 120 | const char* interface, |
Alex Vakulenko | a839bc3 | 2014-08-14 12:55:41 -0700 | [diff] [blame] | 121 | const char* signal_name) override { |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 122 | return dbus_message_is_signal(message, interface, signal_name); |
| 123 | } |
| 124 | |
Alex Vakulenko | a839bc3 | 2014-08-14 12:55:41 -0700 | [diff] [blame] | 125 | dbus_bool_t DBusMessageGetArgs_3(DBusMessage* message, |
| 126 | DBusError* error, |
| 127 | char** out1, |
| 128 | char** out2, |
| 129 | char** out3) override { |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 130 | return dbus_message_get_args(message, error, |
| 131 | DBUS_TYPE_STRING, out1, |
| 132 | DBUS_TYPE_STRING, out2, |
| 133 | DBUS_TYPE_STRING, out3, |
| 134 | G_TYPE_INVALID); |
| 135 | } |
| 136 | }; |
| 137 | |
| 138 | } // namespace chromeos_update_engine |
| 139 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 140 | #endif // UPDATE_ENGINE_REAL_DBUS_WRAPPER_H_ |