blob: f05116ca9cb3abfa27c595498d857545db91ad6b [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 {
Alex Vakulenkoa839bc32014-08-14 12:55:41 -070019 DBusGProxy* ProxyNewForName(DBusGConnection* connection,
20 const char* name,
21 const char* path,
22 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
Alex Vakulenkoa839bc32014-08-14 12:55:41 -070029 void ProxyUnref(DBusGProxy* proxy) override {
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080030 g_object_unref(proxy);
31 }
32
Alex Vakulenkoa839bc32014-08-14 12:55:41 -070033 DBusGConnection* BusGet(DBusBusType type, GError** error) override {
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080034 return dbus_g_bus_get(type, error);
35 }
36
Alex Vakulenkoa839bc32014-08-14 12:55:41 -070037 gboolean ProxyCall_0_1(DBusGProxy* proxy,
38 const char* method,
39 GError** error,
40 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
Alex Vakulenkoa839bc32014-08-14 12:55:41 -070048 gboolean ProxyCall_1_0(DBusGProxy* proxy,
49 const char* method,
50 GError** error,
51 gint in1) override {
Daniel Erat65f1da02014-06-27 22:05:38 -070052 return dbus_g_proxy_call(proxy, method, error,
53 G_TYPE_INT, in1,
54 G_TYPE_INVALID, G_TYPE_INVALID);
55 }
56
Alex Vakulenkoa839bc32014-08-14 12:55:41 -070057 gboolean ProxyCall_3_0(DBusGProxy* proxy,
58 const char* method,
59 GError** error,
60 const char* in1,
61 const char* in2,
62 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
Alex Vakulenkoa839bc32014-08-14 12:55:41 -070069 void ProxyAddSignal_2(DBusGProxy* proxy,
70 const char* signal_name,
71 GType type1,
72 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
Alex Vakulenkoa839bc32014-08-14 12:55:41 -070076 void ProxyConnectSignal(DBusGProxy* proxy,
77 const char* signal_name,
78 GCallback handler,
79 void* data,
80 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
Alex Vakulenkoa839bc32014-08-14 12:55:41 -070085 void ProxyDisconnectSignal(DBusGProxy* proxy,
86 const char* signal_name,
87 GCallback handler,
88 void* data) override {
Gilad Arnoldbeb39e92014-03-11 11:34:50 -070089 dbus_g_proxy_disconnect_signal(proxy, signal_name, handler, data);
90 }
91
Alex Vakulenkoa839bc32014-08-14 12:55:41 -070092 DBusConnection* ConnectionGetConnection(DBusGConnection* gbus) override {
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080093 return dbus_g_connection_get_connection(gbus);
94 }
95
Alex Vakulenkoa839bc32014-08-14 12:55:41 -070096 void DBusBusAddMatch(DBusConnection* connection,
97 const char* rule,
98 DBusError* error) override {
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080099 dbus_bus_add_match(connection, rule, error);
100 }
101
Alex Vakulenkoa839bc32014-08-14 12:55:41 -0700102 dbus_bool_t DBusConnectionAddFilter(
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -0800103 DBusConnection* connection,
104 DBusHandleMessageFunction function,
105 void* user_data,
Alex Vakulenkoa839bc32014-08-14 12:55:41 -0700106 DBusFreeFunction free_data_function) override {
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -0800107 return dbus_connection_add_filter(connection,
108 function,
109 user_data,
110 free_data_function);
111 }
112
Alex Vakulenkoa839bc32014-08-14 12:55:41 -0700113 void DBusConnectionRemoveFilter(DBusConnection* connection,
114 DBusHandleMessageFunction function,
115 void* user_data) override {
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -0800116 dbus_connection_remove_filter(connection, function, user_data);
117 }
118
119 dbus_bool_t DBusMessageIsSignal(DBusMessage* message,
120 const char* interface,
Alex Vakulenkoa839bc32014-08-14 12:55:41 -0700121 const char* signal_name) override {
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -0800122 return dbus_message_is_signal(message, interface, signal_name);
123 }
124
Alex Vakulenkoa839bc32014-08-14 12:55:41 -0700125 dbus_bool_t DBusMessageGetArgs_3(DBusMessage* message,
126 DBusError* error,
127 char** out1,
128 char** out2,
129 char** out3) override {
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -0800130 return dbus_message_get_args(message, error,
131 DBUS_TYPE_STRING, out1,
132 DBUS_TYPE_STRING, out2,
133 DBUS_TYPE_STRING, out3,
134 G_TYPE_INVALID);
135 }
136};
137
138} // namespace chromeos_update_engine
139
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700140#endif // UPDATE_ENGINE_REAL_DBUS_WRAPPER_H_