blob: 1b5c9536ce25a9580ada598745f2a34b8a6d2680 [file] [log] [blame]
Andrew de los Reyesd57d1472010-10-21 13:34:08 -07001// 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
10#include <dbus/dbus-glib.h>
11
12namespace chromeos_update_engine {
13
14class DbusGlibInterface {
15 public:
16 // wraps dbus_g_proxy_new_for_name_owner
17 virtual DBusGProxy* ProxyNewForNameOwner(DBusGConnection* connection,
18 const char* name,
19 const char* path,
20 const char* interface,
21 GError** error) = 0;
22
23 // wraps g_object_unref
24 virtual void ProxyUnref(DBusGProxy* proxy) = 0;
25
26 // wraps dbus_g_bus_get
27 virtual DBusGConnection* BusGet(DBusBusType type, GError** error) = 0;
28
29 // wraps dbus_g_proxy_call
30 virtual gboolean ProxyCall(DBusGProxy* proxy,
31 const char* method,
32 GError** error,
33 GType first_arg_type,
34 GType var_arg1,
35 GHashTable** var_arg2,
36 GType var_arg3) = 0;
37};
38
39class ConcreteDbusGlib : public DbusGlibInterface {
40 virtual DBusGProxy* ProxyNewForNameOwner(DBusGConnection* connection,
41 const char* name,
42 const char* path,
43 const char* interface,
44 GError** error) {
45 return dbus_g_proxy_new_for_name_owner(connection,
46 name,
47 path,
48 interface,
49 error);
50 }
51
52 virtual void ProxyUnref(DBusGProxy* proxy) {
53 g_object_unref(proxy);
54 }
55
56 virtual DBusGConnection* BusGet(DBusBusType type, GError** error) {
57 return dbus_g_bus_get(type, error);
58 }
59
60 virtual gboolean ProxyCall(DBusGProxy* proxy,
61 const char* method,
62 GError** error,
63 GType first_arg_type,
64 GType var_arg1,
65 GHashTable** var_arg2,
66 GType var_arg3) {
67 return dbus_g_proxy_call(
68 proxy, method, error, first_arg_type, var_arg1, var_arg2, var_arg3);
69 }
70};
71
72} // namespace chromeos_update_engine
73
74#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_DBUS_INTERFACE_H__