blob: f51061639160241117a569e1c707053dc5eec575 [file] [log] [blame]
David Rochbergb8b89b12012-02-28 16:11:33 -05001// 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 agrawal06175d72012-04-23 16:46:01 -07008#include "shill/cellular_error.h"
9#include "shill/scope_logger.h"
David Rochbergb8b89b12012-02-28 16:11:33 -050010
11using std::string;
12
13namespace shill {
14
15DBusObjectManagerProxy::DBusObjectManagerProxy(
David Rochbergb8b89b12012-02-28 16:11:33 -050016 DBus::Connection *connection,
17 const string &path,
18 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050019 : proxy_(connection, path, service) {}
David Rochbergb8b89b12012-02-28 16:11:33 -050020DBusObjectManagerProxy::~DBusObjectManagerProxy() {}
21
Eric Shienbrood9a245532012-03-07 14:20:39 -050022void DBusObjectManagerProxy::GetManagedObjects(
23 Error *error,
24 const ManagedObjectsCallback &callback,
25 int timeout) {
26 scoped_ptr<ManagedObjectsCallback> cb(new ManagedObjectsCallback(callback));
27 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070028 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050029 proxy_.GetManagedObjects(cb.get(), timeout);
David Rochbergfa1d31d2012-03-20 10:38:07 -040030 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070031 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050032 if (error)
33 CellularError::FromDBusError(e, error);
34 }
35}
36
37void DBusObjectManagerProxy::set_interfaces_added_callback(
38 const InterfacesAddedSignalCallback &callback) {
39 proxy_.set_interfaces_added_callback(callback);
40}
41
42void DBusObjectManagerProxy::set_interfaces_removed_callback(
43 const InterfacesRemovedSignalCallback &callback) {
44 proxy_.set_interfaces_removed_callback(callback);
David Rochbergb8b89b12012-02-28 16:11:33 -050045}
46
47// Inherited from DBusObjectManagerProxyInterface.
Eric Shienbrood9a245532012-03-07 14:20:39 -050048DBusObjectManagerProxy::Proxy::Proxy(DBus::Connection *connection,
David Rochbergb8b89b12012-02-28 16:11:33 -050049 const std::string &path,
50 const std::string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050051 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
David Rochbergb8b89b12012-02-28 16:11:33 -050052
53DBusObjectManagerProxy::Proxy::~Proxy() {}
54
Eric Shienbrood9a245532012-03-07 14:20:39 -050055void DBusObjectManagerProxy::Proxy::set_interfaces_added_callback(
56 const InterfacesAddedSignalCallback &callback) {
57 interfaces_added_callback_ = callback;
58}
59
60void DBusObjectManagerProxy::Proxy::set_interfaces_removed_callback(
61 const InterfacesRemovedSignalCallback &callback) {
62 interfaces_removed_callback_ = callback;
63}
64
David Rochbergb8b89b12012-02-28 16:11:33 -050065// Signal callback
66void DBusObjectManagerProxy::Proxy::InterfacesAdded(
67 const ::DBus::Path &object_path,
68 const DBusInterfaceToProperties &interface_to_properties) {
Ben Chanfad4a0b2012-04-18 15:49:59 -070069 SLOG(DBus, 2) << __func__ << "(" << object_path << ")";
Eric Shienbrood9a245532012-03-07 14:20:39 -050070 interfaces_added_callback_.Run(object_path, interface_to_properties);
David Rochbergb8b89b12012-02-28 16:11:33 -050071}
72
73// Signal callback
74void DBusObjectManagerProxy::Proxy::InterfacesRemoved(
75 const ::DBus::Path &object_path,
76 const std::vector< std::string > &interfaces) {
Ben Chanfad4a0b2012-04-18 15:49:59 -070077 SLOG(DBus, 2) << __func__ << "(" << object_path << ")";
Eric Shienbrood9a245532012-03-07 14:20:39 -050078 interfaces_removed_callback_.Run(object_path, interfaces);
David Rochbergb8b89b12012-02-28 16:11:33 -050079}
80
81// Method callback
82void DBusObjectManagerProxy::Proxy::GetManagedObjectsCallback(
83 const DBusObjectsWithProperties &objects_with_properties,
84 const DBus::Error &dberror,
85 void *data) {
Ben Chanfad4a0b2012-04-18 15:49:59 -070086 SLOG(DBus, 2) << __func__;
David Rochbergb8b89b12012-02-28 16:11:33 -050087 shill::Error error;
88 CellularError::FromDBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -050089 scoped_ptr<ManagedObjectsCallback> callback(
90 reinterpret_cast<ManagedObjectsCallback *>(data));
David Rochbergb8b89b12012-02-28 16:11:33 -050091
Eric Shienbrood9a245532012-03-07 14:20:39 -050092 callback->Run(objects_with_properties, error);
David Rochbergb8b89b12012-02-28 16:11:33 -050093}
94
95} // namespace shill