blob: a2af6f45df7d0eb7fde3afa6fa78ab7b6737c64f [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
mukesh agrawal06175d72012-04-23 16:46:01 -07006#include "shill/cellular_error.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -07007#include "shill/logging.h"
David Rochbergb8b89b12012-02-28 16:11:33 -05008
9using std::string;
10
11namespace shill {
12
13DBusObjectManagerProxy::DBusObjectManagerProxy(
David Rochbergb8b89b12012-02-28 16:11:33 -050014 DBus::Connection *connection,
15 const string &path,
16 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050017 : proxy_(connection, path, service) {}
David Rochbergb8b89b12012-02-28 16:11:33 -050018DBusObjectManagerProxy::~DBusObjectManagerProxy() {}
19
Eric Shienbrood9a245532012-03-07 14:20:39 -050020void DBusObjectManagerProxy::GetManagedObjects(
21 Error *error,
22 const ManagedObjectsCallback &callback,
23 int timeout) {
24 scoped_ptr<ManagedObjectsCallback> cb(new ManagedObjectsCallback(callback));
25 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070026 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050027 proxy_.GetManagedObjects(cb.get(), timeout);
David Rochbergfa1d31d2012-03-20 10:38:07 -040028 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070029 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050030 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) {
Ben Chanfad4a0b2012-04-18 15:49:59 -070067 SLOG(DBus, 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) {
Ben Chanfad4a0b2012-04-18 15:49:59 -070075 SLOG(DBus, 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) {
Ben Chanfad4a0b2012-04-18 15:49:59 -070084 SLOG(DBus, 2) << __func__;
David Rochbergb8b89b12012-02-28 16:11:33 -050085 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