blob: fa76f0e870c7c76da3567446d0051ec9f99d3158 [file] [log] [blame]
Ben Chanfad4a0b2012-04-18 15:49:59 -07001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Darin Petkov5c97ac52011-07-19 16:30:49 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "shill/dbus_properties_proxy.h"
6
Christopher Wileyb691efd2012-08-09 13:51:51 -07007#include "shill/logging.h"
Darin Petkov5c97ac52011-07-19 16:30:49 -07008
Darin Petkov5c97ac52011-07-19 16:30:49 -07009namespace shill {
10
Darin Petkov5c97ac52011-07-19 16:30:49 -070011using std::string;
12using std::vector;
13
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070014namespace Logging {
15static auto kModuleLogScope = ScopeLogger::kDBus;
Paul Stewarta794cd62015-06-16 13:13:10 -070016static string ObjectID(const DBus::Path* p) { return *p; }
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070017}
18
Paul Stewarta794cd62015-06-16 13:13:10 -070019DBusPropertiesProxy::DBusPropertiesProxy(DBus::Connection* connection,
20 const string& path,
21 const string& service)
Jason Glasgow9c09e362012-04-18 15:16:29 -040022 : proxy_(connection, path, service) {}
Darin Petkov5c97ac52011-07-19 16:30:49 -070023
24DBusPropertiesProxy::~DBusPropertiesProxy() {}
25
Paul Stewarta794cd62015-06-16 13:13:10 -070026DBusPropertiesMap DBusPropertiesProxy::GetAll(const string& interface_name) {
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070027 SLOG(&proxy_.path(), 2) << __func__ << "(" << interface_name << ")";
Gary Morain610977f2012-05-04 16:03:52 -070028 try {
29 return proxy_.GetAll(interface_name);
Paul Stewarta794cd62015-06-16 13:13:10 -070030 } catch (const DBus::Error& e) {
Darin Petkovd2a78bc2012-08-15 12:34:49 +020031 LOG(ERROR) << "DBus exception: " << e.name() << ": " << e.what()
Gary Morain610977f2012-05-04 16:03:52 -070032 << " interface name: " << interface_name;
Gary Morain610977f2012-05-04 16:03:52 -070033 }
Darin Petkovd2a78bc2012-08-15 12:34:49 +020034 return DBusPropertiesMap();
Darin Petkov5c97ac52011-07-19 16:30:49 -070035}
36
Paul Stewarta794cd62015-06-16 13:13:10 -070037DBus::Variant DBusPropertiesProxy::Get(const string& interface_name,
38 const string& property) {
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070039 SLOG(&proxy_.path(), 2) << __func__ << "(" << interface_name << ", "
Arman Uguray5d9a8522013-09-10 17:43:13 -070040 << property << ")";
41 try {
42 return proxy_.Get(interface_name, property);
Paul Stewarta794cd62015-06-16 13:13:10 -070043 } catch (const DBus::Error& e) {
Arman Uguray5d9a8522013-09-10 17:43:13 -070044 LOG(ERROR) << "DBus exception: " << e.name() << ": " << e.what()
45 << " interface name: " << interface_name
46 << ", property: " << property;
47 }
48 return DBus::Variant();
49}
50
Jason Glasgow9c09e362012-04-18 15:16:29 -040051void DBusPropertiesProxy::set_properties_changed_callback(
Paul Stewarta794cd62015-06-16 13:13:10 -070052 const PropertiesChangedCallback& callback) {
Jason Glasgow9c09e362012-04-18 15:16:29 -040053 proxy_.set_properties_changed_callback(callback);
54}
55
56void DBusPropertiesProxy::set_modem_manager_properties_changed_callback(
Paul Stewarta794cd62015-06-16 13:13:10 -070057 const ModemManagerPropertiesChangedCallback& callback) {
Jason Glasgow9c09e362012-04-18 15:16:29 -040058 proxy_.set_modem_manager_properties_changed_callback(callback);
59}
60
Paul Stewarta794cd62015-06-16 13:13:10 -070061DBusPropertiesProxy::Proxy::Proxy(DBus::Connection* connection,
62 const string& path,
63 const string& service)
Jason Glasgow9c09e362012-04-18 15:16:29 -040064 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
Darin Petkov5c97ac52011-07-19 16:30:49 -070065
66DBusPropertiesProxy::Proxy::~Proxy() {}
67
68void DBusPropertiesProxy::Proxy::MmPropertiesChanged(
Paul Stewarta794cd62015-06-16 13:13:10 -070069 const string& interface,
70 const DBusPropertiesMap& properties) {
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070071 SLOG(&path(), 2) << __func__ << "(" << interface << ")";
Jason Glasgow9c09e362012-04-18 15:16:29 -040072 mm_properties_changed_callback_.Run(interface, properties);
Darin Petkov5c97ac52011-07-19 16:30:49 -070073}
74
75void DBusPropertiesProxy::Proxy::PropertiesChanged(
Paul Stewarta794cd62015-06-16 13:13:10 -070076 const string& interface,
77 const DBusPropertiesMap& changed_properties,
78 const vector<string>& invalidated_properties) {
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070079 SLOG(&path(), 2) << __func__ << "(" << interface << ")";
Jason Glasgow9c09e362012-04-18 15:16:29 -040080 properties_changed_callback_.Run(
Darin Petkovc5f56562011-08-06 16:40:05 -070081 interface, changed_properties, invalidated_properties);
Darin Petkov5c97ac52011-07-19 16:30:49 -070082}
83
Jason Glasgow9c09e362012-04-18 15:16:29 -040084void DBusPropertiesProxy::Proxy::set_properties_changed_callback(
Paul Stewarta794cd62015-06-16 13:13:10 -070085 const PropertiesChangedCallback& callback) {
Jason Glasgow9c09e362012-04-18 15:16:29 -040086 properties_changed_callback_ = callback;
87}
88
89void DBusPropertiesProxy::Proxy::set_modem_manager_properties_changed_callback(
Paul Stewarta794cd62015-06-16 13:13:10 -070090 const ModemManagerPropertiesChangedCallback& callback) {
Jason Glasgow9c09e362012-04-18 15:16:29 -040091 mm_properties_changed_callback_ = callback;
92}
93
Darin Petkov5c97ac52011-07-19 16:30:49 -070094} // namespace shill