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