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 | 7ccc819 | 2011-05-24 14:54:49 -0700 | [diff] [blame] | 11 | #include <base/logging.h> |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 12 | #include <dbus-c++/dbus.h> |
| 13 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 14 | #include "shill/device.h" |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 15 | #include "shill/error.h" |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 16 | #include "shill/key_value_store.h" |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 17 | #include "shill/manager.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 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 110 | void ManagerDBusAdaptor::RemoveProfile(const string &/*name*/, |
| 111 | ::DBus::Error &/*error*/) { |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 112 | } |
| 113 | |
mukesh agrawal | e5929bf | 2011-08-29 13:47:23 -0700 | [diff] [blame] | 114 | ::DBus::Path ManagerDBusAdaptor::PushProfile(const std::string &name, |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 115 | ::DBus::Error &error) { |
| 116 | Error e; |
| 117 | string path; |
| 118 | manager_->PushProfile(name, &path, &e); |
| 119 | e.ToDBusError(&error); |
| 120 | return ::DBus::Path(path); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 123 | void ManagerDBusAdaptor::PopProfile(const std::string &name, |
| 124 | ::DBus::Error &error) { |
| 125 | Error e; |
| 126 | manager_->PopProfile(name, &e); |
| 127 | e.ToDBusError(&error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 130 | void ManagerDBusAdaptor::PopAnyProfile(::DBus::Error &error) { |
| 131 | Error e; |
| 132 | manager_->PopAnyProfile(&e); |
| 133 | e.ToDBusError(&error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 136 | void ManagerDBusAdaptor::RecheckPortal(::DBus::Error &error) { |
| 137 | Error e; |
| 138 | manager_->RecheckPortal(&e); |
| 139 | e.ToDBusError(&error); |
| 140 | } |
| 141 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 142 | void ManagerDBusAdaptor::RequestScan(const string &technology, |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 143 | ::DBus::Error &error) { |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 144 | Error e; |
| 145 | manager_->RequestScan(technology, &e); |
| 146 | e.ToDBusError(&error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 149 | void ManagerDBusAdaptor::EnableTechnology(const string &, |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 150 | ::DBus::Error &/*error*/) { |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 153 | void ManagerDBusAdaptor::DisableTechnology(const string &, |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 154 | ::DBus::Error &/*error*/) { |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 157 | // Called, e.g., to get WiFiService handle for a hidden SSID. |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 158 | ::DBus::Path ManagerDBusAdaptor::GetService( |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 159 | const map<string, ::DBus::Variant> &args, |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 160 | ::DBus::Error &error) { |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 161 | ServiceRefPtr service; |
| 162 | KeyValueStore args_store; |
| 163 | Error e; |
| 164 | DBusAdaptor::ArgsToKeyValueStore(args, &args_store, &e); |
| 165 | if (e.IsSuccess()) { |
| 166 | service = manager_->GetService(args_store, &e); |
| 167 | } |
| 168 | if (e.ToDBusError(&error)) { |
| 169 | return "/"; // ensure return is syntactically valid |
| 170 | } |
| 171 | return service->GetRpcIdentifier(); |
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 | // Obsolete, use GetService instead. |
| 175 | ::DBus::Path ManagerDBusAdaptor::GetVPNService( |
| 176 | const map<string, ::DBus::Variant> &args, |
| 177 | ::DBus::Error &error) { |
| 178 | return GetService(args, error); |
| 179 | } |
| 180 | |
| 181 | // Obsolete, use GetService instead. |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 182 | ::DBus::Path ManagerDBusAdaptor::GetWifiService( |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 183 | const map<string, ::DBus::Variant> &args, |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 184 | ::DBus::Error &error) { |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 185 | return GetService(args, error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | void ManagerDBusAdaptor::ConfigureWifiService( |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 189 | const map<string, ::DBus::Variant> &, |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 190 | ::DBus::Error &/*error*/) { |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 193 | void ManagerDBusAdaptor::RegisterAgent(const ::DBus::Path &, |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 194 | ::DBus::Error &/*error*/) { |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 197 | void ManagerDBusAdaptor::UnregisterAgent(const ::DBus::Path &, |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 198 | ::DBus::Error &/*error*/) { |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 199 | } |
| 200 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 201 | int32_t ManagerDBusAdaptor::GetDebugLevel(::DBus::Error &/*error*/) { |
Chris Masone | 7ccc819 | 2011-05-24 14:54:49 -0700 | [diff] [blame] | 202 | return logging::GetMinLogLevel(); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 205 | void ManagerDBusAdaptor::SetDebugLevel(const int32_t &level, |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 206 | ::DBus::Error &/*error*/) { |
Chris Masone | 7ccc819 | 2011-05-24 14:54:49 -0700 | [diff] [blame] | 207 | if (level < logging::LOG_NUM_SEVERITIES) |
| 208 | logging::SetMinLogLevel(level); |
| 209 | else |
| 210 | LOG(WARNING) << "Ignoring attempt to set log level to " << level; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 211 | } |
| 212 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 213 | string ManagerDBusAdaptor::GetServiceOrder(::DBus::Error &/*error*/) { |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 214 | return manager_->GetTechnologyOrder(); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 217 | void ManagerDBusAdaptor::SetServiceOrder(const string &order, |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 218 | ::DBus::Error &error) { |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 219 | Error e; |
| 220 | manager_->SetTechnologyOrder(order, &e); |
| 221 | e.ToDBusError(&error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Elly Jones | 16227d3 | 2012-02-09 14:17:25 -0500 | [diff] [blame] | 224 | std::string ManagerDBusAdaptor::GetDebugTags(::DBus::Error &/*error*/) { |
| 225 | return ""; |
| 226 | } |
| 227 | |
| 228 | void ManagerDBusAdaptor::SetDebugTags(const std::string &/*tags*/, |
| 229 | ::DBus::Error &/*error*/) { |
| 230 | } |
| 231 | |
| 232 | std::string ManagerDBusAdaptor::ListDebugTags(::DBus::Error &/*error*/) { |
| 233 | return ""; |
| 234 | } |
| 235 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 236 | } // namespace shill |