Andrew de los Reyes | d57d147 | 2010-10-21 13:34:08 -0700 | [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_DBUS_INTERFACE_H__ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_DBUS_INTERFACE_H__ |
| 7 | |
| 8 | // This class interfaces with DBus. The interface allows it to be mocked. |
| 9 | |
Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 10 | #include <base/logging.h> |
Andrew de los Reyes | d57d147 | 2010-10-21 13:34:08 -0700 | [diff] [blame] | 11 | #include <dbus/dbus-glib.h> |
| 12 | |
| 13 | namespace chromeos_update_engine { |
| 14 | |
| 15 | class DbusGlibInterface { |
| 16 | public: |
| 17 | // wraps dbus_g_proxy_new_for_name_owner |
| 18 | virtual DBusGProxy* ProxyNewForNameOwner(DBusGConnection* connection, |
| 19 | const char* name, |
| 20 | const char* path, |
| 21 | const char* interface, |
| 22 | GError** error) = 0; |
| 23 | |
| 24 | // wraps g_object_unref |
| 25 | virtual void ProxyUnref(DBusGProxy* proxy) = 0; |
| 26 | |
| 27 | // wraps dbus_g_bus_get |
| 28 | virtual DBusGConnection* BusGet(DBusBusType type, GError** error) = 0; |
Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 29 | |
Andrew de los Reyes | d57d147 | 2010-10-21 13:34:08 -0700 | [diff] [blame] | 30 | // wraps dbus_g_proxy_call |
| 31 | virtual gboolean ProxyCall(DBusGProxy* proxy, |
| 32 | const char* method, |
| 33 | GError** error, |
| 34 | GType first_arg_type, |
| 35 | GType var_arg1, |
| 36 | GHashTable** var_arg2, |
| 37 | GType var_arg3) = 0; |
Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 38 | |
| 39 | virtual gboolean ProxyCall(DBusGProxy* proxy, |
| 40 | const char* method, |
| 41 | GError** error, |
| 42 | GType var_arg1, const char* var_arg2, |
| 43 | GType var_arg3, |
| 44 | GType var_arg4, gchar** var_arg5, |
| 45 | GType var_arg6, GArray** var_arg7, |
| 46 | GType var_arg8) = 0; |
Andrew de los Reyes | d57d147 | 2010-10-21 13:34:08 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | class ConcreteDbusGlib : public DbusGlibInterface { |
| 50 | virtual DBusGProxy* ProxyNewForNameOwner(DBusGConnection* connection, |
| 51 | const char* name, |
| 52 | const char* path, |
| 53 | const char* interface, |
| 54 | GError** error) { |
| 55 | return dbus_g_proxy_new_for_name_owner(connection, |
| 56 | name, |
| 57 | path, |
| 58 | interface, |
| 59 | error); |
| 60 | } |
| 61 | |
| 62 | virtual void ProxyUnref(DBusGProxy* proxy) { |
| 63 | g_object_unref(proxy); |
| 64 | } |
| 65 | |
| 66 | virtual DBusGConnection* BusGet(DBusBusType type, GError** error) { |
| 67 | return dbus_g_bus_get(type, error); |
| 68 | } |
| 69 | |
| 70 | virtual gboolean ProxyCall(DBusGProxy* proxy, |
| 71 | const char* method, |
| 72 | GError** error, |
| 73 | GType first_arg_type, |
| 74 | GType var_arg1, |
| 75 | GHashTable** var_arg2, |
| 76 | GType var_arg3) { |
| 77 | return dbus_g_proxy_call( |
| 78 | proxy, method, error, first_arg_type, var_arg1, var_arg2, var_arg3); |
| 79 | } |
Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 80 | |
| 81 | virtual gboolean ProxyCall(DBusGProxy* proxy, |
| 82 | const char* method, |
| 83 | GError** error, |
| 84 | GType var_arg1, const char* var_arg2, |
| 85 | GType var_arg3, |
| 86 | GType var_arg4, gchar** var_arg5, |
| 87 | GType var_arg6, GArray** var_arg7, |
| 88 | GType var_arg8) { |
| 89 | return dbus_g_proxy_call( |
| 90 | proxy, method, error, var_arg1, var_arg2, var_arg3, |
| 91 | var_arg4, var_arg5, var_arg6, var_arg7, var_arg8); |
| 92 | } |
Andrew de los Reyes | d57d147 | 2010-10-21 13:34:08 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | } // namespace chromeos_update_engine |
| 96 | |
| 97 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_DBUS_INTERFACE_H__ |