David Rochberg | b8b89b1 | 2012-02-28 16:11:33 -0500 | [diff] [blame] | 1 | // Copyright (c) 2012 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 | #include "shill/dbus_objectmanager_proxy.h" |
| 5 | |
| 6 | #include <base/logging.h> |
| 7 | |
| 8 | #include "cellular_error.h" |
| 9 | |
| 10 | using std::string; |
| 11 | |
| 12 | namespace shill { |
| 13 | |
| 14 | DBusObjectManagerProxy::DBusObjectManagerProxy( |
David Rochberg | b8b89b1 | 2012-02-28 16:11:33 -0500 | [diff] [blame] | 15 | DBus::Connection *connection, |
| 16 | const string &path, |
| 17 | const string &service) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 18 | : proxy_(connection, path, service) {} |
David Rochberg | b8b89b1 | 2012-02-28 16:11:33 -0500 | [diff] [blame] | 19 | DBusObjectManagerProxy::~DBusObjectManagerProxy() {} |
| 20 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 21 | void DBusObjectManagerProxy::GetManagedObjects( |
| 22 | Error *error, |
| 23 | const ManagedObjectsCallback &callback, |
| 24 | int timeout) { |
| 25 | scoped_ptr<ManagedObjectsCallback> cb(new ManagedObjectsCallback(callback)); |
| 26 | try { |
| 27 | proxy_.GetManagedObjects(cb.get(), timeout); |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 28 | cb.release(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 29 | } catch (DBus::Error e) { |
| 30 | if (error) |
| 31 | CellularError::FromDBusError(e, error); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | void DBusObjectManagerProxy::set_interfaces_added_callback( |
| 36 | const InterfacesAddedSignalCallback &callback) { |
| 37 | proxy_.set_interfaces_added_callback(callback); |
| 38 | } |
| 39 | |
| 40 | void DBusObjectManagerProxy::set_interfaces_removed_callback( |
| 41 | const InterfacesRemovedSignalCallback &callback) { |
| 42 | proxy_.set_interfaces_removed_callback(callback); |
David Rochberg | b8b89b1 | 2012-02-28 16:11:33 -0500 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | // Inherited from DBusObjectManagerProxyInterface. |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 46 | DBusObjectManagerProxy::Proxy::Proxy(DBus::Connection *connection, |
David Rochberg | b8b89b1 | 2012-02-28 16:11:33 -0500 | [diff] [blame] | 47 | const std::string &path, |
| 48 | const std::string &service) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 49 | : DBus::ObjectProxy(*connection, path, service.c_str()) {} |
David Rochberg | b8b89b1 | 2012-02-28 16:11:33 -0500 | [diff] [blame] | 50 | |
| 51 | DBusObjectManagerProxy::Proxy::~Proxy() {} |
| 52 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 53 | void DBusObjectManagerProxy::Proxy::set_interfaces_added_callback( |
| 54 | const InterfacesAddedSignalCallback &callback) { |
| 55 | interfaces_added_callback_ = callback; |
| 56 | } |
| 57 | |
| 58 | void DBusObjectManagerProxy::Proxy::set_interfaces_removed_callback( |
| 59 | const InterfacesRemovedSignalCallback &callback) { |
| 60 | interfaces_removed_callback_ = callback; |
| 61 | } |
| 62 | |
David Rochberg | b8b89b1 | 2012-02-28 16:11:33 -0500 | [diff] [blame] | 63 | // Signal callback |
| 64 | void DBusObjectManagerProxy::Proxy::InterfacesAdded( |
| 65 | const ::DBus::Path &object_path, |
| 66 | const DBusInterfaceToProperties &interface_to_properties) { |
| 67 | VLOG(2) << __func__ << "(" << object_path << ")"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 68 | interfaces_added_callback_.Run(object_path, interface_to_properties); |
David Rochberg | b8b89b1 | 2012-02-28 16:11:33 -0500 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | // Signal callback |
| 72 | void DBusObjectManagerProxy::Proxy::InterfacesRemoved( |
| 73 | const ::DBus::Path &object_path, |
| 74 | const std::vector< std::string > &interfaces) { |
| 75 | VLOG(2) << __func__ << "(" << object_path << ")"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 76 | interfaces_removed_callback_.Run(object_path, interfaces); |
David Rochberg | b8b89b1 | 2012-02-28 16:11:33 -0500 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | // Method callback |
| 80 | void DBusObjectManagerProxy::Proxy::GetManagedObjectsCallback( |
| 81 | const DBusObjectsWithProperties &objects_with_properties, |
| 82 | const DBus::Error &dberror, |
| 83 | void *data) { |
| 84 | VLOG(2) << __func__; |
| 85 | shill::Error error; |
| 86 | CellularError::FromDBusError(dberror, &error); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 87 | scoped_ptr<ManagedObjectsCallback> callback( |
| 88 | reinterpret_cast<ManagedObjectsCallback *>(data)); |
David Rochberg | b8b89b1 | 2012-02-28 16:11:33 -0500 | [diff] [blame] | 89 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 90 | callback->Run(objects_with_properties, error); |
David Rochberg | b8b89b1 | 2012-02-28 16:11:33 -0500 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | } // namespace shill |