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/SConstruct b/SConstruct
index 666fced..ed8f6e3 100644
--- a/SConstruct
+++ b/SConstruct
@@ -247,9 +247,9 @@
postinstall_runner_action.cc
prefs.cc
proxy_resolver.cc
+ real_system_state.cc
simple_key_value_store.cc
subprocess.cc
- system_state.cc
tarjan.cc
terminator.cc
topological_sort.cc
diff --git a/chrome_browser_proxy_resolver.cc b/chrome_browser_proxy_resolver.cc
index 3841fe9..e5e2fff 100644
--- a/chrome_browser_proxy_resolver.cc
+++ b/chrome_browser_proxy_resolver.cc
@@ -50,7 +50,8 @@
} // namespace {}
-ChromeBrowserProxyResolver::ChromeBrowserProxyResolver(DbusGlibInterface* dbus)
+ChromeBrowserProxyResolver::ChromeBrowserProxyResolver(
+ DBusWrapperInterface* dbus)
: dbus_(dbus), proxy_(NULL), timeout_(kTimeout) {}
bool ChromeBrowserProxyResolver::Init() {
@@ -66,10 +67,10 @@
DBusError dbus_error;
dbus_error_init(&dbus_error);
- dbus_->DbusBusAddMatch(connection, kLibCrosProxyResolveSignalFilter,
+ dbus_->DBusBusAddMatch(connection, kLibCrosProxyResolveSignalFilter,
&dbus_error);
TEST_AND_RETURN_FALSE(!dbus_error_is_set(&dbus_error));
- TEST_AND_RETURN_FALSE(dbus_->DbusConnectionAddFilter(
+ TEST_AND_RETURN_FALSE(dbus_->DBusConnectionAddFilter(
connection,
&ChromeBrowserProxyResolver::StaticFilterMessage,
this,
@@ -78,7 +79,7 @@
proxy_ = dbus_->ProxyNewForName(bus, kLibCrosServiceName, kLibCrosServicePath,
kLibCrosServiceInterface);
if (!proxy_) {
- dbus_->DbusConnectionRemoveFilter(
+ dbus_->DBusConnectionRemoveFilter(
connection,
&ChromeBrowserProxyResolver::StaticFilterMessage,
this);
@@ -94,7 +95,7 @@
DBusGConnection* gbus = dbus_->BusGet(DBUS_BUS_SYSTEM, &gerror);
if (gbus) {
DBusConnection* connection = dbus_->ConnectionGetConnection(gbus);
- dbus_->DbusConnectionRemoveFilter(
+ dbus_->DBusConnectionRemoveFilter(
connection,
&ChromeBrowserProxyResolver::StaticFilterMessage,
this);
@@ -152,7 +153,7 @@
DBusConnection* connection,
DBusMessage* message) {
// Code lifted from libcros.
- if (!dbus_->DbusMessageIsSignal(message,
+ if (!dbus_->DBusMessageIsSignal(message,
kLibCrosProxyResolveSignalInterface,
kLibCrosProxyResolveName)) {
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
@@ -163,7 +164,7 @@
char* error = NULL;
DBusError arg_error;
dbus_error_init(&arg_error);
- if (!dbus_->DbusMessageGetArgs_3(message, &arg_error,
+ if (!dbus_->DBusMessageGetArgs_3(message, &arg_error,
&source_url,
&proxy_list,
&error)) {
diff --git a/chrome_browser_proxy_resolver.h b/chrome_browser_proxy_resolver.h
index 61f5982..1783aef 100644
--- a/chrome_browser_proxy_resolver.h
+++ b/chrome_browser_proxy_resolver.h
@@ -12,7 +12,7 @@
#include <dbus/dbus-glib-lowlevel.h>
#include <gtest/gtest_prod.h> // for FRIEND_TEST
-#include "update_engine/dbus_interface.h"
+#include "update_engine/dbus_wrapper_interface.h"
#include "update_engine/proxy_resolver.h"
namespace chromeos_update_engine {
@@ -27,7 +27,7 @@
class ChromeBrowserProxyResolver : public ProxyResolver {
public:
- explicit ChromeBrowserProxyResolver(DbusGlibInterface* dbus);
+ explicit ChromeBrowserProxyResolver(DBusWrapperInterface* dbus);
virtual ~ChromeBrowserProxyResolver();
bool Init();
@@ -75,7 +75,7 @@
// Shutdown the dbus proxy object.
void Shutdown();
- DbusGlibInterface* dbus_;
+ DBusWrapperInterface* dbus_;
DBusGProxy* proxy_;
DBusGProxy* peer_proxy_;
int timeout_;
diff --git a/chrome_browser_proxy_resolver_unittest.cc b/chrome_browser_proxy_resolver_unittest.cc
index 8ae1a51..628524b 100644
--- a/chrome_browser_proxy_resolver_unittest.cc
+++ b/chrome_browser_proxy_resolver_unittest.cc
@@ -8,7 +8,7 @@
#include <gtest/gtest.h>
#include "update_engine/chrome_browser_proxy_resolver.h"
-#include "update_engine/mock_dbus_interface.h"
+#include "update_engine/mock_dbus_wrapper.h"
using std::deque;
using std::string;
@@ -77,15 +77,15 @@
}
namespace {
-void DbusInterfaceTestResolved(const std::deque<std::string>& proxies,
- void* data) {
+void DBusWrapperTestResolved(const std::deque<std::string>& proxies,
+ void* data) {
EXPECT_EQ(2, proxies.size());
EXPECT_EQ("socks5://192.168.52.83:5555", proxies[0]);
EXPECT_EQ(kNoProxy, proxies[1]);
g_main_loop_quit(reinterpret_cast<GMainLoop*>(data));
}
-void DbusInterfaceTestResolvedNoReply(const std::deque<std::string>& proxies,
- void* data) {
+void DBusWrapperTestResolvedNoReply(const std::deque<std::string>& proxies,
+ void* data) {
EXPECT_EQ(1, proxies.size());
EXPECT_EQ(kNoProxy, proxies[0]);
g_main_loop_quit(reinterpret_cast<GMainLoop*>(data));
@@ -121,7 +121,7 @@
const char kUrl[] = "http://example.com/blah";
- MockDbusGlib dbus_iface;
+ MockDBusWrapper dbus_iface;
EXPECT_CALL(dbus_iface, BusGet(_, _))
.Times(2)
@@ -130,9 +130,9 @@
ConnectionGetConnection(kMockSystemGBus))
.Times(2)
.WillRepeatedly(Return(kMockSystemBus));
- EXPECT_CALL(dbus_iface, DbusBusAddMatch(kMockSystemBus, _, _));
+ EXPECT_CALL(dbus_iface, DBusBusAddMatch(kMockSystemBus, _, _));
EXPECT_CALL(dbus_iface,
- DbusConnectionAddFilter(kMockSystemBus, _, _, _))
+ DBusConnectionAddFilter(kMockSystemBus, _, _, _))
.WillOnce(Return(1));
EXPECT_CALL(dbus_iface,
ProxyNewForName(kMockSystemGBus,
@@ -150,15 +150,15 @@
StrEq(kLibCrosProxyResolveName)))
.WillOnce(Return(chrome_alive ? TRUE : FALSE));
EXPECT_CALL(dbus_iface,
- DbusConnectionRemoveFilter(kMockSystemBus, _, _));
+ DBusConnectionRemoveFilter(kMockSystemBus, _, _));
if (chrome_replies) {
EXPECT_CALL(dbus_iface,
- DbusMessageIsSignal(kMockDbusMessage,
+ DBusMessageIsSignal(kMockDbusMessage,
kLibCrosProxyResolveSignalInterface,
kLibCrosProxyResolveName))
.WillOnce(Return(1));
EXPECT_CALL(dbus_iface,
- DbusMessageGetArgs_3(kMockDbusMessage, _, _, _, _))
+ DBusMessageGetArgs_3(kMockDbusMessage, _, _, _, _))
.WillOnce(DoAll(SetArgumentPointee<2>(strdup(kUrl)),
SetArgumentPointee<3>(
strdup("SOCKS5 192.168.52.83:5555;DIRECT")),
@@ -179,8 +179,8 @@
g_idle_add(SendReply, &args);
EXPECT_TRUE(resolver.GetProxiesForUrl(kUrl,
chrome_replies ?
- &DbusInterfaceTestResolved :
- &DbusInterfaceTestResolvedNoReply,
+ &DBusWrapperTestResolved :
+ &DBusWrapperTestResolvedNoReply,
loop));
g_main_loop_run(loop);
g_main_loop_unref(loop);
diff --git a/connection_manager.cc b/connection_manager.cc
index 1b436dc..97bc1bd 100644
--- a/connection_manager.cc
+++ b/connection_manager.cc
@@ -24,7 +24,7 @@
namespace {
// Gets the DbusGProxy for FlimFlam. Must be free'd with ProxyUnref()
-bool GetFlimFlamProxy(DbusGlibInterface* dbus_iface,
+bool GetFlimFlamProxy(DBusWrapperInterface* dbus_iface,
const char* path,
const char* interface,
DBusGProxy** out_proxy) {
@@ -45,7 +45,7 @@
// On success, caller owns the GHashTable at out_hash_table.
// Returns true on success.
-bool GetProperties(DbusGlibInterface* dbus_iface,
+bool GetProperties(DBusWrapperInterface* dbus_iface,
const char* path,
const char* interface,
GHashTable** out_hash_table) {
@@ -73,7 +73,7 @@
// Returns (via out_path) the default network path, or empty string if
// there's no network up.
// Returns true on success.
-bool GetDefaultServicePath(DbusGlibInterface* dbus_iface, string* out_path) {
+bool GetDefaultServicePath(DBusWrapperInterface* dbus_iface, string* out_path) {
GHashTable* hash_table = NULL;
TEST_AND_RETURN_FALSE(GetProperties(dbus_iface,
@@ -111,7 +111,7 @@
return kNetUnknown;
}
-bool GetServicePathType(DbusGlibInterface* dbus_iface,
+bool GetServicePathType(DBusWrapperInterface* dbus_iface,
const string& path,
NetworkConnectionType* out_type) {
GHashTable* hash_table = NULL;
@@ -228,7 +228,7 @@
}
bool ConnectionManager::GetConnectionType(
- DbusGlibInterface* dbus_iface,
+ DBusWrapperInterface* dbus_iface,
NetworkConnectionType* out_type) const {
string default_service_path;
TEST_AND_RETURN_FALSE(GetDefaultServicePath(dbus_iface,
diff --git a/connection_manager.h b/connection_manager.h
index 6cc279e..58307ff 100644
--- a/connection_manager.h
+++ b/connection_manager.h
@@ -7,7 +7,7 @@
#include <base/basictypes.h>
-#include "update_engine/dbus_interface.h"
+#include "update_engine/dbus_wrapper_interface.h"
namespace chromeos_update_engine {
@@ -34,7 +34,7 @@
// Populates |out_type| with the type of the network connection
// that we are currently connected. The dbus_iface is used to
// query the real connection manager (e.g shill).
- virtual bool GetConnectionType(DbusGlibInterface* dbus_iface,
+ virtual bool GetConnectionType(DBusWrapperInterface* dbus_iface,
NetworkConnectionType* out_type) const;
// Returns true if we're allowed to update the system when we're
diff --git a/connection_manager_unittest.cc b/connection_manager_unittest.cc
index b8e8531..3c89cb6 100644
--- a/connection_manager_unittest.cc
+++ b/connection_manager_unittest.cc
@@ -8,7 +8,7 @@
#include <string>
#include "update_engine/connection_manager.h"
-#include "update_engine/mock_dbus_interface.h"
+#include "update_engine/mock_dbus_wrapper.h"
#include "update_engine/mock_system_state.h"
using std::set;
@@ -50,7 +50,7 @@
DBusGProxy* kMockFlimFlamServiceProxy_;
DBusGConnection* kMockSystemBus_;
const char* kServicePath_;
- MockDbusGlib dbus_iface_;
+ MockDBusWrapper dbus_iface_;
ConnectionManager cmut_; // ConnectionManager under test.
MockSystemState mock_system_state_;
};
diff --git a/dbus_interface.h b/dbus_interface.h
deleted file mode 100644
index 8a4b037..0000000
--- a/dbus_interface.h
+++ /dev/null
@@ -1,181 +0,0 @@
-// 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_INTERFACE_H__
-#define CHROMEOS_PLATFORM_UPDATE_ENGINE_DBUS_INTERFACE_H__
-
-// A mockable interface for DBus.
-
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.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 DbusGlibInterface {
- 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;
-};
-
-
-class ConcreteDbusGlib : public DbusGlibInterface {
- virtual DBusGProxy* ProxyNewForName(DBusGConnection* connection,
- const char* name,
- const char* path,
- const char* interface) {
- return dbus_g_proxy_new_for_name(connection,
- name,
- path,
- interface);
- }
-
- virtual void ProxyUnref(DBusGProxy* proxy) {
- g_object_unref(proxy);
- }
-
- virtual DBusGConnection* BusGet(DBusBusType type, GError** error) {
- return dbus_g_bus_get(type, error);
- }
-
- virtual gboolean ProxyCall_0_1(DBusGProxy* proxy,
- const char* method,
- GError** error,
- GHashTable** out1) {
- return dbus_g_proxy_call(proxy, method, error, G_TYPE_INVALID,
- dbus_g_type_get_map("GHashTable",
- G_TYPE_STRING,
- G_TYPE_VALUE),
- out1, G_TYPE_INVALID);
- }
-
- virtual gboolean ProxyCall_3_0(DBusGProxy* proxy,
- const char* method,
- GError** error,
- const char* in1,
- const char* in2,
- const char* in3) {
- return dbus_g_proxy_call(
- proxy, method, error,
- G_TYPE_STRING, in1, G_TYPE_STRING, in2, G_TYPE_STRING, in3,
- G_TYPE_INVALID, G_TYPE_INVALID);
- }
-
- virtual DBusConnection* ConnectionGetConnection(DBusGConnection* gbus) {
- return dbus_g_connection_get_connection(gbus);
- }
-
- virtual void DbusBusAddMatch(DBusConnection* connection,
- const char* rule,
- DBusError* error) {
- dbus_bus_add_match(connection, rule, error);
- }
-
- virtual dbus_bool_t DbusConnectionAddFilter(
- DBusConnection* connection,
- DBusHandleMessageFunction function,
- void* user_data,
- DBusFreeFunction free_data_function) {
- return dbus_connection_add_filter(connection,
- function,
- user_data,
- free_data_function);
- }
-
- virtual void DbusConnectionRemoveFilter(DBusConnection* connection,
- DBusHandleMessageFunction function,
- void* user_data) {
- dbus_connection_remove_filter(connection, function, user_data);
- }
-
- dbus_bool_t DbusMessageIsSignal(DBusMessage* message,
- const char* interface,
- const char* signal_name) {
- return dbus_message_is_signal(message, interface, signal_name);
- }
-
- virtual dbus_bool_t DbusMessageGetArgs_3(DBusMessage* message,
- DBusError* error,
- char** out1,
- char** out2,
- char** out3) {
- return dbus_message_get_args(message, error,
- DBUS_TYPE_STRING, out1,
- DBUS_TYPE_STRING, out2,
- DBUS_TYPE_STRING, out3,
- G_TYPE_INVALID);
- }
-};
-
-} // namespace chromeos_update_engine
-
-#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_DBUS_INTERFACE_H__
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_
diff --git a/libcurl_http_fetcher.cc b/libcurl_http_fetcher.cc
index b5c67e0..41927ca 100644
--- a/libcurl_http_fetcher.cc
+++ b/libcurl_http_fetcher.cc
@@ -12,8 +12,8 @@
#include <base/stringprintf.h>
#include "update_engine/certificate_checker.h"
-#include "update_engine/dbus_interface.h"
#include "update_engine/hardware_interface.h"
+#include "update_engine/real_dbus_wrapper.h"
#include "update_engine/utils.h"
using google::protobuf::NewCallback;
@@ -40,7 +40,7 @@
// On error, returns false.
bool LibcurlHttpFetcher::IsUpdateAllowedOverCurrentConnection() const {
NetworkConnectionType type;
- ConcreteDbusGlib dbus_iface;
+ RealDBusWrapper dbus_iface;
ConnectionManager* connection_manager = system_state_->connection_manager();
if (!connection_manager->GetConnectionType(&dbus_iface, &type)) {
LOG(INFO) << "We could not determine our connection type. "
diff --git a/main.cc b/main.cc
index 345d6e1..9098063 100644
--- a/main.cc
+++ b/main.cc
@@ -19,8 +19,8 @@
#include "update_engine/certificate_checker.h"
#include "update_engine/dbus_constants.h"
-#include "update_engine/dbus_interface.h"
#include "update_engine/dbus_service.h"
+#include "update_engine/dbus_wrapper_interface.h"
#include "update_engine/real_system_state.h"
#include "update_engine/subprocess.h"
#include "update_engine/terminator.h"
diff --git a/mock_connection_manager.h b/mock_connection_manager.h
index 522e1f6..c74d6ad 100644
--- a/mock_connection_manager.h
+++ b/mock_connection_manager.h
@@ -19,7 +19,7 @@
MockConnectionManager(SystemState* system_state)
: ConnectionManager(system_state) {}
- MOCK_CONST_METHOD2(GetConnectionType, bool(DbusGlibInterface* dbus_iface,
+ MOCK_CONST_METHOD2(GetConnectionType, bool(DBusWrapperInterface* dbus_iface,
NetworkConnectionType* out_type));
MOCK_CONST_METHOD1(IsUpdateAllowedOver, bool(NetworkConnectionType type));
diff --git a/mock_dbus_interface.h b/mock_dbus_wrapper.h
similarity index 78%
rename from mock_dbus_interface.h
rename to mock_dbus_wrapper.h
index 02a4bfc..9fc9a8f 100644
--- a/mock_dbus_interface.h
+++ b/mock_dbus_wrapper.h
@@ -2,16 +2,16 @@
// 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_MOCK_DBUS_INTERFACE_H__
-#define CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_DBUS_INTERFACE_H__
+#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_DBUS_WRAPPER_H_
+#define CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_DBUS_WRAPPER_H_
#include <gmock/gmock.h>
-#include "update_engine/dbus_interface.h"
+#include "update_engine/dbus_wrapper_interface.h"
namespace chromeos_update_engine {
-class MockDbusGlib : public DbusGlibInterface {
+class MockDBusWrapper : public DBusWrapperInterface {
public:
MOCK_METHOD4(ProxyNewForName, DBusGProxy*(DBusGConnection *connection,
const char *name,
@@ -35,26 +35,26 @@
MOCK_METHOD1(ConnectionGetConnection, DBusConnection*(DBusGConnection* gbus));
- MOCK_METHOD3(DbusBusAddMatch, void(DBusConnection* connection,
+ MOCK_METHOD3(DBusBusAddMatch, void(DBusConnection* connection,
const char* rule,
DBusError* error));
- MOCK_METHOD4(DbusConnectionAddFilter, dbus_bool_t(
+ MOCK_METHOD4(DBusConnectionAddFilter, dbus_bool_t(
DBusConnection* connection,
DBusHandleMessageFunction function,
void* user_data,
DBusFreeFunction free_data_function));
- MOCK_METHOD3(DbusConnectionRemoveFilter, void(
+ MOCK_METHOD3(DBusConnectionRemoveFilter, void(
DBusConnection* connection,
DBusHandleMessageFunction function,
void* user_data));
- MOCK_METHOD3(DbusMessageIsSignal, dbus_bool_t(DBusMessage* message,
+ MOCK_METHOD3(DBusMessageIsSignal, dbus_bool_t(DBusMessage* message,
const char* interface,
const char* signal_name));
- MOCK_METHOD5(DbusMessageGetArgs_3, dbus_bool_t(DBusMessage* message,
+ MOCK_METHOD5(DBusMessageGetArgs_3, dbus_bool_t(DBusMessage* message,
DBusError* error,
char** out1,
char** out2,
@@ -63,4 +63,4 @@
} // namespace chromeos_update_engine
-#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_DBUS_INTERFACE_H__
+#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_DBUS_WRAPPER_H_
diff --git a/mock_system_state.h b/mock_system_state.h
index e1dc4cc..a6e764f 100644
--- a/mock_system_state.h
+++ b/mock_system_state.h
@@ -10,7 +10,7 @@
#include <metrics/metrics_library_mock.h>
#include <policy/mock_device_policy.h>
-#include "update_engine/mock_dbus_interface.h"
+#include "update_engine/mock_dbus_wrapper.h"
#include "update_engine/mock_gpio_handler.h"
#include "update_engine/mock_p2p_manager.h"
#include "update_engine/mock_payload_state.h"
@@ -141,7 +141,7 @@
testing::NiceMock<MockPayloadState> mock_payload_state_;
testing::NiceMock<MockGpioHandler>* mock_gpio_handler_;
testing::NiceMock<UpdateAttempterMock>* mock_update_attempter_;
- MockDbusGlib dbus_;
+ MockDBusWrapper dbus_;
// These are the other object we own.
Clock default_clock_;
diff --git a/real_dbus_wrapper.h b/real_dbus_wrapper.h
new file mode 100644
index 0000000..ab7a969
--- /dev/null
+++ b/real_dbus_wrapper.h
@@ -0,0 +1,107 @@
+// 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_REAL_DBUS_WRAPPER_H_
+#define CHROMEOS_PLATFORM_UPDATE_ENGINE_REAL_DBUS_WRAPPER_H_
+
+// A mockable interface for DBus.
+
+#include <dbus/dbus-glib-lowlevel.h>
+#include <dbus/dbus-glib.h>
+
+#include "update_engine/dbus_wrapper_interface.h"
+
+namespace chromeos_update_engine {
+
+class RealDBusWrapper : public DBusWrapperInterface {
+ virtual DBusGProxy* ProxyNewForName(DBusGConnection* connection,
+ const char* name,
+ const char* path,
+ const char* interface) {
+ return dbus_g_proxy_new_for_name(connection,
+ name,
+ path,
+ interface);
+ }
+
+ virtual void ProxyUnref(DBusGProxy* proxy) {
+ g_object_unref(proxy);
+ }
+
+ virtual DBusGConnection* BusGet(DBusBusType type, GError** error) {
+ return dbus_g_bus_get(type, error);
+ }
+
+ virtual gboolean ProxyCall_0_1(DBusGProxy* proxy,
+ const char* method,
+ GError** error,
+ GHashTable** out1) {
+ return dbus_g_proxy_call(proxy, method, error, G_TYPE_INVALID,
+ dbus_g_type_get_map("GHashTable",
+ G_TYPE_STRING,
+ G_TYPE_VALUE),
+ out1, G_TYPE_INVALID);
+ }
+
+ virtual gboolean ProxyCall_3_0(DBusGProxy* proxy,
+ const char* method,
+ GError** error,
+ const char* in1,
+ const char* in2,
+ const char* in3) {
+ return dbus_g_proxy_call(
+ proxy, method, error,
+ G_TYPE_STRING, in1, G_TYPE_STRING, in2, G_TYPE_STRING, in3,
+ G_TYPE_INVALID, G_TYPE_INVALID);
+ }
+
+ virtual DBusConnection* ConnectionGetConnection(DBusGConnection* gbus) {
+ return dbus_g_connection_get_connection(gbus);
+ }
+
+ virtual void DBusBusAddMatch(DBusConnection* connection,
+ const char* rule,
+ DBusError* error) {
+ dbus_bus_add_match(connection, rule, error);
+ }
+
+ virtual dbus_bool_t DBusConnectionAddFilter(
+ DBusConnection* connection,
+ DBusHandleMessageFunction function,
+ void* user_data,
+ DBusFreeFunction free_data_function) {
+ return dbus_connection_add_filter(connection,
+ function,
+ user_data,
+ free_data_function);
+ }
+
+ virtual void DBusConnectionRemoveFilter(DBusConnection* connection,
+ DBusHandleMessageFunction function,
+ void* user_data) {
+ dbus_connection_remove_filter(connection, function, user_data);
+ }
+
+ dbus_bool_t DBusMessageIsSignal(DBusMessage* message,
+ const char* interface,
+ const char* signal_name) {
+ return dbus_message_is_signal(message, interface, signal_name);
+ }
+
+ virtual dbus_bool_t DBusMessageGetArgs_3(DBusMessage* message,
+ DBusError* error,
+ char** out1,
+ char** out2,
+ char** out3) {
+ return dbus_message_get_args(message, error,
+ DBUS_TYPE_STRING, out1,
+ DBUS_TYPE_STRING, out2,
+ DBUS_TYPE_STRING, out3,
+ G_TYPE_INVALID);
+ }
+};
+
+} // namespace chromeos_update_engine
+
+#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_REAL_DBUS_WRAPPER_H_
diff --git a/system_state.cc b/real_system_state.cc
similarity index 100%
rename from system_state.cc
rename to real_system_state.cc
diff --git a/real_system_state.h b/real_system_state.h
index 4ff229d..7c411f8 100644
--- a/real_system_state.h
+++ b/real_system_state.h
@@ -5,16 +5,17 @@
#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_REAL_SYSTEM_STATE_H_
#define CHROMEOS_PLATFORM_UPDATE_ENGINE_REAL_SYSTEM_STATE_H_
-#include <update_engine/system_state.h>
+#include "update_engine/system_state.h"
-#include <update_engine/clock.h>
-#include <update_engine/connection_manager.h>
-#include <update_engine/gpio_handler.h>
-#include <update_engine/hardware.h>
-#include <update_engine/payload_state.h>
-#include <update_engine/prefs.h>
-#include <update_engine/update_attempter.h>
-#include <update_engine/p2p_manager.h>
+#include "update_engine/clock.h"
+#include "update_engine/connection_manager.h"
+#include "update_engine/gpio_handler.h"
+#include "update_engine/hardware.h"
+#include "update_engine/payload_state.h"
+#include "update_engine/prefs.h"
+#include "update_engine/real_dbus_wrapper.h"
+#include "update_engine/update_attempter.h"
+#include "update_engine/p2p_manager.h"
namespace chromeos_update_engine {
@@ -126,7 +127,7 @@
scoped_ptr<GpioHandler> gpio_handler_;
// The dbus object used to initialize the update attempter.
- ConcreteDbusGlib dbus_;
+ RealDBusWrapper dbus_;
// Pointer to the update attempter object.
scoped_ptr<UpdateAttempter> update_attempter_;
diff --git a/update_attempter.cc b/update_attempter.cc
index dcde2cf..9cb7a25 100644
--- a/update_attempter.cc
+++ b/update_attempter.cc
@@ -118,13 +118,13 @@
}
UpdateAttempter::UpdateAttempter(SystemState* system_state,
- DbusGlibInterface* dbus_iface)
+ DBusWrapperInterface* dbus_iface)
: chrome_proxy_resolver_(dbus_iface) {
Init(system_state, kUpdateCompletedMarker);
}
UpdateAttempter::UpdateAttempter(SystemState* system_state,
- DbusGlibInterface* dbus_iface,
+ DBusWrapperInterface* dbus_iface,
const std::string& update_completed_marker)
: chrome_proxy_resolver_(dbus_iface) {
Init(system_state, update_completed_marker);
diff --git a/update_attempter.h b/update_attempter.h
index d5c6adb..d93c049 100644
--- a/update_attempter.h
+++ b/update_attempter.h
@@ -60,7 +60,7 @@
static const int kMaxDeltaUpdateFailures;
UpdateAttempter(SystemState* system_state,
- DbusGlibInterface* dbus_iface);
+ DBusWrapperInterface* dbus_iface);
virtual ~UpdateAttempter();
// Checks for update and, if a newer version is available, attempts to update
@@ -193,7 +193,7 @@
// Special ctor + friend declarations for testing purposes.
UpdateAttempter(SystemState* system_state,
- DbusGlibInterface* dbus_iface,
+ DBusWrapperInterface* dbus_iface,
const std::string& update_completed_marker);
friend class UpdateAttempterUnderTest;
diff --git a/update_attempter_mock.h b/update_attempter_mock.h
index 693cc57..5b57dbc 100644
--- a/update_attempter_mock.h
+++ b/update_attempter_mock.h
@@ -7,7 +7,7 @@
#include <gmock/gmock.h>
-#include "update_engine/mock_dbus_interface.h"
+#include "update_engine/mock_dbus_wrapper.h"
#include "update_engine/mock_system_state.h"
#include "update_engine/update_attempter.h"
@@ -18,7 +18,7 @@
class UpdateAttempterMock : public UpdateAttempter {
public:
explicit UpdateAttempterMock(MockSystemState* mock_system_state,
- MockDbusGlib* dbus)
+ MockDBusWrapper* dbus)
: UpdateAttempter(mock_system_state, dbus) {}
MOCK_METHOD5(Update, void(const std::string& app_version,
diff --git a/update_attempter_unittest.cc b/update_attempter_unittest.cc
index 7031bb9..396b4a8 100644
--- a/update_attempter_unittest.cc
+++ b/update_attempter_unittest.cc
@@ -12,7 +12,7 @@
#include "update_engine/fake_clock.h"
#include "update_engine/filesystem_copier_action.h"
#include "update_engine/install_plan.h"
-#include "update_engine/mock_dbus_interface.h"
+#include "update_engine/mock_dbus_wrapper.h"
#include "update_engine/mock_http_fetcher.h"
#include "update_engine/mock_p2p_manager.h"
#include "update_engine/mock_payload_state.h"
@@ -48,11 +48,11 @@
// explicitly specified, we feed an empty string, which causes the
// UpdateAttempter class to ignore / not write the marker file.
UpdateAttempterUnderTest(MockSystemState* mock_system_state,
- MockDbusGlib* dbus)
+ MockDBusWrapper* dbus)
: UpdateAttempter(mock_system_state, dbus, "") {}
UpdateAttempterUnderTest(MockSystemState* mock_system_state,
- MockDbusGlib* dbus,
+ MockDBusWrapper* dbus,
const string& update_completed_marker)
: UpdateAttempter(mock_system_state, dbus, update_completed_marker) {}
};
@@ -148,7 +148,7 @@
static gboolean StaticP2PEnabledHousekeepingFails(gpointer data);
NiceMock<MockSystemState> mock_system_state_;
- NiceMock<MockDbusGlib> dbus_;
+ NiceMock<MockDBusWrapper> dbus_;
UpdateAttempterUnderTest attempter_;
NiceMock<ActionProcessorMock>* processor_;
NiceMock<PrefsMock>* prefs_; // shortcut to mock_system_state_->mock_prefs()
diff --git a/update_check_scheduler_unittest.cc b/update_check_scheduler_unittest.cc
index 4c9d228..b3497c4 100644
--- a/update_check_scheduler_unittest.cc
+++ b/update_check_scheduler_unittest.cc
@@ -78,7 +78,7 @@
}
MockSystemState mock_system_state_;
- MockDbusGlib dbus_;
+ MockDBusWrapper dbus_;
OpenSSLWrapperMock openssl_wrapper_;
UpdateAttempterMock attempter_;
UpdateCheckSchedulerUnderTest scheduler_;