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 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 11 | #include <dbus-c++/dbus.h> |
| 12 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 13 | #include "shill/device.h" |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 14 | #include "shill/error.h" |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 15 | #include "shill/key_value_store.h" |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 16 | #include "shill/manager.h" |
Ben Chan | bc49ac7 | 2012-04-10 19:59:45 -0700 | [diff] [blame] | 17 | #include "shill/scope_logger.h" |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 18 | #include "shill/wifi_service.h" |
Chris Masone | 7ccc819 | 2011-05-24 14:54:49 -0700 | [diff] [blame] | 19 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 20 | using std::map; |
| 21 | using std::string; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 22 | using std::vector; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 23 | |
| 24 | namespace shill { |
| 25 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 26 | // static |
Chris Masone | 19e3040 | 2011-07-19 15:48:47 -0700 | [diff] [blame] | 27 | const char ManagerDBusAdaptor::kPath[] = "/"; |
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 | ManagerDBusAdaptor::ManagerDBusAdaptor(DBus::Connection* conn, Manager *manager) |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 30 | : DBusAdaptor(conn, kPath), |
| 31 | manager_(manager) { |
| 32 | } |
Chris Masone | ec6b18b | 2011-06-08 14:09:10 -0700 | [diff] [blame] | 33 | |
| 34 | ManagerDBusAdaptor::~ManagerDBusAdaptor() { |
| 35 | manager_ = NULL; |
| 36 | } |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 37 | |
| 38 | void ManagerDBusAdaptor::UpdateRunning() {} |
| 39 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 40 | void ManagerDBusAdaptor::EmitBoolChanged(const string &name, bool value) { |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 41 | PropertyChanged(name, DBusAdaptor::BoolToVariant(value)); |
| 42 | } |
| 43 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 44 | void ManagerDBusAdaptor::EmitUintChanged(const string &name, |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 45 | uint32 value) { |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 46 | PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value)); |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 49 | void ManagerDBusAdaptor::EmitIntChanged(const string &name, int value) { |
| 50 | PropertyChanged(name, DBusAdaptor::Int32ToVariant(value)); |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 53 | void ManagerDBusAdaptor::EmitStringChanged(const string &name, |
| 54 | const string &value) { |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 55 | PropertyChanged(name, DBusAdaptor::StringToVariant(value)); |
| 56 | } |
| 57 | |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 58 | void ManagerDBusAdaptor::EmitStringsChanged(const string &name, |
| 59 | const vector<string> &value) { |
| 60 | PropertyChanged(name, DBusAdaptor::StringsToVariant(value)); |
| 61 | } |
| 62 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 63 | void ManagerDBusAdaptor::EmitRpcIdentifierArrayChanged( |
| 64 | const string &name, |
| 65 | const vector<string> &value) { |
| 66 | vector< ::DBus::Path> paths; |
| 67 | vector<string>::const_iterator it; |
| 68 | for (it = value.begin(); it != value.end(); ++it) { |
| 69 | paths.push_back(*it); |
| 70 | } |
| 71 | |
mukesh agrawal | 2366eed | 2012-03-20 18:21:50 -0700 | [diff] [blame] | 72 | PropertyChanged(name, DBusAdaptor::PathsToVariant(paths)); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 75 | void ManagerDBusAdaptor::EmitStateChanged(const string &new_state) { |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 76 | StateChanged(new_state); |
| 77 | } |
| 78 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 79 | map<string, ::DBus::Variant> ManagerDBusAdaptor::GetProperties( |
| 80 | ::DBus::Error &error) { |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 81 | map<string, ::DBus::Variant> properties; |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 82 | DBusAdaptor::GetProperties(manager_->store(), &properties, &error); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 83 | return properties; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 86 | void ManagerDBusAdaptor::SetProperty(const string &name, |
| 87 | const ::DBus::Variant &value, |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 88 | ::DBus::Error &error) { |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 89 | if (DBusAdaptor::SetProperty(manager_->mutable_store(), |
| 90 | name, |
| 91 | value, |
| 92 | &error)) { |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 93 | PropertyChanged(name, value); |
| 94 | } |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 95 | } |
| 96 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 97 | string ManagerDBusAdaptor::GetState(::DBus::Error &/*error*/) { |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 98 | return string(); |
| 99 | } |
| 100 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 101 | ::DBus::Path ManagerDBusAdaptor::CreateProfile(const string &name, |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 102 | ::DBus::Error &error) { |
| 103 | Error e; |
| 104 | string path; |
| 105 | manager_->CreateProfile(name, &path, &e); |
| 106 | e.ToDBusError(&error); |
| 107 | return ::DBus::Path(path); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Paul Stewart | e73d05c | 2012-03-29 16:26:05 -0700 | [diff] [blame] | 110 | void ManagerDBusAdaptor::RemoveProfile(const string &name, |
| 111 | ::DBus::Error &error) { |
| 112 | Error e; |
| 113 | manager_->RemoveProfile(name, &e); |
| 114 | e.ToDBusError(&error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 115 | } |
| 116 | |
mukesh agrawal | e5929bf | 2011-08-29 13:47:23 -0700 | [diff] [blame] | 117 | ::DBus::Path ManagerDBusAdaptor::PushProfile(const std::string &name, |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 118 | ::DBus::Error &error) { |
| 119 | Error e; |
| 120 | string path; |
| 121 | manager_->PushProfile(name, &path, &e); |
| 122 | e.ToDBusError(&error); |
| 123 | return ::DBus::Path(path); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 126 | void ManagerDBusAdaptor::PopProfile(const std::string &name, |
| 127 | ::DBus::Error &error) { |
| 128 | Error e; |
| 129 | manager_->PopProfile(name, &e); |
| 130 | e.ToDBusError(&error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 133 | void ManagerDBusAdaptor::PopAnyProfile(::DBus::Error &error) { |
| 134 | Error e; |
| 135 | manager_->PopAnyProfile(&e); |
| 136 | e.ToDBusError(&error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 139 | void ManagerDBusAdaptor::RecheckPortal(::DBus::Error &error) { |
| 140 | Error e; |
| 141 | manager_->RecheckPortal(&e); |
| 142 | e.ToDBusError(&error); |
| 143 | } |
| 144 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 145 | void ManagerDBusAdaptor::RequestScan(const string &technology, |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 146 | ::DBus::Error &error) { |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 147 | Error e; |
| 148 | manager_->RequestScan(technology, &e); |
| 149 | e.ToDBusError(&error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 152 | void ManagerDBusAdaptor::EnableTechnology(const string &technology_name, |
| 153 | ::DBus::Error &error) { |
| 154 | Error e(Error::kOperationInitiated); |
| 155 | DBus::Tag *tag = new DBus::Tag(); |
| 156 | manager_->EnableTechnology(technology_name, &e, GetMethodReplyCallback(tag)); |
| 157 | ReturnResultOrDefer(tag, e, &error); |
| 158 | // TODO(ers): A reply will be sent to the client as soon as the first |
| 159 | // device of a given technology has finished being enabled. It would |
| 160 | // seem arguably more correct to wait until all the devices were enabled. |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 163 | void ManagerDBusAdaptor::DisableTechnology(const string &technology_name, |
| 164 | ::DBus::Error &error) { |
| 165 | Error e(Error::kOperationInitiated); |
| 166 | DBus::Tag *tag = new DBus::Tag(); |
| 167 | manager_->DisableTechnology(technology_name, &e, GetMethodReplyCallback(tag)); |
| 168 | ReturnResultOrDefer(tag, e, &error); |
| 169 | // TODO(ers): A reply will be sent to the client as soon as the first |
| 170 | // device of a given technology has finished being disabled. It would |
| 171 | // seem arguably more correct to wait until all the devices were enabled. |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 174 | // Called, e.g., to get WiFiService handle for a hidden SSID. |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 175 | ::DBus::Path ManagerDBusAdaptor::GetService( |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 176 | const map<string, ::DBus::Variant> &args, |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 177 | ::DBus::Error &error) { |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 178 | ServiceRefPtr service; |
| 179 | KeyValueStore args_store; |
| 180 | Error e; |
| 181 | DBusAdaptor::ArgsToKeyValueStore(args, &args_store, &e); |
| 182 | if (e.IsSuccess()) { |
| 183 | service = manager_->GetService(args_store, &e); |
| 184 | } |
| 185 | if (e.ToDBusError(&error)) { |
| 186 | return "/"; // ensure return is syntactically valid |
| 187 | } |
| 188 | return service->GetRpcIdentifier(); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 191 | // Obsolete, use GetService instead. |
| 192 | ::DBus::Path ManagerDBusAdaptor::GetVPNService( |
| 193 | const map<string, ::DBus::Variant> &args, |
| 194 | ::DBus::Error &error) { |
| 195 | return GetService(args, error); |
| 196 | } |
| 197 | |
| 198 | // Obsolete, use GetService instead. |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 199 | ::DBus::Path ManagerDBusAdaptor::GetWifiService( |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 200 | const map<string, ::DBus::Variant> &args, |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 201 | ::DBus::Error &error) { |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 202 | return GetService(args, error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 205 | |
| 206 | void ManagerDBusAdaptor::ConfigureService( |
| 207 | const map<string, ::DBus::Variant> &args, |
| 208 | ::DBus::Error &error) { |
| 209 | KeyValueStore args_store; |
| 210 | Error e; |
| 211 | DBusAdaptor::ArgsToKeyValueStore(args, &args_store, &e); |
| 212 | if (e.IsSuccess()) { |
| 213 | manager_->ConfigureService(args_store, &e); |
| 214 | } |
| 215 | e.ToDBusError(&error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 218 | void ManagerDBusAdaptor::RegisterAgent(const ::DBus::Path &, |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 219 | ::DBus::Error &/*error*/) { |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 222 | void ManagerDBusAdaptor::UnregisterAgent(const ::DBus::Path &, |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 223 | ::DBus::Error &/*error*/) { |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 224 | } |
| 225 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 226 | int32_t ManagerDBusAdaptor::GetDebugLevel(::DBus::Error &/*error*/) { |
Chris Masone | 7ccc819 | 2011-05-24 14:54:49 -0700 | [diff] [blame] | 227 | return logging::GetMinLogLevel(); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 230 | void ManagerDBusAdaptor::SetDebugLevel(const int32_t &level, |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 231 | ::DBus::Error &/*error*/) { |
Ben Chan | bc49ac7 | 2012-04-10 19:59:45 -0700 | [diff] [blame] | 232 | if (level < logging::LOG_NUM_SEVERITIES) { |
Chris Masone | 7ccc819 | 2011-05-24 14:54:49 -0700 | [diff] [blame] | 233 | logging::SetMinLogLevel(level); |
Ben Chan | bc49ac7 | 2012-04-10 19:59:45 -0700 | [diff] [blame] | 234 | // Like VLOG, SLOG uses negative verbose level. |
| 235 | ScopeLogger::GetInstance()->set_verbose_level(-level); |
| 236 | } else { |
Chris Masone | 7ccc819 | 2011-05-24 14:54:49 -0700 | [diff] [blame] | 237 | LOG(WARNING) << "Ignoring attempt to set log level to " << level; |
Ben Chan | bc49ac7 | 2012-04-10 19:59:45 -0700 | [diff] [blame] | 238 | } |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 239 | } |
| 240 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 241 | string ManagerDBusAdaptor::GetServiceOrder(::DBus::Error &/*error*/) { |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 242 | return manager_->GetTechnologyOrder(); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 245 | void ManagerDBusAdaptor::SetServiceOrder(const string &order, |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 246 | ::DBus::Error &error) { |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 247 | Error e; |
| 248 | manager_->SetTechnologyOrder(order, &e); |
| 249 | e.ToDBusError(&error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Elly Jones | 16227d3 | 2012-02-09 14:17:25 -0500 | [diff] [blame] | 252 | std::string ManagerDBusAdaptor::GetDebugTags(::DBus::Error &/*error*/) { |
Ben Chan | bc49ac7 | 2012-04-10 19:59:45 -0700 | [diff] [blame] | 253 | return ScopeLogger::GetInstance()->GetEnabledScopeNames(); |
Elly Jones | 16227d3 | 2012-02-09 14:17:25 -0500 | [diff] [blame] | 254 | } |
| 255 | |
Ben Chan | bc49ac7 | 2012-04-10 19:59:45 -0700 | [diff] [blame] | 256 | void ManagerDBusAdaptor::SetDebugTags(const std::string &tags, |
Elly Jones | 16227d3 | 2012-02-09 14:17:25 -0500 | [diff] [blame] | 257 | ::DBus::Error &/*error*/) { |
Ben Chan | bc49ac7 | 2012-04-10 19:59:45 -0700 | [diff] [blame] | 258 | ScopeLogger::GetInstance()->EnableScopesByName(tags); |
Elly Jones | 16227d3 | 2012-02-09 14:17:25 -0500 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | std::string ManagerDBusAdaptor::ListDebugTags(::DBus::Error &/*error*/) { |
Ben Chan | bc49ac7 | 2012-04-10 19:59:45 -0700 | [diff] [blame] | 262 | return ScopeLogger::GetInstance()->GetAllScopeNames(); |
Elly Jones | 16227d3 | 2012-02-09 14:17:25 -0500 | [diff] [blame] | 263 | } |
| 264 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 265 | } // namespace shill |