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 | |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 6 | #include "shill/cellular_error.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 7 | #include "shill/logging.h" |
David Rochberg | b8b89b1 | 2012-02-28 16:11:33 -0500 | [diff] [blame] | 8 | |
| 9 | using std::string; |
| 10 | |
| 11 | namespace shill { |
| 12 | |
| 13 | DBusObjectManagerProxy::DBusObjectManagerProxy( |
David Rochberg | b8b89b1 | 2012-02-28 16:11:33 -0500 | [diff] [blame] | 14 | DBus::Connection *connection, |
| 15 | const string &path, |
| 16 | const string &service) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 17 | : proxy_(connection, path, service) {} |
David Rochberg | b8b89b1 | 2012-02-28 16:11:33 -0500 | [diff] [blame] | 18 | DBusObjectManagerProxy::~DBusObjectManagerProxy() {} |
| 19 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 20 | void DBusObjectManagerProxy::GetManagedObjects( |
| 21 | Error *error, |
| 22 | const ManagedObjectsCallback &callback, |
| 23 | int timeout) { |
| 24 | scoped_ptr<ManagedObjectsCallback> cb(new ManagedObjectsCallback(callback)); |
| 25 | try { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 26 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 27 | proxy_.GetManagedObjects(cb.get(), timeout); |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 28 | cb.release(); |
Ben Chan | 80326f3 | 2012-05-04 17:51:32 -0700 | [diff] [blame] | 29 | } catch (const DBus::Error &e) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 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) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 67 | SLOG(DBus, 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) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 75 | SLOG(DBus, 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) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 84 | SLOG(DBus, 2) << __func__; |
David Rochberg | b8b89b1 | 2012-02-28 16:11:33 -0500 | [diff] [blame] | 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 |