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