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