blob: 0978c3b8bb6e21d082a20b9dd3f47c4811034c7c [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
5#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_DBUS_WRAPPER_H_
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_DBUS_WRAPPER_H_
7
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
56 // Wraps dbus_g_connection_get_connection().
57 virtual DBusConnection* ConnectionGetConnection(DBusGConnection* gbus) = 0;
58
59 // Wraps dbus_bus_add_match().
60 virtual void DBusBusAddMatch(DBusConnection* connection,
61 const char* rule,
62 DBusError* error) = 0;
63
64 // Wraps dbus_connection_add_filter().
65 virtual dbus_bool_t DBusConnectionAddFilter(
66 DBusConnection* connection,
67 DBusHandleMessageFunction function,
68 void* user_data,
69 DBusFreeFunction free_data_function) = 0;
70
71 // Wraps dbus_connection_remove_filter().
72 virtual void DBusConnectionRemoveFilter(DBusConnection* connection,
73 DBusHandleMessageFunction function,
74 void* user_data) = 0;
75
76 // Wraps dbus_message_is_signal().
77 virtual dbus_bool_t DBusMessageIsSignal(DBusMessage* message,
78 const char* interface,
79 const char* signal_name) = 0;
80
81 // Wraps dbus_message_get_args(). Deploys the same approach for handling
82 // variadic arguments as ProxyCall above.
83 virtual dbus_bool_t DBusMessageGetArgs_3(DBusMessage* message,
84 DBusError* error,
85 char** out1,
86 char** out2,
87 char** out3) = 0;
88};
89
90} // namespace chromeos_update_engine
91
92#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_DBUS_WRAPPER_H_