Further cleanup around DBus interface classes.
* Removed the "Glib" part from the various DbusGlib class name and added
"Wrapper" instead: only part of the methods here declared have
anything to do with Glib; in essence, this is an interface containing
wrappers for various DBus functions.
* Changed "Dbus" to "DBus", to comply with the rest of the world.
* Renamed the actual implementation "RealDBusWrapper" (instead of
"Concrete").
* Separated out RealDBusWrapper into its own header file. Client code,
which often only cares about the abstract class, does not need to pull
it unless specifically requiring it.
* Cleaned up the includes in these headers.
Aside from all that, also renamed system_state.cc into
real_system_state.cc, as this is what this file contains.
BUG=None
TEST=Unit tests.
Change-Id: I015c407cbc159aba8b5925eb0e916ba604c829cd
Reviewed-on: https://chromium-review.googlesource.com/189373
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
diff --git a/dbus_wrapper_interface.h b/dbus_wrapper_interface.h
new file mode 100644
index 0000000..0978c3b
--- /dev/null
+++ b/dbus_wrapper_interface.h
@@ -0,0 +1,92 @@
+// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_DBUS_WRAPPER_H_
+#define CHROMEOS_PLATFORM_UPDATE_ENGINE_DBUS_WRAPPER_H_
+
+// A mockable interface for DBus.
+
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus.h>
+
+#ifndef DBUS_TYPE_G_OBJECT_PATH_ARRAY
+#define DBUS_TYPE_G_OBJECT_PATH_ARRAY \
+ (dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH))
+#endif
+
+#ifndef DBUS_TYPE_G_STRING_ARRAY
+#define DBUS_TYPE_G_STRING_ARRAY \
+ (dbus_g_type_get_collection ("GPtrArray", G_TYPE_STRING))
+#endif
+
+namespace chromeos_update_engine {
+
+class DBusWrapperInterface {
+ public:
+ // Wraps dbus_g_proxy_new_for_name().
+ virtual DBusGProxy* ProxyNewForName(DBusGConnection* connection,
+ const char* name,
+ const char* path,
+ const char* interface) = 0;
+
+ // Wraps g_object_unref().
+ virtual void ProxyUnref(DBusGProxy* proxy) = 0;
+
+ // Wraps dbus_g_bus_get().
+ virtual DBusGConnection* BusGet(DBusBusType type, GError** error) = 0;
+
+ // Wraps dbus_g_proxy_call(). Since this is a variadic function without a
+ // va_list equivalent, we have to list specific wrappers depending on the
+ // number of input and output arguments, based on the required usage. Note,
+ // however, that we do rely on automatic signature overriding to facilitate
+ // different types of input/output arguments.
+ virtual gboolean ProxyCall_0_1(DBusGProxy* proxy,
+ const char* method,
+ GError** error,
+ GHashTable** out1) = 0;
+
+ virtual gboolean ProxyCall_3_0(DBusGProxy* proxy,
+ const char* method,
+ GError** error,
+ const char* in1,
+ const char* in2,
+ const char* in3) = 0;
+
+ // Wraps dbus_g_connection_get_connection().
+ virtual DBusConnection* ConnectionGetConnection(DBusGConnection* gbus) = 0;
+
+ // Wraps dbus_bus_add_match().
+ virtual void DBusBusAddMatch(DBusConnection* connection,
+ const char* rule,
+ DBusError* error) = 0;
+
+ // Wraps dbus_connection_add_filter().
+ virtual dbus_bool_t DBusConnectionAddFilter(
+ DBusConnection* connection,
+ DBusHandleMessageFunction function,
+ void* user_data,
+ DBusFreeFunction free_data_function) = 0;
+
+ // Wraps dbus_connection_remove_filter().
+ virtual void DBusConnectionRemoveFilter(DBusConnection* connection,
+ DBusHandleMessageFunction function,
+ void* user_data) = 0;
+
+ // Wraps dbus_message_is_signal().
+ virtual dbus_bool_t DBusMessageIsSignal(DBusMessage* message,
+ const char* interface,
+ const char* signal_name) = 0;
+
+ // Wraps dbus_message_get_args(). Deploys the same approach for handling
+ // variadic arguments as ProxyCall above.
+ virtual dbus_bool_t DBusMessageGetArgs_3(DBusMessage* message,
+ DBusError* error,
+ char** out1,
+ char** out2,
+ char** out3) = 0;
+};
+
+} // namespace chromeos_update_engine
+
+#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_DBUS_WRAPPER_H_