blob: ab7a969b84a6ed92865fd7fba53cd13c09da9dd9 [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_REAL_DBUS_WRAPPER_H_
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_REAL_DBUS_WRAPPER_H_
7
8// A mockable interface for DBus.
9
10#include <dbus/dbus-glib-lowlevel.h>
11#include <dbus/dbus-glib.h>
12
13#include "update_engine/dbus_wrapper_interface.h"
14
15namespace chromeos_update_engine {
16
17class RealDBusWrapper : public DBusWrapperInterface {
18 virtual DBusGProxy* ProxyNewForName(DBusGConnection* connection,
19 const char* name,
20 const char* path,
21 const char* interface) {
22 return dbus_g_proxy_new_for_name(connection,
23 name,
24 path,
25 interface);
26 }
27
28 virtual void ProxyUnref(DBusGProxy* proxy) {
29 g_object_unref(proxy);
30 }
31
32 virtual DBusGConnection* BusGet(DBusBusType type, GError** error) {
33 return dbus_g_bus_get(type, error);
34 }
35
36 virtual gboolean ProxyCall_0_1(DBusGProxy* proxy,
37 const char* method,
38 GError** error,
39 GHashTable** out1) {
40 return dbus_g_proxy_call(proxy, method, error, G_TYPE_INVALID,
41 dbus_g_type_get_map("GHashTable",
42 G_TYPE_STRING,
43 G_TYPE_VALUE),
44 out1, G_TYPE_INVALID);
45 }
46
47 virtual gboolean ProxyCall_3_0(DBusGProxy* proxy,
48 const char* method,
49 GError** error,
50 const char* in1,
51 const char* in2,
52 const char* in3) {
53 return dbus_g_proxy_call(
54 proxy, method, error,
55 G_TYPE_STRING, in1, G_TYPE_STRING, in2, G_TYPE_STRING, in3,
56 G_TYPE_INVALID, G_TYPE_INVALID);
57 }
58
59 virtual DBusConnection* ConnectionGetConnection(DBusGConnection* gbus) {
60 return dbus_g_connection_get_connection(gbus);
61 }
62
63 virtual void DBusBusAddMatch(DBusConnection* connection,
64 const char* rule,
65 DBusError* error) {
66 dbus_bus_add_match(connection, rule, error);
67 }
68
69 virtual dbus_bool_t DBusConnectionAddFilter(
70 DBusConnection* connection,
71 DBusHandleMessageFunction function,
72 void* user_data,
73 DBusFreeFunction free_data_function) {
74 return dbus_connection_add_filter(connection,
75 function,
76 user_data,
77 free_data_function);
78 }
79
80 virtual void DBusConnectionRemoveFilter(DBusConnection* connection,
81 DBusHandleMessageFunction function,
82 void* user_data) {
83 dbus_connection_remove_filter(connection, function, user_data);
84 }
85
86 dbus_bool_t DBusMessageIsSignal(DBusMessage* message,
87 const char* interface,
88 const char* signal_name) {
89 return dbus_message_is_signal(message, interface, signal_name);
90 }
91
92 virtual dbus_bool_t DBusMessageGetArgs_3(DBusMessage* message,
93 DBusError* error,
94 char** out1,
95 char** out2,
96 char** out3) {
97 return dbus_message_get_args(message, error,
98 DBUS_TYPE_STRING, out1,
99 DBUS_TYPE_STRING, out2,
100 DBUS_TYPE_STRING, out3,
101 G_TYPE_INVALID);
102 }
103};
104
105} // namespace chromeos_update_engine
106
107#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_REAL_DBUS_WRAPPER_H_