blob: 57211c5fd0e51602dcf8744dfa7591864726a311 [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).
Alex Deymo9b7ae1a2014-12-15 10:35:56 -080069 virtual void ProxyAddSignal_1(DBusGProxy* proxy,
70 const char* signal_name,
71 GType type1) = 0;
72
Gilad Arnoldbeb39e92014-03-11 11:34:50 -070073 virtual void ProxyAddSignal_2(DBusGProxy* proxy,
74 const char* signal_name,
75 GType type1,
76 GType type2) = 0;
77
78 // Wrapper for dbus_g_proxy_{connect,disconnect}_signal().
79 virtual void ProxyConnectSignal(DBusGProxy* proxy,
80 const char* signal_name,
81 GCallback handler,
82 void* data,
83 GClosureNotify free_data_func) = 0;
84 virtual void ProxyDisconnectSignal(DBusGProxy* proxy,
85 const char* signal_name,
86 GCallback handler,
87 void* data) = 0;
88
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080089 // Wraps dbus_g_connection_get_connection().
90 virtual DBusConnection* ConnectionGetConnection(DBusGConnection* gbus) = 0;
91
92 // Wraps dbus_bus_add_match().
93 virtual void DBusBusAddMatch(DBusConnection* connection,
94 const char* rule,
95 DBusError* error) = 0;
96
97 // Wraps dbus_connection_add_filter().
98 virtual dbus_bool_t DBusConnectionAddFilter(
99 DBusConnection* connection,
100 DBusHandleMessageFunction function,
101 void* user_data,
102 DBusFreeFunction free_data_function) = 0;
103
104 // Wraps dbus_connection_remove_filter().
105 virtual void DBusConnectionRemoveFilter(DBusConnection* connection,
106 DBusHandleMessageFunction function,
107 void* user_data) = 0;
108
109 // Wraps dbus_message_is_signal().
110 virtual dbus_bool_t DBusMessageIsSignal(DBusMessage* message,
111 const char* interface,
112 const char* signal_name) = 0;
113
114 // Wraps dbus_message_get_args(). Deploys the same approach for handling
115 // variadic arguments as ProxyCall above.
116 virtual dbus_bool_t DBusMessageGetArgs_3(DBusMessage* message,
117 DBusError* error,
118 char** out1,
119 char** out2,
120 char** out3) = 0;
121};
122
123} // namespace chromeos_update_engine
124
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700125#endif // UPDATE_ENGINE_DBUS_WRAPPER_INTERFACE_H_