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 | |
| 5 | #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_REAL_DBUS_WRAPPER_H_ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_REAL_DBUS_WRAPPER_H_ |
| 7 | |
| 8 | // A mockable interface for DBus. |
| 9 | |
| 10 | #include <dbus/dbus-glib-lowlevel.h> |
| 11 | #include <dbus/dbus-glib.h> |
| 12 | |
| 13 | #include "update_engine/dbus_wrapper_interface.h" |
| 14 | |
| 15 | namespace chromeos_update_engine { |
| 16 | |
| 17 | class RealDBusWrapper : public DBusWrapperInterface { |
| 18 | virtual DBusGProxy* ProxyNewForName(DBusGConnection* connection, |
| 19 | const char* name, |
| 20 | const char* path, |
| 21 | const char* interface) { |
| 22 | return dbus_g_proxy_new_for_name(connection, |
| 23 | name, |
| 24 | path, |
| 25 | interface); |
| 26 | } |
| 27 | |
| 28 | virtual void ProxyUnref(DBusGProxy* proxy) { |
| 29 | g_object_unref(proxy); |
| 30 | } |
| 31 | |
| 32 | virtual DBusGConnection* BusGet(DBusBusType type, GError** error) { |
| 33 | return dbus_g_bus_get(type, error); |
| 34 | } |
| 35 | |
| 36 | virtual gboolean ProxyCall_0_1(DBusGProxy* proxy, |
| 37 | const char* method, |
| 38 | GError** error, |
| 39 | GHashTable** out1) { |
| 40 | return dbus_g_proxy_call(proxy, method, error, G_TYPE_INVALID, |
| 41 | dbus_g_type_get_map("GHashTable", |
| 42 | G_TYPE_STRING, |
| 43 | G_TYPE_VALUE), |
| 44 | out1, G_TYPE_INVALID); |
| 45 | } |
| 46 | |
| 47 | virtual gboolean ProxyCall_3_0(DBusGProxy* proxy, |
| 48 | const char* method, |
| 49 | GError** error, |
| 50 | const char* in1, |
| 51 | const char* in2, |
| 52 | const char* in3) { |
| 53 | return dbus_g_proxy_call( |
| 54 | proxy, method, error, |
| 55 | G_TYPE_STRING, in1, G_TYPE_STRING, in2, G_TYPE_STRING, in3, |
| 56 | G_TYPE_INVALID, G_TYPE_INVALID); |
| 57 | } |
| 58 | |
Gilad Arnold | beb39e9 | 2014-03-11 11:34:50 -0700 | [diff] [blame] | 59 | virtual void ProxyAddSignal_2(DBusGProxy* proxy, |
| 60 | const char* signal_name, |
| 61 | GType type1, |
| 62 | GType type2) { |
| 63 | dbus_g_proxy_add_signal(proxy, signal_name, type1, type2, G_TYPE_INVALID); |
| 64 | } |
| 65 | |
| 66 | virtual void ProxyConnectSignal(DBusGProxy* proxy, |
| 67 | const char* signal_name, |
| 68 | GCallback handler, |
| 69 | void* data, |
| 70 | GClosureNotify free_data_func) { |
| 71 | dbus_g_proxy_connect_signal(proxy, signal_name, handler, data, |
| 72 | free_data_func); |
| 73 | } |
| 74 | |
| 75 | virtual void ProxyDisconnectSignal(DBusGProxy* proxy, |
| 76 | const char* signal_name, |
| 77 | GCallback handler, |
| 78 | void* data) { |
| 79 | dbus_g_proxy_disconnect_signal(proxy, signal_name, handler, data); |
| 80 | } |
| 81 | |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 82 | virtual DBusConnection* ConnectionGetConnection(DBusGConnection* gbus) { |
| 83 | return dbus_g_connection_get_connection(gbus); |
| 84 | } |
| 85 | |
| 86 | virtual void DBusBusAddMatch(DBusConnection* connection, |
| 87 | const char* rule, |
| 88 | DBusError* error) { |
| 89 | dbus_bus_add_match(connection, rule, error); |
| 90 | } |
| 91 | |
| 92 | virtual dbus_bool_t DBusConnectionAddFilter( |
| 93 | DBusConnection* connection, |
| 94 | DBusHandleMessageFunction function, |
| 95 | void* user_data, |
| 96 | DBusFreeFunction free_data_function) { |
| 97 | return dbus_connection_add_filter(connection, |
| 98 | function, |
| 99 | user_data, |
| 100 | free_data_function); |
| 101 | } |
| 102 | |
| 103 | virtual void DBusConnectionRemoveFilter(DBusConnection* connection, |
| 104 | DBusHandleMessageFunction function, |
| 105 | void* user_data) { |
| 106 | dbus_connection_remove_filter(connection, function, user_data); |
| 107 | } |
| 108 | |
| 109 | dbus_bool_t DBusMessageIsSignal(DBusMessage* message, |
| 110 | const char* interface, |
| 111 | const char* signal_name) { |
| 112 | return dbus_message_is_signal(message, interface, signal_name); |
| 113 | } |
| 114 | |
| 115 | virtual dbus_bool_t DBusMessageGetArgs_3(DBusMessage* message, |
| 116 | DBusError* error, |
| 117 | char** out1, |
| 118 | char** out2, |
| 119 | char** out3) { |
| 120 | return dbus_message_get_args(message, error, |
| 121 | DBUS_TYPE_STRING, out1, |
| 122 | DBUS_TYPE_STRING, out2, |
| 123 | DBUS_TYPE_STRING, out3, |
| 124 | G_TYPE_INVALID); |
| 125 | } |
| 126 | }; |
| 127 | |
| 128 | } // namespace chromeos_update_engine |
| 129 | |
| 130 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_REAL_DBUS_WRAPPER_H_ |