blob: 306ddf3b54b98a75d4e17e243f99e6202319c74b [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
Jason Glasgow9c09e362012-04-18 15:16:29 -040014DBusPropertiesProxy::DBusPropertiesProxy(DBus::Connection *connection,
Darin Petkov5c97ac52011-07-19 16:30:49 -070015 const string &path,
16 const string &service)
Jason Glasgow9c09e362012-04-18 15:16:29 -040017 : proxy_(connection, path, service) {}
Darin Petkov5c97ac52011-07-19 16:30:49 -070018
19DBusPropertiesProxy::~DBusPropertiesProxy() {}
20
Darin Petkove0a312e2011-07-20 13:45:28 -070021DBusPropertiesMap DBusPropertiesProxy::GetAll(const string &interface_name) {
mukesh agrawal06175d72012-04-23 16:46:01 -070022 SLOG(DBus, 2) << __func__ << "(" << interface_name << ")";
Gary Morain610977f2012-05-04 16:03:52 -070023 try {
24 return proxy_.GetAll(interface_name);
25 } catch (const DBus::Error &e) {
Darin Petkovd2a78bc2012-08-15 12:34:49 +020026 LOG(ERROR) << "DBus exception: " << e.name() << ": " << e.what()
Gary Morain610977f2012-05-04 16:03:52 -070027 << " interface name: " << interface_name;
Gary Morain610977f2012-05-04 16:03:52 -070028 }
Darin Petkovd2a78bc2012-08-15 12:34:49 +020029 return DBusPropertiesMap();
Darin Petkov5c97ac52011-07-19 16:30:49 -070030}
31
Arman Uguray5d9a8522013-09-10 17:43:13 -070032DBus::Variant DBusPropertiesProxy::Get(const string &interface_name,
33 const string &property) {
34 SLOG(DBus, 2) << __func__ << "(" << interface_name << ", "
35 << property << ")";
36 try {
37 return proxy_.Get(interface_name, property);
38 } catch (const DBus::Error &e) {
39 LOG(ERROR) << "DBus exception: " << e.name() << ": " << e.what()
40 << " interface name: " << interface_name
41 << ", property: " << property;
42 }
43 return DBus::Variant();
44}
45
Jason Glasgow9c09e362012-04-18 15:16:29 -040046void DBusPropertiesProxy::set_properties_changed_callback(
47 const PropertiesChangedCallback &callback) {
48 proxy_.set_properties_changed_callback(callback);
49}
50
51void DBusPropertiesProxy::set_modem_manager_properties_changed_callback(
52 const ModemManagerPropertiesChangedCallback &callback) {
53 proxy_.set_modem_manager_properties_changed_callback(callback);
54}
55
56DBusPropertiesProxy::Proxy::Proxy(DBus::Connection *connection,
Darin Petkov5c97ac52011-07-19 16:30:49 -070057 const string &path,
58 const string &service)
Jason Glasgow9c09e362012-04-18 15:16:29 -040059 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
Darin Petkov5c97ac52011-07-19 16:30:49 -070060
61DBusPropertiesProxy::Proxy::~Proxy() {}
62
63void DBusPropertiesProxy::Proxy::MmPropertiesChanged(
64 const string &interface,
Darin Petkove0a312e2011-07-20 13:45:28 -070065 const DBusPropertiesMap &properties) {
Ben Chanfad4a0b2012-04-18 15:49:59 -070066 SLOG(DBus, 2) << __func__ << "(" << interface << ")";
Jason Glasgow9c09e362012-04-18 15:16:29 -040067 mm_properties_changed_callback_.Run(interface, properties);
Darin Petkov5c97ac52011-07-19 16:30:49 -070068}
69
70void DBusPropertiesProxy::Proxy::PropertiesChanged(
71 const string &interface,
Darin Petkove0a312e2011-07-20 13:45:28 -070072 const DBusPropertiesMap &changed_properties,
Darin Petkov5c97ac52011-07-19 16:30:49 -070073 const vector<string> &invalidated_properties) {
Ben Chanfad4a0b2012-04-18 15:49:59 -070074 SLOG(DBus, 2) << __func__ << "(" << interface << ")";
Jason Glasgow9c09e362012-04-18 15:16:29 -040075 properties_changed_callback_.Run(
Darin Petkovc5f56562011-08-06 16:40:05 -070076 interface, changed_properties, invalidated_properties);
Darin Petkov5c97ac52011-07-19 16:30:49 -070077}
78
Jason Glasgow9c09e362012-04-18 15:16:29 -040079void DBusPropertiesProxy::Proxy::set_properties_changed_callback(
80 const PropertiesChangedCallback &callback) {
81 properties_changed_callback_ = callback;
82}
83
84void DBusPropertiesProxy::Proxy::set_modem_manager_properties_changed_callback(
85 const ModemManagerPropertiesChangedCallback &callback) {
86 mm_properties_changed_callback_ = callback;
87}
88
Darin Petkov5c97ac52011-07-19 16:30:49 -070089} // namespace shill