mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -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/manager_dbus_adaptor.h" |
| 6 | |
| 7 | #include <map> |
| 8 | #include <string> |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 9 | #include <vector> |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 10 | |
Christopher Wiley | 0d9cf0c | 2013-02-19 19:24:57 -0800 | [diff] [blame] | 11 | #include <base/bind.h> |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 12 | #include <dbus-c++/dbus.h> |
| 13 | |
Christopher Wiley | 0d9cf0c | 2013-02-19 19:24:57 -0800 | [diff] [blame] | 14 | #include "shill/callbacks.h" |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 15 | #include "shill/device.h" |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 16 | #include "shill/error.h" |
Gaurav Shah | b790aa2 | 2012-10-23 12:51:12 -0700 | [diff] [blame] | 17 | #include "shill/geolocation_info.h" |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 18 | #include "shill/key_value_store.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 19 | #include "shill/logging.h" |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 20 | #include "shill/manager.h" |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 21 | #include "shill/wifi_service.h" |
Chris Masone | 7ccc819 | 2011-05-24 14:54:49 -0700 | [diff] [blame] | 22 | |
Christopher Wiley | 0d9cf0c | 2013-02-19 19:24:57 -0800 | [diff] [blame] | 23 | using base::Bind; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 24 | using std::map; |
| 25 | using std::string; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 26 | using std::vector; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 27 | |
| 28 | namespace shill { |
| 29 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 30 | // static |
Chris Masone | 19e3040 | 2011-07-19 15:48:47 -0700 | [diff] [blame] | 31 | const char ManagerDBusAdaptor::kPath[] = "/"; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 32 | |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 33 | ManagerDBusAdaptor::ManagerDBusAdaptor(DBus::Connection* conn, Manager *manager) |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 34 | : DBusAdaptor(conn, kPath), |
| 35 | manager_(manager) { |
| 36 | } |
Chris Masone | ec6b18b | 2011-06-08 14:09:10 -0700 | [diff] [blame] | 37 | |
| 38 | ManagerDBusAdaptor::~ManagerDBusAdaptor() { |
| 39 | manager_ = NULL; |
| 40 | } |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 41 | |
| 42 | void ManagerDBusAdaptor::UpdateRunning() {} |
| 43 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 44 | void ManagerDBusAdaptor::EmitBoolChanged(const 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 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 49 | void ManagerDBusAdaptor::EmitUintChanged(const string &name, |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 50 | uint32 value) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 51 | SLOG(DBus, 2) << __func__ << ": " << name; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 52 | PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value)); |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 55 | void ManagerDBusAdaptor::EmitIntChanged(const string &name, int value) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 56 | SLOG(DBus, 2) << __func__ << ": " << name; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 57 | PropertyChanged(name, DBusAdaptor::Int32ToVariant(value)); |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 60 | void ManagerDBusAdaptor::EmitStringChanged(const string &name, |
| 61 | const string &value) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 62 | SLOG(DBus, 2) << __func__ << ": " << name; |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 63 | PropertyChanged(name, DBusAdaptor::StringToVariant(value)); |
| 64 | } |
| 65 | |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 66 | void ManagerDBusAdaptor::EmitStringsChanged(const string &name, |
| 67 | const vector<string> &value) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 68 | SLOG(DBus, 2) << __func__ << ": " << name; |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 69 | PropertyChanged(name, DBusAdaptor::StringsToVariant(value)); |
| 70 | } |
| 71 | |
Paul Stewart | 49739c0 | 2012-08-08 17:24:03 -0700 | [diff] [blame] | 72 | void ManagerDBusAdaptor::EmitRpcIdentifierChanged( |
| 73 | const string &name, |
| 74 | const string &value) { |
| 75 | SLOG(DBus, 2) << __func__ << ": " << name; |
| 76 | PropertyChanged(name, DBusAdaptor::PathToVariant(value)); |
| 77 | } |
| 78 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 79 | void ManagerDBusAdaptor::EmitRpcIdentifierArrayChanged( |
| 80 | const string &name, |
| 81 | const vector<string> &value) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 82 | SLOG(DBus, 2) << __func__ << ": " << name; |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 83 | vector< ::DBus::Path> paths; |
| 84 | vector<string>::const_iterator it; |
| 85 | for (it = value.begin(); it != value.end(); ++it) { |
| 86 | paths.push_back(*it); |
| 87 | } |
| 88 | |
mukesh agrawal | 2366eed | 2012-03-20 18:21:50 -0700 | [diff] [blame] | 89 | PropertyChanged(name, DBusAdaptor::PathsToVariant(paths)); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 92 | void ManagerDBusAdaptor::EmitStateChanged(const string &new_state) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 93 | SLOG(DBus, 2) << __func__; |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 94 | StateChanged(new_state); |
| 95 | } |
| 96 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 97 | map<string, ::DBus::Variant> ManagerDBusAdaptor::GetProperties( |
| 98 | ::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 99 | SLOG(DBus, 2) << __func__; |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 100 | map<string, ::DBus::Variant> properties; |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 101 | DBusAdaptor::GetProperties(manager_->store(), &properties, &error); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 102 | return properties; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 105 | void ManagerDBusAdaptor::SetProperty(const string &name, |
| 106 | const ::DBus::Variant &value, |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 107 | ::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 108 | SLOG(DBus, 2) << __func__ << ": " << name; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 109 | if (DBusAdaptor::SetProperty(manager_->mutable_store(), |
| 110 | name, |
| 111 | value, |
| 112 | &error)) { |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 113 | PropertyChanged(name, value); |
| 114 | } |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 115 | } |
| 116 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 117 | string ManagerDBusAdaptor::GetState(::DBus::Error &/*error*/) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 118 | SLOG(DBus, 2) << __func__; |
Paul Stewart | 38fd24c | 2012-04-25 14:06:29 -0700 | [diff] [blame] | 119 | return manager_->CalculateState(NULL); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 122 | ::DBus::Path ManagerDBusAdaptor::CreateProfile(const string &name, |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 123 | ::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 124 | SLOG(DBus, 2) << __func__ << ": " << name; |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 125 | Error e; |
| 126 | string path; |
| 127 | manager_->CreateProfile(name, &path, &e); |
Paul Stewart | f3eced9 | 2013-04-17 12:18:22 -0700 | [diff] [blame] | 128 | if (e.ToDBusError(&error)) { |
| 129 | return "/"; |
| 130 | } |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 131 | return ::DBus::Path(path); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Paul Stewart | e73d05c | 2012-03-29 16:26:05 -0700 | [diff] [blame] | 134 | void ManagerDBusAdaptor::RemoveProfile(const string &name, |
| 135 | ::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 136 | SLOG(DBus, 2) << __func__ << ": " << name; |
Paul Stewart | e73d05c | 2012-03-29 16:26:05 -0700 | [diff] [blame] | 137 | Error e; |
| 138 | manager_->RemoveProfile(name, &e); |
| 139 | e.ToDBusError(&error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Paul Stewart | d2e1c36 | 2013-03-03 19:06:07 -0800 | [diff] [blame] | 142 | ::DBus::Path ManagerDBusAdaptor::PushProfile(const string &name, |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 143 | ::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 144 | SLOG(DBus, 2) << __func__ << ": " << name; |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 145 | Error e; |
| 146 | string path; |
| 147 | manager_->PushProfile(name, &path, &e); |
Paul Stewart | f3eced9 | 2013-04-17 12:18:22 -0700 | [diff] [blame] | 148 | if (e.ToDBusError(&error)) { |
| 149 | return "/"; |
| 150 | } |
| 151 | return ::DBus::Path(path); |
| 152 | } |
| 153 | |
| 154 | ::DBus::Path ManagerDBusAdaptor::InsertUserProfile(const string &name, |
| 155 | const string &user_hash, |
| 156 | ::DBus::Error &error) { |
| 157 | SLOG(DBus, 2) << __func__ << ": " << name; |
| 158 | Error e; |
| 159 | string path; |
| 160 | manager_->InsertUserProfile(name, user_hash, &path, &e); |
| 161 | if (e.ToDBusError(&error)) { |
| 162 | return "/"; |
| 163 | } |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 164 | return ::DBus::Path(path); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Paul Stewart | d2e1c36 | 2013-03-03 19:06:07 -0800 | [diff] [blame] | 167 | void ManagerDBusAdaptor::PopProfile(const string &name, |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 168 | ::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 169 | SLOG(DBus, 2) << __func__ << ": " << name; |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 170 | Error e; |
| 171 | manager_->PopProfile(name, &e); |
| 172 | e.ToDBusError(&error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 175 | void ManagerDBusAdaptor::PopAnyProfile(::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 176 | SLOG(DBus, 2) << __func__; |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 177 | Error e; |
| 178 | manager_->PopAnyProfile(&e); |
| 179 | e.ToDBusError(&error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Paul Stewart | 307c250 | 2013-03-23 12:32:10 -0700 | [diff] [blame] | 182 | void ManagerDBusAdaptor::PopAllUserProfiles(::DBus::Error &error) { |
| 183 | SLOG(DBus, 2) << __func__; |
| 184 | Error e; |
| 185 | manager_->PopAllUserProfiles(&e); |
| 186 | e.ToDBusError(&error); |
| 187 | } |
| 188 | |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 189 | void ManagerDBusAdaptor::RecheckPortal(::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 190 | SLOG(DBus, 2) << __func__; |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 191 | Error e; |
| 192 | manager_->RecheckPortal(&e); |
| 193 | e.ToDBusError(&error); |
| 194 | } |
| 195 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 196 | void ManagerDBusAdaptor::RequestScan(const string &technology, |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 197 | ::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 198 | SLOG(DBus, 2) << __func__ << ": " << technology; |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 199 | Error e; |
Wade Guthrie | 68d4109 | 2013-04-02 12:56:02 -0700 | [diff] [blame] | 200 | manager_->RequestScan(Device::kFullScan, technology, &e); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 201 | e.ToDBusError(&error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 204 | void ManagerDBusAdaptor::EnableTechnology(const string &technology_name, |
| 205 | ::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 206 | SLOG(DBus, 2) << __func__ << ": " << technology_name; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 207 | Error e(Error::kOperationInitiated); |
| 208 | DBus::Tag *tag = new DBus::Tag(); |
| 209 | manager_->EnableTechnology(technology_name, &e, GetMethodReplyCallback(tag)); |
| 210 | ReturnResultOrDefer(tag, e, &error); |
| 211 | // TODO(ers): A reply will be sent to the client as soon as the first |
| 212 | // device of a given technology has finished being enabled. It would |
| 213 | // seem arguably more correct to wait until all the devices were enabled. |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 216 | void ManagerDBusAdaptor::DisableTechnology(const string &technology_name, |
| 217 | ::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 218 | SLOG(DBus, 2) << __func__ << ": " << technology_name; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 219 | Error e(Error::kOperationInitiated); |
| 220 | DBus::Tag *tag = new DBus::Tag(); |
| 221 | manager_->DisableTechnology(technology_name, &e, GetMethodReplyCallback(tag)); |
| 222 | ReturnResultOrDefer(tag, e, &error); |
| 223 | // TODO(ers): A reply will be sent to the client as soon as the first |
| 224 | // device of a given technology has finished being disabled. It would |
| 225 | // seem arguably more correct to wait until all the devices were enabled. |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 228 | // Called, e.g., to get WiFiService handle for a hidden SSID. |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 229 | ::DBus::Path ManagerDBusAdaptor::GetService( |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 230 | const map<string, ::DBus::Variant> &args, |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 231 | ::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 232 | SLOG(DBus, 2) << __func__; |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 233 | ServiceRefPtr service; |
| 234 | KeyValueStore args_store; |
| 235 | Error e; |
| 236 | DBusAdaptor::ArgsToKeyValueStore(args, &args_store, &e); |
| 237 | if (e.IsSuccess()) { |
| 238 | service = manager_->GetService(args_store, &e); |
| 239 | } |
| 240 | if (e.ToDBusError(&error)) { |
| 241 | return "/"; // ensure return is syntactically valid |
| 242 | } |
| 243 | return service->GetRpcIdentifier(); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 246 | // Obsolete, use GetService instead. |
| 247 | ::DBus::Path ManagerDBusAdaptor::GetVPNService( |
| 248 | const map<string, ::DBus::Variant> &args, |
| 249 | ::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 250 | SLOG(DBus, 2) << __func__; |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 251 | return GetService(args, error); |
| 252 | } |
| 253 | |
| 254 | // Obsolete, use GetService instead. |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 255 | ::DBus::Path ManagerDBusAdaptor::GetWifiService( |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 256 | const map<string, ::DBus::Variant> &args, |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 257 | ::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 258 | SLOG(DBus, 2) << __func__; |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 259 | return GetService(args, error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 262 | |
Paul Stewart | d39d692 | 2012-12-21 08:59:57 -0800 | [diff] [blame] | 263 | ::DBus::Path ManagerDBusAdaptor::ConfigureService( |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 264 | const map<string, ::DBus::Variant> &args, |
| 265 | ::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 266 | SLOG(DBus, 2) << __func__; |
Paul Stewart | d39d692 | 2012-12-21 08:59:57 -0800 | [diff] [blame] | 267 | ServiceRefPtr service; |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 268 | KeyValueStore args_store; |
Paul Stewart | d39d692 | 2012-12-21 08:59:57 -0800 | [diff] [blame] | 269 | Error key_value_store_error; |
| 270 | DBusAdaptor::ArgsToKeyValueStore(args, &args_store, &key_value_store_error); |
| 271 | if (key_value_store_error.ToDBusError(&error)) { |
| 272 | return "/"; // ensure return is syntactically valid. |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 273 | } |
Paul Stewart | d39d692 | 2012-12-21 08:59:57 -0800 | [diff] [blame] | 274 | Error configure_error; |
| 275 | service = manager_->ConfigureService(args_store, &configure_error); |
| 276 | if (configure_error.ToDBusError(&error)) { |
| 277 | return "/"; // ensure return is syntactically valid. |
| 278 | } |
| 279 | return service->GetRpcIdentifier(); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Paul Stewart | d2e1c36 | 2013-03-03 19:06:07 -0800 | [diff] [blame] | 282 | ::DBus::Path ManagerDBusAdaptor::ConfigureServiceForProfile( |
| 283 | const ::DBus::Path &profile_rpcid, |
| 284 | const map<string, ::DBus::Variant> &args, |
| 285 | ::DBus::Error &error) { |
| 286 | SLOG(DBus, 2) << __func__; |
| 287 | ServiceRefPtr service; |
| 288 | KeyValueStore args_store; |
| 289 | Error key_value_store_error; |
| 290 | DBusAdaptor::ArgsToKeyValueStore(args, &args_store, &key_value_store_error); |
| 291 | if (key_value_store_error.ToDBusError(&error)) { |
| 292 | return "/"; // ensure return is syntactically valid. |
| 293 | } |
| 294 | Error configure_error; |
| 295 | service = manager_->ConfigureServiceForProfile( |
| 296 | profile_rpcid, args_store, &configure_error); |
| 297 | if (!service || configure_error.ToDBusError(&error)) { |
| 298 | return "/"; // ensure return is syntactically valid. |
| 299 | } |
| 300 | return service->GetRpcIdentifier(); |
| 301 | } |
| 302 | |
Paul Stewart | 7a20aa4 | 2013-01-17 12:21:41 -0800 | [diff] [blame] | 303 | ::DBus::Path ManagerDBusAdaptor::FindMatchingService( |
| 304 | const map<string, ::DBus::Variant> &args, |
| 305 | ::DBus::Error &error) { |
| 306 | SLOG(DBus, 2) << __func__; |
| 307 | KeyValueStore args_store; |
| 308 | Error value_error; |
| 309 | DBusAdaptor::ArgsToKeyValueStore(args, &args_store, &value_error); |
| 310 | if (value_error.ToDBusError(&error)) { |
| 311 | return "/"; // ensure return is syntactically valid |
| 312 | } |
| 313 | |
| 314 | Error find_error; |
| 315 | ServiceRefPtr service = |
| 316 | manager_->FindMatchingService(args_store, &find_error); |
| 317 | if (find_error.ToDBusError(&error)) { |
| 318 | return "/"; // ensure return is syntactically valid |
| 319 | } |
| 320 | |
| 321 | return service->GetRpcIdentifier(); |
| 322 | } |
| 323 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 324 | int32_t ManagerDBusAdaptor::GetDebugLevel(::DBus::Error &/*error*/) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 325 | SLOG(DBus, 2) << __func__; |
Chris Masone | 7ccc819 | 2011-05-24 14:54:49 -0700 | [diff] [blame] | 326 | return logging::GetMinLogLevel(); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 329 | void ManagerDBusAdaptor::SetDebugLevel(const int32_t &level, |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 330 | ::DBus::Error &/*error*/) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 331 | SLOG(DBus, 2) << __func__ << ": " << level; |
Ben Chan | bc49ac7 | 2012-04-10 19:59:45 -0700 | [diff] [blame] | 332 | if (level < logging::LOG_NUM_SEVERITIES) { |
Chris Masone | 7ccc819 | 2011-05-24 14:54:49 -0700 | [diff] [blame] | 333 | logging::SetMinLogLevel(level); |
Ben Chan | bc49ac7 | 2012-04-10 19:59:45 -0700 | [diff] [blame] | 334 | // Like VLOG, SLOG uses negative verbose level. |
| 335 | ScopeLogger::GetInstance()->set_verbose_level(-level); |
| 336 | } else { |
Chris Masone | 7ccc819 | 2011-05-24 14:54:49 -0700 | [diff] [blame] | 337 | LOG(WARNING) << "Ignoring attempt to set log level to " << level; |
Ben Chan | bc49ac7 | 2012-04-10 19:59:45 -0700 | [diff] [blame] | 338 | } |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 339 | } |
| 340 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 341 | string ManagerDBusAdaptor::GetServiceOrder(::DBus::Error &/*error*/) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 342 | SLOG(DBus, 2) << __func__; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 343 | return manager_->GetTechnologyOrder(); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 346 | void ManagerDBusAdaptor::SetServiceOrder(const string &order, |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 347 | ::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 348 | SLOG(DBus, 2) << __func__ << ": " << order; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 349 | Error e; |
| 350 | manager_->SetTechnologyOrder(order, &e); |
| 351 | e.ToDBusError(&error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Paul Stewart | d2e1c36 | 2013-03-03 19:06:07 -0800 | [diff] [blame] | 354 | string ManagerDBusAdaptor::GetDebugTags(::DBus::Error &/*error*/) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 355 | SLOG(DBus, 2) << __func__; |
Ben Chan | bc49ac7 | 2012-04-10 19:59:45 -0700 | [diff] [blame] | 356 | return ScopeLogger::GetInstance()->GetEnabledScopeNames(); |
Elly Jones | 16227d3 | 2012-02-09 14:17:25 -0500 | [diff] [blame] | 357 | } |
| 358 | |
Paul Stewart | d2e1c36 | 2013-03-03 19:06:07 -0800 | [diff] [blame] | 359 | void ManagerDBusAdaptor::SetDebugTags(const string &tags, |
Elly Jones | 16227d3 | 2012-02-09 14:17:25 -0500 | [diff] [blame] | 360 | ::DBus::Error &/*error*/) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 361 | SLOG(DBus, 2) << __func__ << ": " << tags; |
Ben Chan | bc49ac7 | 2012-04-10 19:59:45 -0700 | [diff] [blame] | 362 | ScopeLogger::GetInstance()->EnableScopesByName(tags); |
Elly Jones | 16227d3 | 2012-02-09 14:17:25 -0500 | [diff] [blame] | 363 | } |
| 364 | |
Paul Stewart | d2e1c36 | 2013-03-03 19:06:07 -0800 | [diff] [blame] | 365 | string ManagerDBusAdaptor::ListDebugTags(::DBus::Error &/*error*/) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 366 | SLOG(DBus, 2) << __func__; |
Ben Chan | bc49ac7 | 2012-04-10 19:59:45 -0700 | [diff] [blame] | 367 | return ScopeLogger::GetInstance()->GetAllScopeNames(); |
Elly Jones | 16227d3 | 2012-02-09 14:17:25 -0500 | [diff] [blame] | 368 | } |
| 369 | |
Gaurav Shah | 645bff8 | 2012-10-08 14:06:04 -0700 | [diff] [blame] | 370 | map<string, ::DBus::Variant> ManagerDBusAdaptor::GetNetworksForGeolocation( |
| 371 | ::DBus::Error &/*error*/) { |
| 372 | SLOG(DBus, 2) << __func__; |
| 373 | map<string, ::DBus::Variant> networks; |
Gaurav Shah | b790aa2 | 2012-10-23 12:51:12 -0700 | [diff] [blame] | 374 | map<string, GeolocationInfos> geoinfo_map = |
| 375 | manager_->GetNetworksForGeolocation(); |
| 376 | for (map<string, GeolocationInfos>::iterator it = geoinfo_map.begin(); |
| 377 | it != geoinfo_map.end(); ++it) { |
| 378 | Stringmaps value; |
| 379 | // Convert GeolocationInfos to their Stringmaps equivalent. |
| 380 | for(GeolocationInfos::const_iterator geoinfo_it = it->second.begin(); |
| 381 | geoinfo_it != it->second.end(); ++geoinfo_it) { |
| 382 | value.push_back(geoinfo_it->properties()); |
| 383 | } |
| 384 | networks[it->first] = StringmapsToVariant(value); |
| 385 | } |
Gaurav Shah | 645bff8 | 2012-10-08 14:06:04 -0700 | [diff] [blame] | 386 | return networks; |
| 387 | } |
| 388 | |
Christopher Wiley | 3d5ab40 | 2013-02-15 13:25:58 -0800 | [diff] [blame] | 389 | bool ManagerDBusAdaptor::VerifyDestination(const string &certificate, |
| 390 | const string &public_key, |
| 391 | const string &nonce, |
| 392 | const string &signed_data, |
| 393 | const string &destination_udn, |
Christopher Wiley | cdde79f | 2013-05-01 14:26:56 -0700 | [diff] [blame] | 394 | const string &hotspot_ssid, |
| 395 | const string &hotspot_bssid, |
Christopher Wiley | 3d5ab40 | 2013-02-15 13:25:58 -0800 | [diff] [blame] | 396 | ::DBus::Error &error) { |
| 397 | SLOG(DBus, 2) << __func__; |
Christopher Wiley | 0d9cf0c | 2013-02-19 19:24:57 -0800 | [diff] [blame] | 398 | Error e(Error::kOperationInitiated); |
| 399 | DBus::Tag *tag = new DBus::Tag(); |
| 400 | manager_->VerifyDestination(certificate, public_key, nonce, |
| 401 | signed_data, destination_udn, |
Christopher Wiley | cdde79f | 2013-05-01 14:26:56 -0700 | [diff] [blame] | 402 | hotspot_ssid, hotspot_bssid, |
Christopher Wiley | 0d9cf0c | 2013-02-19 19:24:57 -0800 | [diff] [blame] | 403 | GetBoolMethodReplyCallback(tag), &e); |
| 404 | ReturnResultOrDefer(tag, e, &error); |
| 405 | CHECK(e.IsFailure()) << __func__ << " should only return directly on error."; |
Christopher Wiley | 3d5ab40 | 2013-02-15 13:25:58 -0800 | [diff] [blame] | 406 | return false; |
| 407 | } |
| 408 | |
| 409 | string ManagerDBusAdaptor::VerifyAndEncryptCredentials( |
| 410 | const string &certificate, |
| 411 | const string &public_key, |
| 412 | const string &nonce, |
| 413 | const string &signed_data, |
| 414 | const string &destination_udn, |
Christopher Wiley | cdde79f | 2013-05-01 14:26:56 -0700 | [diff] [blame] | 415 | const string &hotspot_ssid, |
| 416 | const string &hotspot_bssid, |
Christopher Wiley | 3d5ab40 | 2013-02-15 13:25:58 -0800 | [diff] [blame] | 417 | const ::DBus::Path &network, |
| 418 | ::DBus::Error &error) { |
| 419 | SLOG(DBus, 2) << __func__; |
Christopher Wiley | 0d9cf0c | 2013-02-19 19:24:57 -0800 | [diff] [blame] | 420 | Error e(Error::kOperationInitiated); |
| 421 | DBus::Tag *tag = new DBus::Tag(); |
| 422 | manager_->VerifyAndEncryptCredentials(certificate, public_key, nonce, |
| 423 | signed_data, destination_udn, |
Christopher Wiley | cdde79f | 2013-05-01 14:26:56 -0700 | [diff] [blame] | 424 | hotspot_ssid, hotspot_bssid, |
Christopher Wiley | 0d9cf0c | 2013-02-19 19:24:57 -0800 | [diff] [blame] | 425 | network, |
| 426 | GetStringMethodReplyCallback(tag), |
| 427 | &e); |
| 428 | ReturnResultOrDefer(tag, e, &error); |
| 429 | CHECK(e.IsFailure()) << __func__ << " should only return directly on error."; |
Christopher Wiley | 3d5ab40 | 2013-02-15 13:25:58 -0800 | [diff] [blame] | 430 | return ""; |
| 431 | } |
| 432 | |
| 433 | string ManagerDBusAdaptor::VerifyAndEncryptData( |
| 434 | const string &certificate, |
| 435 | const string &public_key, |
| 436 | const string &nonce, |
| 437 | const string &signed_data, |
| 438 | const string &destination_udn, |
Christopher Wiley | cdde79f | 2013-05-01 14:26:56 -0700 | [diff] [blame] | 439 | const string &hotspot_ssid, |
| 440 | const string &hotspot_bssid, |
Christopher Wiley | 3d5ab40 | 2013-02-15 13:25:58 -0800 | [diff] [blame] | 441 | const string &data, |
| 442 | ::DBus::Error &error) { |
| 443 | SLOG(DBus, 2) << __func__; |
Christopher Wiley | 0d9cf0c | 2013-02-19 19:24:57 -0800 | [diff] [blame] | 444 | Error e(Error::kOperationInitiated); |
| 445 | DBus::Tag *tag = new DBus::Tag(); |
| 446 | manager_->VerifyAndEncryptData(certificate, public_key, nonce, |
| 447 | signed_data, destination_udn, |
Christopher Wiley | cdde79f | 2013-05-01 14:26:56 -0700 | [diff] [blame] | 448 | hotspot_ssid, hotspot_bssid, |
Christopher Wiley | 0d9cf0c | 2013-02-19 19:24:57 -0800 | [diff] [blame] | 449 | data, GetStringMethodReplyCallback(tag), |
| 450 | &e); |
| 451 | ReturnResultOrDefer(tag, e, &error); |
| 452 | CHECK(e.IsFailure()) << __func__ << " should only return directly on error."; |
Christopher Wiley | 3d5ab40 | 2013-02-15 13:25:58 -0800 | [diff] [blame] | 453 | return ""; |
| 454 | } |
| 455 | |
Paul Stewart | 39db5ca | 2013-03-18 14:15:17 -0700 | [diff] [blame] | 456 | void ManagerDBusAdaptor::ConnectToBestServices(::DBus::Error &error) { |
Darin Petkov | cbe9c39 | 2013-04-11 11:52:35 +0200 | [diff] [blame] | 457 | SLOG(DBus, 2) << __func__; |
Paul Stewart | 39db5ca | 2013-03-18 14:15:17 -0700 | [diff] [blame] | 458 | Error e; |
| 459 | manager_->ConnectToBestServices(&e); |
| 460 | e.ToDBusError(&error); |
| 461 | } |
Christopher Wiley | 3d5ab40 | 2013-02-15 13:25:58 -0800 | [diff] [blame] | 462 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 463 | } // namespace shill |