blob: b7656000bac95bf4e84f3448bfd1bcbd8ee70e34 [file] [log] [blame]
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -08001// 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 Arnoldcf175a02014-07-10 16:48:47 -07005#ifndef UPDATE_ENGINE_DBUS_WRAPPER_INTERFACE_H_
6#define UPDATE_ENGINE_DBUS_WRAPPER_INTERFACE_H_
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -08007
8// A mockable interface for DBus.
9
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080010#include <dbus/dbus.h>
Alex Vakulenko44cab302014-07-23 13:12:15 -070011#include <dbus/dbus-glib.h>
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080012
13#ifndef DBUS_TYPE_G_OBJECT_PATH_ARRAY
14#define DBUS_TYPE_G_OBJECT_PATH_ARRAY \
Alex Vakulenkod2779df2014-06-16 13:19:00 -070015 (dbus_g_type_get_collection("GPtrArray", DBUS_TYPE_G_OBJECT_PATH))
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080016#endif
17
18#ifndef DBUS_TYPE_G_STRING_ARRAY
19#define DBUS_TYPE_G_STRING_ARRAY \
Alex Vakulenkod2779df2014-06-16 13:19:00 -070020 (dbus_g_type_get_collection("GPtrArray", G_TYPE_STRING))
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080021#endif
22
23namespace chromeos_update_engine {
24
25class DBusWrapperInterface {
26 public:
Alex Deymoe8948702014-11-11 21:44:45 -080027 virtual ~DBusWrapperInterface() = default;
28
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080029 // Wraps dbus_g_proxy_new_for_name().
30 virtual DBusGProxy* ProxyNewForName(DBusGConnection* connection,
31 const char* name,
32 const char* path,
33 const char* interface) = 0;
34
35 // Wraps g_object_unref().
36 virtual void ProxyUnref(DBusGProxy* proxy) = 0;
37
38 // Wraps dbus_g_bus_get().
39 virtual DBusGConnection* BusGet(DBusBusType type, GError** error) = 0;
40
41 // Wraps dbus_g_proxy_call(). Since this is a variadic function without a
42 // va_list equivalent, we have to list specific wrappers depending on the
43 // number of input and output arguments, based on the required usage. Note,
44 // however, that we do rely on automatic signature overriding to facilitate
45 // different types of input/output arguments.
46 virtual gboolean ProxyCall_0_1(DBusGProxy* proxy,
47 const char* method,
48 GError** error,
49 GHashTable** out1) = 0;
50
Daniel Erat65f1da02014-06-27 22:05:38 -070051 virtual gboolean ProxyCall_1_0(DBusGProxy* proxy,
52 const char* method,
53 GError** error,
54 gint in1) = 0;
55
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080056 virtual gboolean ProxyCall_3_0(DBusGProxy* proxy,
57 const char* method,
58 GError** error,
59 const char* in1,
60 const char* in2,
61 const char* in3) = 0;
62
Gilad Arnoldbeb39e92014-03-11 11:34:50 -070063 // Wrappers for dbus_g_proxy_add_signal() (variadic).
64 virtual void ProxyAddSignal_2(DBusGProxy* proxy,
65 const char* signal_name,
66 GType type1,
67 GType type2) = 0;
68
69 // Wrapper for dbus_g_proxy_{connect,disconnect}_signal().
70 virtual void ProxyConnectSignal(DBusGProxy* proxy,
71 const char* signal_name,
72 GCallback handler,
73 void* data,
74 GClosureNotify free_data_func) = 0;
75 virtual void ProxyDisconnectSignal(DBusGProxy* proxy,
76 const char* signal_name,
77 GCallback handler,
78 void* data) = 0;
79
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080080 // Wraps dbus_g_connection_get_connection().
81 virtual DBusConnection* ConnectionGetConnection(DBusGConnection* gbus) = 0;
82
83 // Wraps dbus_bus_add_match().
84 virtual void DBusBusAddMatch(DBusConnection* connection,
85 const char* rule,
86 DBusError* error) = 0;
87
88 // Wraps dbus_connection_add_filter().
89 virtual dbus_bool_t DBusConnectionAddFilter(
90 DBusConnection* connection,
91 DBusHandleMessageFunction function,
92 void* user_data,
93 DBusFreeFunction free_data_function) = 0;
94
95 // Wraps dbus_connection_remove_filter().
96 virtual void DBusConnectionRemoveFilter(DBusConnection* connection,
97 DBusHandleMessageFunction function,
98 void* user_data) = 0;
99
100 // Wraps dbus_message_is_signal().
101 virtual dbus_bool_t DBusMessageIsSignal(DBusMessage* message,
102 const char* interface,
103 const char* signal_name) = 0;
104
105 // Wraps dbus_message_get_args(). Deploys the same approach for handling
106 // variadic arguments as ProxyCall above.
107 virtual dbus_bool_t DBusMessageGetArgs_3(DBusMessage* message,
108 DBusError* error,
109 char** out1,
110 char** out2,
111 char** out3) = 0;
112};
113
114} // namespace chromeos_update_engine
115
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700116#endif // UPDATE_ENGINE_DBUS_WRAPPER_INTERFACE_H_