blob: 002b486418b52af8b918d4dd2b45141403190cf3 [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_REAL_DBUS_WRAPPER_H_
6#define UPDATE_ENGINE_REAL_DBUS_WRAPPER_H_
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -08007
8// A mockable interface for DBus.
9
Daniel Erat65f1da02014-06-27 22:05:38 -070010#include <base/macros.h>
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080011#include <dbus/dbus-glib.h>
Alex Vakulenko44cab302014-07-23 13:12:15 -070012#include <dbus/dbus-glib-lowlevel.h>
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080013
14#include "update_engine/dbus_wrapper_interface.h"
15
16namespace chromeos_update_engine {
17
18class RealDBusWrapper : public DBusWrapperInterface {
19 virtual DBusGProxy* ProxyNewForName(DBusGConnection* connection,
20 const char* name,
21 const char* path,
Daniel Erat65f1da02014-06-27 22:05:38 -070022 const char* interface) OVERRIDE {
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080023 return dbus_g_proxy_new_for_name(connection,
24 name,
25 path,
26 interface);
27 }
28
Daniel Erat65f1da02014-06-27 22:05:38 -070029 virtual void ProxyUnref(DBusGProxy* proxy) OVERRIDE {
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080030 g_object_unref(proxy);
31 }
32
Daniel Erat65f1da02014-06-27 22:05:38 -070033 virtual DBusGConnection* BusGet(DBusBusType type, GError** error) OVERRIDE {
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080034 return dbus_g_bus_get(type, error);
35 }
36
37 virtual gboolean ProxyCall_0_1(DBusGProxy* proxy,
38 const char* method,
39 GError** error,
Daniel Erat65f1da02014-06-27 22:05:38 -070040 GHashTable** out1) OVERRIDE {
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080041 return dbus_g_proxy_call(proxy, method, error, G_TYPE_INVALID,
42 dbus_g_type_get_map("GHashTable",
43 G_TYPE_STRING,
44 G_TYPE_VALUE),
45 out1, G_TYPE_INVALID);
46 }
47
Daniel Erat65f1da02014-06-27 22:05:38 -070048 virtual gboolean ProxyCall_1_0(DBusGProxy* proxy,
49 const char* method,
50 GError** error,
51 gint in1) OVERRIDE {
52 return dbus_g_proxy_call(proxy, method, error,
53 G_TYPE_INT, in1,
54 G_TYPE_INVALID, G_TYPE_INVALID);
55 }
56
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080057 virtual gboolean ProxyCall_3_0(DBusGProxy* proxy,
58 const char* method,
59 GError** error,
60 const char* in1,
61 const char* in2,
Daniel Erat65f1da02014-06-27 22:05:38 -070062 const char* in3) OVERRIDE {
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080063 return dbus_g_proxy_call(
64 proxy, method, error,
65 G_TYPE_STRING, in1, G_TYPE_STRING, in2, G_TYPE_STRING, in3,
66 G_TYPE_INVALID, G_TYPE_INVALID);
67 }
68
Gilad Arnoldbeb39e92014-03-11 11:34:50 -070069 virtual void ProxyAddSignal_2(DBusGProxy* proxy,
70 const char* signal_name,
71 GType type1,
Daniel Erat65f1da02014-06-27 22:05:38 -070072 GType type2) OVERRIDE {
Gilad Arnoldbeb39e92014-03-11 11:34:50 -070073 dbus_g_proxy_add_signal(proxy, signal_name, type1, type2, G_TYPE_INVALID);
74 }
75
76 virtual void ProxyConnectSignal(DBusGProxy* proxy,
77 const char* signal_name,
78 GCallback handler,
79 void* data,
Daniel Erat65f1da02014-06-27 22:05:38 -070080 GClosureNotify free_data_func) OVERRIDE {
Gilad Arnoldbeb39e92014-03-11 11:34:50 -070081 dbus_g_proxy_connect_signal(proxy, signal_name, handler, data,
82 free_data_func);
83 }
84
85 virtual void ProxyDisconnectSignal(DBusGProxy* proxy,
86 const char* signal_name,
87 GCallback handler,
Daniel Erat65f1da02014-06-27 22:05:38 -070088 void* data) OVERRIDE {
Gilad Arnoldbeb39e92014-03-11 11:34:50 -070089 dbus_g_proxy_disconnect_signal(proxy, signal_name, handler, data);
90 }
91
Daniel Erat65f1da02014-06-27 22:05:38 -070092 virtual DBusConnection* ConnectionGetConnection(
93 DBusGConnection* gbus) OVERRIDE {
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080094 return dbus_g_connection_get_connection(gbus);
95 }
96
97 virtual void DBusBusAddMatch(DBusConnection* connection,
98 const char* rule,
Daniel Erat65f1da02014-06-27 22:05:38 -070099 DBusError* error) OVERRIDE {
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -0800100 dbus_bus_add_match(connection, rule, error);
101 }
102
103 virtual dbus_bool_t DBusConnectionAddFilter(
104 DBusConnection* connection,
105 DBusHandleMessageFunction function,
106 void* user_data,
Daniel Erat65f1da02014-06-27 22:05:38 -0700107 DBusFreeFunction free_data_function) OVERRIDE {
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -0800108 return dbus_connection_add_filter(connection,
109 function,
110 user_data,
111 free_data_function);
112 }
113
114 virtual void DBusConnectionRemoveFilter(DBusConnection* connection,
115 DBusHandleMessageFunction function,
Daniel Erat65f1da02014-06-27 22:05:38 -0700116 void* user_data) OVERRIDE {
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -0800117 dbus_connection_remove_filter(connection, function, user_data);
118 }
119
120 dbus_bool_t DBusMessageIsSignal(DBusMessage* message,
121 const char* interface,
Daniel Erat65f1da02014-06-27 22:05:38 -0700122 const char* signal_name) OVERRIDE {
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -0800123 return dbus_message_is_signal(message, interface, signal_name);
124 }
125
126 virtual dbus_bool_t DBusMessageGetArgs_3(DBusMessage* message,
127 DBusError* error,
128 char** out1,
129 char** out2,
Daniel Erat65f1da02014-06-27 22:05:38 -0700130 char** out3) OVERRIDE {
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -0800131 return dbus_message_get_args(message, error,
132 DBUS_TYPE_STRING, out1,
133 DBUS_TYPE_STRING, out2,
134 DBUS_TYPE_STRING, out3,
135 G_TYPE_INVALID);
136 }
137};
138
139} // namespace chromeos_update_engine
140
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700141#endif // UPDATE_ENGINE_REAL_DBUS_WRAPPER_H_