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" |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 14 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 15 | using base::Bind; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 16 | using std::map; |
| 17 | using std::string; |
| 18 | |
| 19 | namespace shill { |
| 20 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 21 | // static |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 22 | const char DeviceDBusAdaptor::kPath[] = "/device/"; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 23 | |
Chris Masone | ec6b18b | 2011-06-08 14:09:10 -0700 | [diff] [blame] | 24 | DeviceDBusAdaptor::DeviceDBusAdaptor(DBus::Connection* conn, Device *device) |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 25 | : DBusAdaptor(conn, kPath + device->UniqueName()), |
Chris Masone | 4e85161 | 2011-07-01 10:46:53 -0700 | [diff] [blame] | 26 | device_(device), |
| 27 | connection_name_(conn->unique_name()) { |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 28 | } |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 29 | |
Chris Masone | ec6b18b | 2011-06-08 14:09:10 -0700 | [diff] [blame] | 30 | DeviceDBusAdaptor::~DeviceDBusAdaptor() { |
| 31 | device_ = NULL; |
| 32 | } |
Chris Masone | 4e85161 | 2011-07-01 10:46:53 -0700 | [diff] [blame] | 33 | const std::string &DeviceDBusAdaptor::GetRpcIdentifier() { |
| 34 | return path(); |
| 35 | } |
| 36 | |
| 37 | const std::string &DeviceDBusAdaptor::GetRpcConnectionIdentifier() { |
| 38 | return connection_name_; |
| 39 | } |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 40 | |
| 41 | void DeviceDBusAdaptor::UpdateEnabled() {} |
| 42 | |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 43 | void DeviceDBusAdaptor::EmitBoolChanged(const std::string& name, bool value) { |
| 44 | PropertyChanged(name, DBusAdaptor::BoolToVariant(value)); |
| 45 | } |
| 46 | |
| 47 | void DeviceDBusAdaptor::EmitUintChanged(const std::string& name, uint32 value) { |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 48 | PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value)); |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | void DeviceDBusAdaptor::EmitIntChanged(const std::string& name, int value) { |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 52 | PropertyChanged(name, DBusAdaptor::Int32ToVariant(value)); |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | void DeviceDBusAdaptor::EmitStringChanged(const std::string& name, |
| 56 | const std::string& value) { |
| 57 | PropertyChanged(name, DBusAdaptor::StringToVariant(value)); |
| 58 | } |
| 59 | |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 60 | void DeviceDBusAdaptor::EmitStringmapsChanged(const std::string &name, |
| 61 | const Stringmaps &value) { |
| 62 | PropertyChanged(name, DBusAdaptor::StringmapsToVariant(value)); |
| 63 | } |
| 64 | |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 65 | void DeviceDBusAdaptor::EmitKeyValueStoreChanged(const std::string &name, |
| 66 | const KeyValueStore &value) { |
| 67 | PropertyChanged(name, DBusAdaptor::KeyValueStoreToVariant(value)); |
| 68 | } |
| 69 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 70 | map<string, ::DBus::Variant> DeviceDBusAdaptor::GetProperties( |
| 71 | ::DBus::Error &error) { |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 72 | map<string, ::DBus::Variant> properties; |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 73 | DBusAdaptor::GetProperties(device_->store(), &properties, &error); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 74 | return properties; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 75 | } |
| 76 | |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 77 | void DeviceDBusAdaptor::SetProperty(const string &name, |
| 78 | const ::DBus::Variant &value, |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 79 | ::DBus::Error &error) { |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 80 | DBusAdaptor::SetProperty(device_->mutable_store(), name, value, &error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 81 | } |
| 82 | |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 83 | void DeviceDBusAdaptor::ClearProperty(const std::string &name, |
mukesh agrawal | 8abd2f6 | 2012-01-30 14:56:14 -0800 | [diff] [blame] | 84 | ::DBus::Error &error) { |
| 85 | DBusAdaptor::ClearProperty(device_->mutable_store(), name, &error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 88 | void DeviceDBusAdaptor::Enable(::DBus::Error &error) { |
| 89 | Error e(Error::kOperationInitiated); |
| 90 | DBus::Tag *tag = new DBus::Tag(); |
| 91 | device_->SetEnabledPersistent(true, &e, GetMethodReplyCallback(tag)); |
| 92 | ReturnResultOrDefer(tag, e, &error); |
| 93 | } |
| 94 | |
| 95 | void DeviceDBusAdaptor::Disable(::DBus::Error &error) { |
| 96 | Error e(Error::kOperationInitiated); |
| 97 | DBus::Tag *tag = new DBus::Tag(); |
| 98 | device_->SetEnabledPersistent(false, &e, GetMethodReplyCallback(tag)); |
| 99 | ReturnResultOrDefer(tag, e, &error); |
| 100 | } |
| 101 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 102 | void DeviceDBusAdaptor::ProposeScan(::DBus::Error &error) { |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 103 | Error e; |
| 104 | device_->Scan(&e); |
| 105 | e.ToDBusError(&error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | ::DBus::Path DeviceDBusAdaptor::AddIPConfig(const string& , |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 109 | ::DBus::Error &/*error*/) { |
Darin Petkov | fd164b8 | 2012-02-10 14:11:52 +0100 | [diff] [blame] | 110 | return "/"; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Darin Petkov | 9ae310f | 2011-08-30 15:41:13 -0700 | [diff] [blame] | 113 | void DeviceDBusAdaptor::Register(const string &network_id, |
| 114 | ::DBus::Error &error) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 115 | VLOG(2) << __func__ << "(" << network_id << ")"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 116 | Error e(Error::kOperationInitiated); |
| 117 | DBus::Tag *tag = new DBus::Tag(); |
| 118 | device_->RegisterOnNetwork(network_id, &e, GetMethodReplyCallback(tag)); |
| 119 | ReturnResultOrDefer(tag, e, &error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 122 | void DeviceDBusAdaptor::RequirePin( |
| 123 | const string &pin, const bool &require, DBus::Error &error) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 124 | Error e(Error::kOperationInitiated); |
| 125 | DBus::Tag *tag = new DBus::Tag(); |
| 126 | device_->RequirePIN(pin, require, &e, GetMethodReplyCallback(tag)); |
| 127 | ReturnResultOrDefer(tag, e, &error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 130 | void DeviceDBusAdaptor::EnterPin(const string &pin, DBus::Error &error) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 131 | Error e(Error::kOperationInitiated); |
| 132 | DBus::Tag *tag = new DBus::Tag(); |
| 133 | device_->EnterPIN(pin, &e, GetMethodReplyCallback(tag)); |
| 134 | ReturnResultOrDefer(tag, e, &error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 137 | void DeviceDBusAdaptor::UnblockPin( |
| 138 | const string &unblock_code, const string &pin, DBus::Error &error) { |
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_->UnblockPIN(unblock_code, pin, &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::ChangePin( |
| 146 | const string &old_pin, const string &new_pin, DBus::Error &error) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 147 | Error e; |
| 148 | DBus::Tag *tag = new DBus::Tag(); |
| 149 | device_->ChangePIN(old_pin, new_pin, &e, GetMethodReplyCallback(tag)); |
| 150 | ReturnResultOrDefer(tag, e, &error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 153 | } // namespace shill |