Add semi-generated glue for dbus_objectmanager interface
BUG=chromium-os:26650
TEST=unit tests pass. no tests for glue code (matching dbus_properties glue code)
Change-Id: Idd31c4225a488a84b09b6bf28e44842281104d59
Reviewed-on: https://gerrit.chromium.org/gerrit/16998
Commit-Ready: David Rochberg <rochberg@chromium.org>
Reviewed-by: David Rochberg <rochberg@chromium.org>
Tested-by: David Rochberg <rochberg@chromium.org>
diff --git a/Makefile b/Makefile
index 1a11252..487b1cd 100644
--- a/Makefile
+++ b/Makefile
@@ -108,6 +108,7 @@
crypto_rot47.o \
dbus_adaptor.o \
dbus_control.o \
+ dbus_objectmanager_proxy.o \
dbus_properties.o \
dbus_properties_proxy.o \
default_profile.o \
diff --git a/dbus_objectmanager_proxy.cc b/dbus_objectmanager_proxy.cc
new file mode 100644
index 0000000..5f83e49
--- /dev/null
+++ b/dbus_objectmanager_proxy.cc
@@ -0,0 +1,71 @@
+// Copyright (c) 2012 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.
+#include "shill/dbus_objectmanager_proxy.h"
+
+#include <base/logging.h>
+
+#include "cellular_error.h"
+
+using std::string;
+
+namespace shill {
+
+DBusObjectManagerProxy::DBusObjectManagerProxy(
+ DBusObjectManagerProxyDelegate *delegate,
+ DBus::Connection *connection,
+ const string &path,
+ const string &service)
+ : proxy_(delegate, connection, path, service) {}
+
+DBusObjectManagerProxy::~DBusObjectManagerProxy() {}
+
+void DBusObjectManagerProxy::GetManagedObjects(AsyncCallHandler *call_handler,
+ int timeout) {
+ return proxy_.GetManagedObjects(call_handler, timeout);
+}
+
+// Inherited from DBusObjectManagerProxyInterface.
+DBusObjectManagerProxy::Proxy::Proxy(DBusObjectManagerProxyDelegate *delegate,
+ DBus::Connection *connection,
+ const std::string &path,
+ const std::string &service)
+ : DBus::ObjectProxy(*connection, path, service.c_str()),
+ delegate_(delegate) {}
+
+
+DBusObjectManagerProxy::Proxy::~Proxy() {}
+
+// Signal callback
+void DBusObjectManagerProxy::Proxy::InterfacesAdded(
+ const ::DBus::Path &object_path,
+ const DBusInterfaceToProperties &interface_to_properties) {
+ VLOG(2) << __func__ << "(" << object_path << ")";
+ delegate_->OnInterfacesAdded(object_path, interface_to_properties);
+}
+
+// Signal callback
+void DBusObjectManagerProxy::Proxy::InterfacesRemoved(
+ const ::DBus::Path &object_path,
+ const std::vector< std::string > &interfaces) {
+ VLOG(2) << __func__ << "(" << object_path << ")";
+ delegate_->OnInterfacesRemoved(object_path, interfaces);
+}
+
+// Method callback
+void DBusObjectManagerProxy::Proxy::GetManagedObjectsCallback(
+ const DBusObjectsWithProperties &objects_with_properties,
+ const DBus::Error &dberror,
+ void *data) {
+ VLOG(2) << __func__;
+ shill::Error error;
+ CellularError::FromDBusError(dberror, &error);
+ AsyncCallHandler *call_handler = reinterpret_cast<AsyncCallHandler *>(data);
+
+ delegate_->OnGetManagedObjectsCallback(
+ objects_with_properties,
+ error,
+ call_handler);
+}
+
+} // namespace shill
diff --git a/dbus_objectmanager_proxy.h b/dbus_objectmanager_proxy.h
new file mode 100644
index 0000000..d3324db
--- /dev/null
+++ b/dbus_objectmanager_proxy.h
@@ -0,0 +1,64 @@
+
+// Copyright (c) 2012 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 SHILL_DBUS_OBJECTMANAGER_PROXY_H_
+#define SHILL_DBUS_OBJECTMANAGER_PROXY_H_
+#include <string>
+
+#include "shill/dbus_objectmanager_proxy_interface.h"
+#include "shill/dbus_bindings/dbus-objectmanager.h"
+
+namespace shill {
+
+class DBusObjectManagerProxy : public DBusObjectManagerProxyInterface {
+ public:
+ // Constructs a org.freedesktop.DBus.ObjectManager DBus object proxy
+ // at |path| owned by |service|. Caught signals and asynchronous
+ // method replies will be dispatched to |delegate|.
+
+ DBusObjectManagerProxy(DBusObjectManagerProxyDelegate *delegate,
+ DBus::Connection *connection,
+ const std::string &path,
+ const std::string &service);
+ virtual ~DBusObjectManagerProxy();
+
+ // Inherited methods from DBusObjectManagerProxyInterface.
+ virtual void GetManagedObjects(AsyncCallHandler *call_handler, int timeout);
+
+ private:
+ class Proxy : public org::freedesktop::DBus::ObjectManager_proxy,
+ public DBus::ObjectProxy {
+ public:
+ Proxy(DBusObjectManagerProxyDelegate *delegate,
+ DBus::Connection *connection,
+ const std::string &path,
+ const std::string &service);
+ virtual ~Proxy();
+
+ private:
+ // Signal callbacks
+ virtual void InterfacesAdded(
+ const ::DBus::Path &object_path,
+ const DBusInterfaceToProperties &interfaces_and_properties);
+ virtual void InterfacesRemoved(const ::DBus::Path &object_path,
+ const std::vector<std::string> &interfaces);
+
+ // Method callbacks
+ virtual void GetManagedObjectsCallback(
+ const DBusObjectsWithProperties &objects_with_properties,
+ const DBus::Error &error,
+ void *call_handler);
+
+ DBusObjectManagerProxyDelegate *delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(Proxy);
+ };
+ Proxy proxy_;
+
+ DISALLOW_COPY_AND_ASSIGN(DBusObjectManagerProxy);
+};
+
+} // namespace shill
+
+#endif // SHILL_DBUS_OBJECTMANAGER_PROXY_H_
diff --git a/dbus_objectmanager_proxy_interface.h b/dbus_objectmanager_proxy_interface.h
new file mode 100644
index 0000000..7584f2e
--- /dev/null
+++ b/dbus_objectmanager_proxy_interface.h
@@ -0,0 +1,55 @@
+// Copyright (c) 2012 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 SHILL_DBUS_OBJECTMANAGER_INTERFACE_H_
+#define SHILL_DBUS_OBJECTMANAGER_INTERFACE_H_
+#include <string>
+
+#include <base/basictypes.h>
+
+#include "shill/dbus_properties.h" // For DBusPropertiesMap
+
+namespace shill {
+
+class AsyncCallHandler;
+class Error;
+
+typedef std::map<std::string, DBusPropertiesMap> DBusInterfaceToProperties;
+typedef
+ std::map< ::DBus::Path, DBusInterfaceToProperties> DBusObjectsWithProperties;
+
+// These are the methods that a org.freedesktop.DBus.ObjectManager
+// proxy must support. The interface is provided so that it can be
+// mocked in tests. All calls are made asynchronously. Call
+// completion is signalled through the corresponding 'OnXXXCallback'
+// method in the ProxyDelegate interface.
+
+class DBusObjectManagerProxyInterface {
+ public:
+ virtual ~DBusObjectManagerProxyInterface() {}
+ virtual void GetManagedObjects(
+ AsyncCallHandler *call_handler, int timeout) = 0;
+};
+
+class DBusObjectManagerProxyDelegate {
+ public:
+ virtual ~DBusObjectManagerProxyDelegate() {}
+
+ // Signals
+ virtual void OnInterfacesAdded(
+ const ::DBus::Path &object_path,
+ const DBusInterfaceToProperties &interface_to_properties) = 0;
+ virtual void OnInterfacesRemoved(
+ const ::DBus::Path &object_path,
+ const std::vector<std::string> &interfaces) = 0;
+
+ // Async method callbacks
+ virtual void OnGetManagedObjectsCallback(
+ const DBusObjectsWithProperties &objects_with_properties,
+ const shill::Error &error,
+ AsyncCallHandler *call_handler) = 0;
+};
+
+} // namespace shill
+
+#endif // SHILL_DBUS_OBJECTMANAGER_INTERFACE_H_