Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_DBUS_INTERFACE_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_DBUS_INTERFACE_H__ | 
| 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_DBUS_INTERFACE_H__ | 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_DBUS_INTERFACE_H__ | 
| 7 | 7 | 
| 8 // This class interfaces with DBus. The interface allows it to be mocked. | 8 // This class interfaces with DBus. The interface allows it to be mocked. | 
| 9 | 9 | 
| 10 #include <base/logging.h> | |
| 10 #include <dbus/dbus-glib.h> | 11 #include <dbus/dbus-glib.h> | 
| 11 | 12 | 
| 12 namespace chromeos_update_engine { | 13 namespace chromeos_update_engine { | 
| 13 | 14 | 
| 14 class DbusGlibInterface { | 15 class DbusGlibInterface { | 
| 15 public: | 16 public: | 
| 16 // wraps dbus_g_proxy_new_for_name_owner | 17 // wraps dbus_g_proxy_new_for_name_owner | 
| 17 virtual DBusGProxy* ProxyNewForNameOwner(DBusGConnection* connection, | 18 virtual DBusGProxy* ProxyNewForNameOwner(DBusGConnection* connection, | 
| 18 const char* name, | 19 const char* name, | 
| 19 const char* path, | 20 const char* path, | 
| 20 const char* interface, | 21 const char* interface, | 
| 21 GError** error) = 0; | 22 GError** error) = 0; | 
| 22 | 23 | 
| 23 // wraps g_object_unref | 24 // wraps g_object_unref | 
| 24 virtual void ProxyUnref(DBusGProxy* proxy) = 0; | 25 virtual void ProxyUnref(DBusGProxy* proxy) = 0; | 
| 25 | 26 | 
| 26 // wraps dbus_g_bus_get | 27 // wraps dbus_g_bus_get | 
| 27 virtual DBusGConnection* BusGet(DBusBusType type, GError** error) = 0; | 28 virtual DBusGConnection* BusGet(DBusBusType type, GError** error) = 0; | 
| 28 | 29 | 
| 29 // wraps dbus_g_proxy_call | 30 // wraps dbus_g_proxy_call | 
| 30 virtual gboolean ProxyCall(DBusGProxy* proxy, | 31 virtual gboolean ProxyCall(DBusGProxy* proxy, | 
| 31 const char* method, | 32 const char* method, | 
| 32 GError** error, | 33 GError** error, | 
| 33 GType first_arg_type, | 34 GType first_arg_type, | 
| 34 GType var_arg1, | 35 GType var_arg1, | 
| 35 GHashTable** var_arg2, | 36 GHashTable** var_arg2, | 
| 36 GType var_arg3) = 0; | 37 GType var_arg3) = 0; | 
| 38 // Mock calls only go up to 10 args, so this is not required to be | |
| 
 
petkov
2010/11/18 23:26:46
add an empty line before.
 
adlr
2010/11/19 00:41:06
this comment was outdated and has been removed. al
 
 | |
| 39 // implemented in the mock. | |
| 40 virtual gboolean ProxyCall(DBusGProxy* proxy, | |
| 41 const char* method, | |
| 42 GError** error, | |
| 43 GType, const char*, | |
| 
 
petkov
2010/11/18 23:26:46
per style, you have to name the parameters, right?
 
adlr
2010/11/19 00:41:06
Done.
 
 | |
| 44 GType, | |
| 45 GType, gchar**, | |
| 46 GType, GArray**, | |
| 47 GType) { | |
| 
 
petkov
2010/11/18 23:26:46
The last argument is always INVALID, right? So you
 
adlr
2010/11/19 00:41:06
i got the mock to implement this, so the impl here
 
petkov
2010/11/19 01:09:19
OK, although the last argument is still unnecessar
 
adlr
2010/11/19 02:00:52
It's true that it's not necessary since in practic
 
 | |
| 48 NOTREACHED(); | |
| 49 return false; // appease gcc | |
| 50 }; | |
| 37 }; | 51 }; | 
| 38 | 52 | 
| 39 class ConcreteDbusGlib : public DbusGlibInterface { | 53 class ConcreteDbusGlib : public DbusGlibInterface { | 
| 40 virtual DBusGProxy* ProxyNewForNameOwner(DBusGConnection* connection, | 54 virtual DBusGProxy* ProxyNewForNameOwner(DBusGConnection* connection, | 
| 41 const char* name, | 55 const char* name, | 
| 42 const char* path, | 56 const char* path, | 
| 43 const char* interface, | 57 const char* interface, | 
| 44 GError** error) { | 58 GError** error) { | 
| 45 return dbus_g_proxy_new_for_name_owner(connection, | 59 return dbus_g_proxy_new_for_name_owner(connection, | 
| 46 name, | 60 name, | 
| (...skipping 13 matching lines...) Expand all Loading... | |
| 60 virtual gboolean ProxyCall(DBusGProxy* proxy, | 74 virtual gboolean ProxyCall(DBusGProxy* proxy, | 
| 61 const char* method, | 75 const char* method, | 
| 62 GError** error, | 76 GError** error, | 
| 63 GType first_arg_type, | 77 GType first_arg_type, | 
| 64 GType var_arg1, | 78 GType var_arg1, | 
| 65 GHashTable** var_arg2, | 79 GHashTable** var_arg2, | 
| 66 GType var_arg3) { | 80 GType var_arg3) { | 
| 67 return dbus_g_proxy_call( | 81 return dbus_g_proxy_call( | 
| 68 proxy, method, error, first_arg_type, var_arg1, var_arg2, var_arg3); | 82 proxy, method, error, first_arg_type, var_arg1, var_arg2, var_arg3); | 
| 69 } | 83 } | 
| 84 virtual gboolean ProxyCall(DBusGProxy* proxy, | |
| 
 
petkov
2010/11/18 23:26:46
add an empty line before.
 
adlr
2010/11/19 00:41:06
Done.
 
 | |
| 85 const char* method, | |
| 86 GError** error, | |
| 87 GType var_arg1, const char* var_arg2, | |
| 88 GType var_arg3, | |
| 89 GType var_arg4, gchar** var_arg5, | |
| 90 GType var_arg6, GArray** var_arg7, | |
| 91 GType var_arg8) { | |
| 92 return dbus_g_proxy_call( | |
| 
 
petkov
2010/11/18 23:26:46
Do you want to use a dbus_g_proxy_call with a time
 
adlr
2010/11/19 00:41:06
I think there's a default timeout of 30s, which th
 
 | |
| 93 proxy, method, error, var_arg1, var_arg2, var_arg3, | |
| 94 var_arg4, var_arg5, var_arg6, var_arg7, var_arg8); | |
| 95 } | |
| 70 }; | 96 }; | 
| 71 | 97 | 
| 72 } // namespace chromeos_update_engine | 98 } // namespace chromeos_update_engine | 
| 73 | 99 | 
| 74 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_DBUS_INTERFACE_H__ | 100 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_DBUS_INTERFACE_H__ | 
| OLD | NEW |