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 |
| 27 | const char ManagerDBusAdaptor::kInterfaceName[] = SHILL_INTERFACE; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 28 | // static |
Chris Masone | 19e3040 | 2011-07-19 15:48:47 -0700 | [diff] [blame] | 29 | const char ManagerDBusAdaptor::kPath[] = "/"; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 30 | |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 31 | ManagerDBusAdaptor::ManagerDBusAdaptor(DBus::Connection* conn, Manager *manager) |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 32 | : DBusAdaptor(conn, kPath), |
| 33 | manager_(manager) { |
| 34 | } |
Chris Masone | ec6b18b | 2011-06-08 14:09:10 -0700 | [diff] [blame] | 35 | |
| 36 | ManagerDBusAdaptor::~ManagerDBusAdaptor() { |
| 37 | manager_ = NULL; |
| 38 | } |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 39 | |
| 40 | void ManagerDBusAdaptor::UpdateRunning() {} |
| 41 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 42 | void ManagerDBusAdaptor::EmitBoolChanged(const string &name, bool value) { |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 43 | PropertyChanged(name, DBusAdaptor::BoolToVariant(value)); |
| 44 | } |
| 45 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 46 | void ManagerDBusAdaptor::EmitUintChanged(const string &name, |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 47 | 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 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 51 | void ManagerDBusAdaptor::EmitIntChanged(const string &name, int value) { |
| 52 | PropertyChanged(name, DBusAdaptor::Int32ToVariant(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::EmitStringChanged(const string &name, |
| 56 | const string &value) { |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 57 | PropertyChanged(name, DBusAdaptor::StringToVariant(value)); |
| 58 | } |
| 59 | |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 60 | void ManagerDBusAdaptor::EmitStringsChanged(const string &name, |
| 61 | const vector<string> &value) { |
| 62 | PropertyChanged(name, DBusAdaptor::StringsToVariant(value)); |
| 63 | } |
| 64 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 65 | void ManagerDBusAdaptor::EmitRpcIdentifierArrayChanged( |
| 66 | const string &name, |
| 67 | const vector<string> &value) { |
| 68 | vector< ::DBus::Path> paths; |
| 69 | vector<string>::const_iterator it; |
| 70 | for (it = value.begin(); it != value.end(); ++it) { |
| 71 | paths.push_back(*it); |
| 72 | } |
| 73 | |
| 74 | PropertyChanged(name, DBusAdaptor::PathArrayToVariant(paths)); |
| 75 | } |
| 76 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 77 | void ManagerDBusAdaptor::EmitStateChanged(const string &new_state) { |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 78 | StateChanged(new_state); |
| 79 | } |
| 80 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 81 | map<string, ::DBus::Variant> ManagerDBusAdaptor::GetProperties( |
| 82 | ::DBus::Error &error) { |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 83 | map<string, ::DBus::Variant> properties; |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 84 | DBusAdaptor::GetProperties(manager_->store(), &properties, &error); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 85 | return properties; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 88 | void ManagerDBusAdaptor::SetProperty(const string &name, |
| 89 | const ::DBus::Variant &value, |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 90 | ::DBus::Error &error) { |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 91 | if (DBusAdaptor::SetProperty(manager_->mutable_store(), |
| 92 | name, |
| 93 | value, |
| 94 | &error)) { |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 95 | PropertyChanged(name, value); |
| 96 | } |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 97 | } |
| 98 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 99 | string ManagerDBusAdaptor::GetState(::DBus::Error &/*error*/) { |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 100 | return string(); |
| 101 | } |
| 102 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 103 | ::DBus::Path ManagerDBusAdaptor::CreateProfile(const string &name, |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 104 | ::DBus::Error &error) { |
| 105 | Error e; |
| 106 | string path; |
| 107 | manager_->CreateProfile(name, &path, &e); |
| 108 | e.ToDBusError(&error); |
| 109 | return ::DBus::Path(path); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 110 | } |
| 111 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 112 | void ManagerDBusAdaptor::RemoveProfile(const string &/*name*/, |
| 113 | ::DBus::Error &/*error*/) { |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 114 | } |
| 115 | |
mukesh agrawal | e5929bf | 2011-08-29 13:47:23 -0700 | [diff] [blame] | 116 | ::DBus::Path ManagerDBusAdaptor::PushProfile(const std::string &name, |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 117 | ::DBus::Error &error) { |
| 118 | Error e; |
| 119 | string path; |
| 120 | manager_->PushProfile(name, &path, &e); |
| 121 | e.ToDBusError(&error); |
| 122 | return ::DBus::Path(path); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 125 | void ManagerDBusAdaptor::PopProfile(const std::string &name, |
| 126 | ::DBus::Error &error) { |
| 127 | Error e; |
| 128 | manager_->PopProfile(name, &e); |
| 129 | e.ToDBusError(&error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 132 | void ManagerDBusAdaptor::PopAnyProfile(::DBus::Error &error) { |
| 133 | Error e; |
| 134 | manager_->PopAnyProfile(&e); |
| 135 | e.ToDBusError(&error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame^] | 138 | void ManagerDBusAdaptor::RecheckPortal(::DBus::Error &error) { |
| 139 | Error e; |
| 140 | manager_->RecheckPortal(&e); |
| 141 | e.ToDBusError(&error); |
| 142 | } |
| 143 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 144 | void ManagerDBusAdaptor::RequestScan(const string &technology, |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 145 | ::DBus::Error &error) { |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 146 | Error e; |
| 147 | manager_->RequestScan(technology, &e); |
| 148 | e.ToDBusError(&error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 151 | void ManagerDBusAdaptor::EnableTechnology(const string &, |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 152 | ::DBus::Error &/*error*/) { |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 155 | void ManagerDBusAdaptor::DisableTechnology(const string &, |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 156 | ::DBus::Error &/*error*/) { |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 159 | // Called, e.g., to get WiFiService handle for a hidden SSID. |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 160 | ::DBus::Path ManagerDBusAdaptor::GetService( |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 161 | const map<string, ::DBus::Variant> &args, |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 162 | ::DBus::Error &error) { |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 163 | ServiceRefPtr service; |
| 164 | KeyValueStore args_store; |
| 165 | Error e; |
| 166 | DBusAdaptor::ArgsToKeyValueStore(args, &args_store, &e); |
| 167 | if (e.IsSuccess()) { |
| 168 | service = manager_->GetService(args_store, &e); |
| 169 | } |
| 170 | if (e.ToDBusError(&error)) { |
| 171 | return "/"; // ensure return is syntactically valid |
| 172 | } |
| 173 | return service->GetRpcIdentifier(); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 176 | // Obsolete, use GetService instead. |
| 177 | ::DBus::Path ManagerDBusAdaptor::GetVPNService( |
| 178 | const map<string, ::DBus::Variant> &args, |
| 179 | ::DBus::Error &error) { |
| 180 | return GetService(args, error); |
| 181 | } |
| 182 | |
| 183 | // Obsolete, use GetService instead. |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 184 | ::DBus::Path ManagerDBusAdaptor::GetWifiService( |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 185 | const map<string, ::DBus::Variant> &args, |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 186 | ::DBus::Error &error) { |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 187 | return GetService(args, error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | void ManagerDBusAdaptor::ConfigureWifiService( |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 191 | const map<string, ::DBus::Variant> &, |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 192 | ::DBus::Error &/*error*/) { |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 195 | void ManagerDBusAdaptor::RegisterAgent(const ::DBus::Path &, |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 196 | ::DBus::Error &/*error*/) { |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 199 | void ManagerDBusAdaptor::UnregisterAgent(const ::DBus::Path &, |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 200 | ::DBus::Error &/*error*/) { |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 201 | } |
| 202 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 203 | int32_t ManagerDBusAdaptor::GetDebugLevel(::DBus::Error &/*error*/) { |
Chris Masone | 7ccc819 | 2011-05-24 14:54:49 -0700 | [diff] [blame] | 204 | return logging::GetMinLogLevel(); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 207 | void ManagerDBusAdaptor::SetDebugLevel(const int32_t &level, |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 208 | ::DBus::Error &/*error*/) { |
Chris Masone | 7ccc819 | 2011-05-24 14:54:49 -0700 | [diff] [blame] | 209 | if (level < logging::LOG_NUM_SEVERITIES) |
| 210 | logging::SetMinLogLevel(level); |
| 211 | else |
| 212 | LOG(WARNING) << "Ignoring attempt to set log level to " << level; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 213 | } |
| 214 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 215 | string ManagerDBusAdaptor::GetServiceOrder(::DBus::Error &/*error*/) { |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 216 | return manager_->GetTechnologyOrder(); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 219 | void ManagerDBusAdaptor::SetServiceOrder(const string &order, |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 220 | ::DBus::Error &error) { |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 221 | Error e; |
| 222 | manager_->SetTechnologyOrder(order, &e); |
| 223 | e.ToDBusError(&error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Elly Jones | 16227d3 | 2012-02-09 14:17:25 -0500 | [diff] [blame] | 226 | std::string ManagerDBusAdaptor::GetDebugTags(::DBus::Error &/*error*/) { |
| 227 | return ""; |
| 228 | } |
| 229 | |
| 230 | void ManagerDBusAdaptor::SetDebugTags(const std::string &/*tags*/, |
| 231 | ::DBus::Error &/*error*/) { |
| 232 | } |
| 233 | |
| 234 | std::string ManagerDBusAdaptor::ListDebugTags(::DBus::Error &/*error*/) { |
| 235 | return ""; |
| 236 | } |
| 237 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 238 | } // namespace shill |