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" |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 14 | #include "shill/scope_logger.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 | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 79 | SLOG(DBus, 2) << __func__; |
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; |
| 117 | device_->Scan(&e); |
| 118 | e.ToDBusError(&error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | ::DBus::Path DeviceDBusAdaptor::AddIPConfig(const string& , |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 122 | ::DBus::Error &/*error*/) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 123 | SLOG(DBus, 2) << __func__; |
Darin Petkov | fd164b8 | 2012-02-10 14:11:52 +0100 | [diff] [blame] | 124 | return "/"; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Darin Petkov | 9ae310f | 2011-08-30 15:41:13 -0700 | [diff] [blame] | 127 | void DeviceDBusAdaptor::Register(const string &network_id, |
| 128 | ::DBus::Error &error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 129 | SLOG(DBus, 2) << __func__ << "(" << network_id << ")"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 130 | Error e(Error::kOperationInitiated); |
| 131 | DBus::Tag *tag = new DBus::Tag(); |
| 132 | device_->RegisterOnNetwork(network_id, &e, GetMethodReplyCallback(tag)); |
| 133 | ReturnResultOrDefer(tag, e, &error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 136 | void DeviceDBusAdaptor::RequirePin( |
| 137 | const string &pin, const bool &require, DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 138 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 139 | Error e(Error::kOperationInitiated); |
| 140 | DBus::Tag *tag = new DBus::Tag(); |
| 141 | device_->RequirePIN(pin, require, &e, GetMethodReplyCallback(tag)); |
| 142 | ReturnResultOrDefer(tag, e, &error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 145 | void DeviceDBusAdaptor::EnterPin(const string &pin, DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 146 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 147 | Error e(Error::kOperationInitiated); |
| 148 | DBus::Tag *tag = new DBus::Tag(); |
| 149 | device_->EnterPIN(pin, &e, GetMethodReplyCallback(tag)); |
| 150 | ReturnResultOrDefer(tag, e, &error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 153 | void DeviceDBusAdaptor::UnblockPin( |
| 154 | const string &unblock_code, const string &pin, DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 155 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 156 | Error e(Error::kOperationInitiated); |
| 157 | DBus::Tag *tag = new DBus::Tag(); |
| 158 | device_->UnblockPIN(unblock_code, pin, &e, GetMethodReplyCallback(tag)); |
| 159 | ReturnResultOrDefer(tag, e, &error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 162 | void DeviceDBusAdaptor::ChangePin( |
| 163 | const string &old_pin, const string &new_pin, DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 164 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 165 | Error e; |
| 166 | DBus::Tag *tag = new DBus::Tag(); |
| 167 | device_->ChangePIN(old_pin, new_pin, &e, GetMethodReplyCallback(tag)); |
| 168 | ReturnResultOrDefer(tag, e, &error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 171 | } // namespace shill |