mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 2 | // 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/device_dbus_adaptor.h" |
| 6 | |
| 7 | #include <map> |
| 8 | #include <string> |
| 9 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 10 | #include <base/bind.h> |
| 11 | |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 12 | #include "shill/device.h" |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 13 | #include "shill/error.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 14 | #include "shill/logging.h" |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 15 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 16 | using base::Bind; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 17 | using std::map; |
| 18 | using std::string; |
| 19 | |
| 20 | namespace shill { |
| 21 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 22 | // static |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 23 | const char DeviceDBusAdaptor::kPath[] = "/device/"; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 24 | |
Chris Masone | ec6b18b | 2011-06-08 14:09:10 -0700 | [diff] [blame] | 25 | DeviceDBusAdaptor::DeviceDBusAdaptor(DBus::Connection* conn, Device *device) |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 26 | : DBusAdaptor(conn, kPath + device->UniqueName()), |
Chris Masone | 4e85161 | 2011-07-01 10:46:53 -0700 | [diff] [blame] | 27 | device_(device), |
| 28 | connection_name_(conn->unique_name()) { |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 29 | } |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 30 | |
Chris Masone | ec6b18b | 2011-06-08 14:09:10 -0700 | [diff] [blame] | 31 | DeviceDBusAdaptor::~DeviceDBusAdaptor() { |
| 32 | device_ = NULL; |
| 33 | } |
Chris Masone | 4e85161 | 2011-07-01 10:46:53 -0700 | [diff] [blame] | 34 | const std::string &DeviceDBusAdaptor::GetRpcIdentifier() { |
| 35 | return path(); |
| 36 | } |
| 37 | |
| 38 | const std::string &DeviceDBusAdaptor::GetRpcConnectionIdentifier() { |
| 39 | return connection_name_; |
| 40 | } |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 41 | |
| 42 | void DeviceDBusAdaptor::UpdateEnabled() {} |
| 43 | |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 44 | void DeviceDBusAdaptor::EmitBoolChanged(const std::string& name, bool value) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 45 | SLOG(DBus, 2) << __func__ << ": " << name; |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 46 | PropertyChanged(name, DBusAdaptor::BoolToVariant(value)); |
| 47 | } |
| 48 | |
| 49 | void DeviceDBusAdaptor::EmitUintChanged(const std::string& name, uint32 value) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 50 | SLOG(DBus, 2) << __func__ << ": " << name; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 51 | PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value)); |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | void DeviceDBusAdaptor::EmitIntChanged(const std::string& name, int value) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 55 | SLOG(DBus, 2) << __func__ << ": " << name; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 56 | PropertyChanged(name, DBusAdaptor::Int32ToVariant(value)); |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | void DeviceDBusAdaptor::EmitStringChanged(const std::string& name, |
| 60 | const std::string& value) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 61 | SLOG(DBus, 2) << __func__ << ": " << name; |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 62 | PropertyChanged(name, DBusAdaptor::StringToVariant(value)); |
| 63 | } |
| 64 | |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 65 | void DeviceDBusAdaptor::EmitStringmapsChanged(const std::string &name, |
| 66 | const Stringmaps &value) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 67 | SLOG(DBus, 2) << __func__ << ": " << name; |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 68 | PropertyChanged(name, DBusAdaptor::StringmapsToVariant(value)); |
| 69 | } |
| 70 | |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 71 | void DeviceDBusAdaptor::EmitKeyValueStoreChanged(const std::string &name, |
| 72 | const KeyValueStore &value) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 73 | SLOG(DBus, 2) << __func__ << ": " << name; |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 74 | PropertyChanged(name, DBusAdaptor::KeyValueStoreToVariant(value)); |
| 75 | } |
| 76 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 77 | map<string, ::DBus::Variant> DeviceDBusAdaptor::GetProperties( |
| 78 | ::DBus::Error &error) { |
mukesh agrawal | 465331c | 2012-05-30 11:26:11 -0700 | [diff] [blame] | 79 | SLOG(DBus, 2) << __func__ << " " << device_->FriendlyName(); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 80 | map<string, ::DBus::Variant> properties; |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 81 | DBusAdaptor::GetProperties(device_->store(), &properties, &error); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 82 | return properties; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 83 | } |
| 84 | |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 85 | void DeviceDBusAdaptor::SetProperty(const string &name, |
| 86 | const ::DBus::Variant &value, |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 87 | ::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 88 | SLOG(DBus, 2) << __func__ << ": " << name; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 89 | DBusAdaptor::SetProperty(device_->mutable_store(), name, value, &error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 90 | } |
| 91 | |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 92 | void DeviceDBusAdaptor::ClearProperty(const std::string &name, |
mukesh agrawal | 8abd2f6 | 2012-01-30 14:56:14 -0800 | [diff] [blame] | 93 | ::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 94 | SLOG(DBus, 2) << __func__ << ": " << name; |
mukesh agrawal | 8abd2f6 | 2012-01-30 14:56:14 -0800 | [diff] [blame] | 95 | DBusAdaptor::ClearProperty(device_->mutable_store(), name, &error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 98 | void DeviceDBusAdaptor::Enable(::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 99 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 100 | Error e(Error::kOperationInitiated); |
| 101 | DBus::Tag *tag = new DBus::Tag(); |
| 102 | device_->SetEnabledPersistent(true, &e, GetMethodReplyCallback(tag)); |
| 103 | ReturnResultOrDefer(tag, e, &error); |
| 104 | } |
| 105 | |
| 106 | void DeviceDBusAdaptor::Disable(::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 107 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 108 | Error e(Error::kOperationInitiated); |
| 109 | DBus::Tag *tag = new DBus::Tag(); |
| 110 | device_->SetEnabledPersistent(false, &e, GetMethodReplyCallback(tag)); |
| 111 | ReturnResultOrDefer(tag, e, &error); |
| 112 | } |
| 113 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 114 | void DeviceDBusAdaptor::ProposeScan(::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 115 | SLOG(DBus, 2) << __func__; |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 116 | Error e; |
Wade Guthrie | 68d4109 | 2013-04-02 12:56:02 -0700 | [diff] [blame] | 117 | // User scan requests, which are the likely source of DBus requests, probably |
| 118 | // aren't time-critical so we might as well perform a complete scan. It |
| 119 | // also provides a failsafe for progressive scan. |
| 120 | device_->Scan(Device::kFullScan, &e); |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 121 | e.ToDBusError(&error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | ::DBus::Path DeviceDBusAdaptor::AddIPConfig(const string& , |
Paul Stewart | 624b9a2 | 2012-05-21 14:17:35 -0700 | [diff] [blame] | 125 | ::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 126 | SLOG(DBus, 2) << __func__; |
Paul Stewart | 624b9a2 | 2012-05-21 14:17:35 -0700 | [diff] [blame] | 127 | Error e(Error::kNotSupported, "This function is deprecated in shill"); |
| 128 | e.ToDBusError(&error); |
Darin Petkov | fd164b8 | 2012-02-10 14:11:52 +0100 | [diff] [blame] | 129 | return "/"; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Darin Petkov | 9ae310f | 2011-08-30 15:41:13 -0700 | [diff] [blame] | 132 | void DeviceDBusAdaptor::Register(const string &network_id, |
| 133 | ::DBus::Error &error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 134 | SLOG(DBus, 2) << __func__ << "(" << network_id << ")"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 135 | Error e(Error::kOperationInitiated); |
| 136 | DBus::Tag *tag = new DBus::Tag(); |
| 137 | device_->RegisterOnNetwork(network_id, &e, GetMethodReplyCallback(tag)); |
| 138 | ReturnResultOrDefer(tag, e, &error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 141 | void DeviceDBusAdaptor::RequirePin( |
| 142 | const string &pin, const bool &require, DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 143 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 144 | Error e(Error::kOperationInitiated); |
| 145 | DBus::Tag *tag = new DBus::Tag(); |
| 146 | device_->RequirePIN(pin, require, &e, GetMethodReplyCallback(tag)); |
| 147 | ReturnResultOrDefer(tag, e, &error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 150 | void DeviceDBusAdaptor::EnterPin(const string &pin, DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 151 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 152 | Error e(Error::kOperationInitiated); |
| 153 | DBus::Tag *tag = new DBus::Tag(); |
| 154 | device_->EnterPIN(pin, &e, GetMethodReplyCallback(tag)); |
| 155 | ReturnResultOrDefer(tag, e, &error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 158 | void DeviceDBusAdaptor::UnblockPin( |
| 159 | const string &unblock_code, const string &pin, DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 160 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 161 | Error e(Error::kOperationInitiated); |
| 162 | DBus::Tag *tag = new DBus::Tag(); |
| 163 | device_->UnblockPIN(unblock_code, pin, &e, GetMethodReplyCallback(tag)); |
| 164 | ReturnResultOrDefer(tag, e, &error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 167 | void DeviceDBusAdaptor::ChangePin( |
| 168 | const string &old_pin, const string &new_pin, DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 169 | SLOG(DBus, 2) << __func__; |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 170 | Error e(Error::kOperationInitiated); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 171 | DBus::Tag *tag = new DBus::Tag(); |
| 172 | device_->ChangePIN(old_pin, new_pin, &e, GetMethodReplyCallback(tag)); |
| 173 | ReturnResultOrDefer(tag, e, &error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Ben Chan | ad663e1 | 2013-01-08 01:58:47 -0800 | [diff] [blame] | 176 | void DeviceDBusAdaptor::Reset(::DBus::Error &error) { |
| 177 | SLOG(DBus, 2) << __func__; |
| 178 | Error e(Error::kOperationInitiated); |
| 179 | DBus::Tag *tag = new DBus::Tag(); |
| 180 | device_->Reset(&e, GetMethodReplyCallback(tag)); |
| 181 | ReturnResultOrDefer(tag, e, &error); |
| 182 | } |
| 183 | |
Paul Stewart | 6ff27f5 | 2012-07-11 06:51:41 -0700 | [diff] [blame] | 184 | void DeviceDBusAdaptor::ResetByteCounters(DBus::Error &error) { |
| 185 | device_->ResetByteCounters(); |
| 186 | } |
| 187 | |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 188 | void DeviceDBusAdaptor::SetCarrier(const string &carrier, DBus::Error &error) { |
| 189 | SLOG(DBus, 2) << __func__ << "(" << carrier << ")"; |
| 190 | Error e(Error::kOperationInitiated); |
| 191 | DBus::Tag *tag = new DBus::Tag(); |
| 192 | device_->SetCarrier(carrier, &e, GetMethodReplyCallback(tag)); |
| 193 | ReturnResultOrDefer(tag, e, &error); |
| 194 | } |
| 195 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 196 | } // namespace shill |