blob: 568d4fa9c6b984cd76826c0dd38f7b025d6fe40e [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
David Pursell02c18642014-11-06 11:26:11 -080051 virtual gboolean ProxyCall_0_1(DBusGProxy* proxy,
52 const char* method,
53 GError** error,
54 gint* out1) = 0;
55
Daniel Erat65f1da02014-06-27 22:05:38 -070056 virtual gboolean ProxyCall_1_0(DBusGProxy* proxy,
57 const char* method,
58 GError** error,
59 gint in1) = 0;
60
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080061 virtual gboolean ProxyCall_3_0(DBusGProxy* proxy,
62 const char* method,
63 GError** error,
64 const char* in1,
65 const char* in2,
66 const char* in3) = 0;
67
Gilad Arnoldbeb39e92014-03-11 11:34:50 -070068 // Wrappers for dbus_g_proxy_add_signal() (variadic).
69 virtual void ProxyAddSignal_2(DBusGProxy* proxy,
70 const char* signal_name,
71 GType type1,
72 GType type2) = 0;
73
74 // Wrapper for dbus_g_proxy_{connect,disconnect}_signal().
75 virtual void ProxyConnectSignal(DBusGProxy* proxy,
76 const char* signal_name,
77 GCallback handler,
78 void* data,
79 GClosureNotify free_data_func) = 0;
80 virtual void ProxyDisconnectSignal(DBusGProxy* proxy,
81 const char* signal_name,
82 GCallback handler,
83 void* data) = 0;
84
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080085 // Wraps dbus_g_connection_get_connection().
86 virtual DBusConnection* ConnectionGetConnection(DBusGConnection* gbus) = 0;
87
88 // Wraps dbus_bus_add_match().
89 virtual void DBusBusAddMatch(DBusConnection* connection,
90 const char* rule,
91 DBusError* error) = 0;
92
93 // Wraps dbus_connection_add_filter().
94 virtual dbus_bool_t DBusConnectionAddFilter(
95 DBusConnection* connection,
96 DBusHandleMessageFunction function,
97 void* user_data,
98 DBusFreeFunction free_data_function) = 0;
99
100 // Wraps dbus_connection_remove_filter().
101 virtual void DBusConnectionRemoveFilter(DBusConnection* connection,
102 DBusHandleMessageFunction function,
103 void* user_data) = 0;
104
105 // Wraps dbus_message_is_signal().
106 virtual dbus_bool_t DBusMessageIsSignal(DBusMessage* message,
107 const char* interface,
108 const char* signal_name) = 0;
109
110 // Wraps dbus_message_get_args(). Deploys the same approach for handling
111 // variadic arguments as ProxyCall above.
112 virtual dbus_bool_t DBusMessageGetArgs_3(DBusMessage* message,
113 DBusError* error,
114 char** out1,
115 char** out2,
116 char** out3) = 0;
117};
118
119} // namespace chromeos_update_engine
120
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700121#endif // UPDATE_ENGINE_DBUS_WRAPPER_INTERFACE_H_