blob: d1a778d5bbb63385b277a87bfd1c6cd13b81f13b [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
8#include "cellular_error.h"
9
10using std::string;
11
12namespace shill {
13
14DBusObjectManagerProxy::DBusObjectManagerProxy(
David Rochbergb8b89b12012-02-28 16:11:33 -050015 DBus::Connection *connection,
16 const string &path,
17 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050018 : proxy_(connection, path, service) {}
David Rochbergb8b89b12012-02-28 16:11:33 -050019DBusObjectManagerProxy::~DBusObjectManagerProxy() {}
20
Eric Shienbrood9a245532012-03-07 14:20:39 -050021void 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 Rochbergfa1d31d2012-03-20 10:38:07 -040028 cb.release();
Eric Shienbrood9a245532012-03-07 14:20:39 -050029 } catch (DBus::Error e) {
30 if (error)
31 CellularError::FromDBusError(e, error);
32 }
33}
34
35void DBusObjectManagerProxy::set_interfaces_added_callback(
36 const InterfacesAddedSignalCallback &callback) {
37 proxy_.set_interfaces_added_callback(callback);
38}
39
40void DBusObjectManagerProxy::set_interfaces_removed_callback(
41 const InterfacesRemovedSignalCallback &callback) {
42 proxy_.set_interfaces_removed_callback(callback);
David Rochbergb8b89b12012-02-28 16:11:33 -050043}
44
45// Inherited from DBusObjectManagerProxyInterface.
Eric Shienbrood9a245532012-03-07 14:20:39 -050046DBusObjectManagerProxy::Proxy::Proxy(DBus::Connection *connection,
David Rochbergb8b89b12012-02-28 16:11:33 -050047 const std::string &path,
48 const std::string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050049 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
David Rochbergb8b89b12012-02-28 16:11:33 -050050
51DBusObjectManagerProxy::Proxy::~Proxy() {}
52
Eric Shienbrood9a245532012-03-07 14:20:39 -050053void DBusObjectManagerProxy::Proxy::set_interfaces_added_callback(
54 const InterfacesAddedSignalCallback &callback) {
55 interfaces_added_callback_ = callback;
56}
57
58void DBusObjectManagerProxy::Proxy::set_interfaces_removed_callback(
59 const InterfacesRemovedSignalCallback &callback) {
60 interfaces_removed_callback_ = callback;
61}
62
David Rochbergb8b89b12012-02-28 16:11:33 -050063// Signal callback
64void DBusObjectManagerProxy::Proxy::InterfacesAdded(
65 const ::DBus::Path &object_path,
66 const DBusInterfaceToProperties &interface_to_properties) {
67 VLOG(2) << __func__ << "(" << object_path << ")";
Eric Shienbrood9a245532012-03-07 14:20:39 -050068 interfaces_added_callback_.Run(object_path, interface_to_properties);
David Rochbergb8b89b12012-02-28 16:11:33 -050069}
70
71// Signal callback
72void DBusObjectManagerProxy::Proxy::InterfacesRemoved(
73 const ::DBus::Path &object_path,
74 const std::vector< std::string > &interfaces) {
75 VLOG(2) << __func__ << "(" << object_path << ")";
Eric Shienbrood9a245532012-03-07 14:20:39 -050076 interfaces_removed_callback_.Run(object_path, interfaces);
David Rochbergb8b89b12012-02-28 16:11:33 -050077}
78
79// Method callback
80void 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 Shienbrood9a245532012-03-07 14:20:39 -050087 scoped_ptr<ManagedObjectsCallback> callback(
88 reinterpret_cast<ManagedObjectsCallback *>(data));
David Rochbergb8b89b12012-02-28 16:11:33 -050089
Eric Shienbrood9a245532012-03-07 14:20:39 -050090 callback->Run(objects_with_properties, error);
David Rochbergb8b89b12012-02-28 16:11:33 -050091}
92
93} // namespace shill