blob: 0a1adcbfc14b63a226e2074d38be6df6a24c7bfb [file] [log] [blame]
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -08001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Chris Masoned7732e42011-05-20 11:08:56 -07002// 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 Masone8fe2c7e2011-06-09 15:51:19 -07009#include <vector>
Chris Masoned7732e42011-05-20 11:08:56 -070010
Chris Masone8fe2c7e2011-06-09 15:51:19 -070011#include <dbus-c++/dbus.h>
12
mukesh agrawal32399322011-09-01 10:53:43 -070013#include "shill/device.h"
Chris Masone8fe2c7e2011-06-09 15:51:19 -070014#include "shill/error.h"
mukesh agrawal7a4e4002011-09-06 11:26:05 -070015#include "shill/key_value_store.h"
Chris Masone8fe2c7e2011-06-09 15:51:19 -070016#include "shill/manager.h"
Ben Chanbc49ac72012-04-10 19:59:45 -070017#include "shill/scope_logger.h"
mukesh agrawal7a4e4002011-09-06 11:26:05 -070018#include "shill/wifi_service.h"
Chris Masone7ccc8192011-05-24 14:54:49 -070019
Chris Masoned7732e42011-05-20 11:08:56 -070020using std::map;
21using std::string;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070022using std::vector;
Chris Masoned7732e42011-05-20 11:08:56 -070023
24namespace shill {
25
Chris Masoned7732e42011-05-20 11:08:56 -070026// static
Chris Masone19e30402011-07-19 15:48:47 -070027const char ManagerDBusAdaptor::kPath[] = "/";
Chris Masoned7732e42011-05-20 11:08:56 -070028
Chris Masoned0ceb8c2011-06-02 10:05:39 -070029ManagerDBusAdaptor::ManagerDBusAdaptor(DBus::Connection* conn, Manager *manager)
Chris Masoned7732e42011-05-20 11:08:56 -070030 : DBusAdaptor(conn, kPath),
31 manager_(manager) {
32}
Chris Masoneec6b18b2011-06-08 14:09:10 -070033
34ManagerDBusAdaptor::~ManagerDBusAdaptor() {
35 manager_ = NULL;
36}
Chris Masoned7732e42011-05-20 11:08:56 -070037
38void ManagerDBusAdaptor::UpdateRunning() {}
39
Chris Masone8fe2c7e2011-06-09 15:51:19 -070040void ManagerDBusAdaptor::EmitBoolChanged(const string &name, bool value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070041 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masoned0ceb8c2011-06-02 10:05:39 -070042 PropertyChanged(name, DBusAdaptor::BoolToVariant(value));
43}
44
Chris Masone8fe2c7e2011-06-09 15:51:19 -070045void ManagerDBusAdaptor::EmitUintChanged(const string &name,
Chris Masoned0ceb8c2011-06-02 10:05:39 -070046 uint32 value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070047 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070048 PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value));
Chris Masoned0ceb8c2011-06-02 10:05:39 -070049}
50
Chris Masone8fe2c7e2011-06-09 15:51:19 -070051void ManagerDBusAdaptor::EmitIntChanged(const string &name, int value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070052 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070053 PropertyChanged(name, DBusAdaptor::Int32ToVariant(value));
Chris Masoned0ceb8c2011-06-02 10:05:39 -070054}
55
Chris Masone8fe2c7e2011-06-09 15:51:19 -070056void ManagerDBusAdaptor::EmitStringChanged(const string &name,
57 const string &value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070058 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masoned0ceb8c2011-06-02 10:05:39 -070059 PropertyChanged(name, DBusAdaptor::StringToVariant(value));
60}
61
Gaurav Shah435de2c2011-11-17 19:01:07 -080062void ManagerDBusAdaptor::EmitStringsChanged(const string &name,
63 const vector<string> &value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070064 SLOG(DBus, 2) << __func__ << ": " << name;
Gaurav Shah435de2c2011-11-17 19:01:07 -080065 PropertyChanged(name, DBusAdaptor::StringsToVariant(value));
66}
67
mukesh agrawal32399322011-09-01 10:53:43 -070068void ManagerDBusAdaptor::EmitRpcIdentifierArrayChanged(
69 const string &name,
70 const vector<string> &value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070071 SLOG(DBus, 2) << __func__ << ": " << name;
mukesh agrawal32399322011-09-01 10:53:43 -070072 vector< ::DBus::Path> paths;
73 vector<string>::const_iterator it;
74 for (it = value.begin(); it != value.end(); ++it) {
75 paths.push_back(*it);
76 }
77
mukesh agrawal2366eed2012-03-20 18:21:50 -070078 PropertyChanged(name, DBusAdaptor::PathsToVariant(paths));
mukesh agrawal32399322011-09-01 10:53:43 -070079}
80
Chris Masone8fe2c7e2011-06-09 15:51:19 -070081void ManagerDBusAdaptor::EmitStateChanged(const string &new_state) {
mukesh agrawal06175d72012-04-23 16:46:01 -070082 SLOG(DBus, 2) << __func__;
Chris Masoned0ceb8c2011-06-02 10:05:39 -070083 StateChanged(new_state);
84}
85
Chris Masoned7732e42011-05-20 11:08:56 -070086map<string, ::DBus::Variant> ManagerDBusAdaptor::GetProperties(
87 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070088 SLOG(DBus, 2) << __func__;
Chris Masonea8a2c252011-06-27 22:16:30 -070089 map<string, ::DBus::Variant> properties;
Chris Masone27c4aa52011-07-02 13:10:14 -070090 DBusAdaptor::GetProperties(manager_->store(), &properties, &error);
Chris Masonea8a2c252011-06-27 22:16:30 -070091 return properties;
Chris Masoned7732e42011-05-20 11:08:56 -070092}
93
Chris Masone8fe2c7e2011-06-09 15:51:19 -070094void ManagerDBusAdaptor::SetProperty(const string &name,
95 const ::DBus::Variant &value,
Chris Masoned7732e42011-05-20 11:08:56 -070096 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070097 SLOG(DBus, 2) << __func__ << ": " << name;
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -080098 if (DBusAdaptor::SetProperty(manager_->mutable_store(),
99 name,
100 value,
101 &error)) {
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700102 PropertyChanged(name, value);
103 }
Chris Masoned7732e42011-05-20 11:08:56 -0700104}
105
mukesh agrawal1830fa12011-09-26 14:31:40 -0700106string ManagerDBusAdaptor::GetState(::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700107 SLOG(DBus, 2) << __func__;
Paul Stewart38fd24c2012-04-25 14:06:29 -0700108 return manager_->CalculateState(NULL);
Chris Masoned7732e42011-05-20 11:08:56 -0700109}
110
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700111::DBus::Path ManagerDBusAdaptor::CreateProfile(const string &name,
Paul Stewart19c871d2011-12-15 16:10:13 -0800112 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700113 SLOG(DBus, 2) << __func__ << ": " << name;
Paul Stewart19c871d2011-12-15 16:10:13 -0800114 Error e;
115 string path;
116 manager_->CreateProfile(name, &path, &e);
117 e.ToDBusError(&error);
118 return ::DBus::Path(path);
Chris Masoned7732e42011-05-20 11:08:56 -0700119}
120
Paul Stewarte73d05c2012-03-29 16:26:05 -0700121void ManagerDBusAdaptor::RemoveProfile(const string &name,
122 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700123 SLOG(DBus, 2) << __func__ << ": " << name;
Paul Stewarte73d05c2012-03-29 16:26:05 -0700124 Error e;
125 manager_->RemoveProfile(name, &e);
126 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700127}
128
mukesh agrawale5929bf2011-08-29 13:47:23 -0700129::DBus::Path ManagerDBusAdaptor::PushProfile(const std::string &name,
Paul Stewart19c871d2011-12-15 16:10:13 -0800130 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700131 SLOG(DBus, 2) << __func__ << ": " << name;
Paul Stewart19c871d2011-12-15 16:10:13 -0800132 Error e;
133 string path;
134 manager_->PushProfile(name, &path, &e);
135 e.ToDBusError(&error);
136 return ::DBus::Path(path);
Chris Masoneccc88812011-06-08 18:00:10 -0700137}
138
Paul Stewart19c871d2011-12-15 16:10:13 -0800139void ManagerDBusAdaptor::PopProfile(const std::string &name,
140 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700141 SLOG(DBus, 2) << __func__ << ": " << name;
Paul Stewart19c871d2011-12-15 16:10:13 -0800142 Error e;
143 manager_->PopProfile(name, &e);
144 e.ToDBusError(&error);
Chris Masoneccc88812011-06-08 18:00:10 -0700145}
146
Paul Stewart19c871d2011-12-15 16:10:13 -0800147void ManagerDBusAdaptor::PopAnyProfile(::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700148 SLOG(DBus, 2) << __func__;
Paul Stewart19c871d2011-12-15 16:10:13 -0800149 Error e;
150 manager_->PopAnyProfile(&e);
151 e.ToDBusError(&error);
Chris Masoneccc88812011-06-08 18:00:10 -0700152}
153
Paul Stewartc681fa02012-03-02 19:40:04 -0800154void ManagerDBusAdaptor::RecheckPortal(::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700155 SLOG(DBus, 2) << __func__;
Paul Stewartc681fa02012-03-02 19:40:04 -0800156 Error e;
157 manager_->RecheckPortal(&e);
158 e.ToDBusError(&error);
159}
160
mukesh agrawal32399322011-09-01 10:53:43 -0700161void ManagerDBusAdaptor::RequestScan(const string &technology,
Chris Masoned7732e42011-05-20 11:08:56 -0700162 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700163 SLOG(DBus, 2) << __func__ << ": " << technology;
mukesh agrawal32399322011-09-01 10:53:43 -0700164 Error e;
165 manager_->RequestScan(technology, &e);
166 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700167}
168
Eric Shienbrood9a245532012-03-07 14:20:39 -0500169void ManagerDBusAdaptor::EnableTechnology(const string &technology_name,
170 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700171 SLOG(DBus, 2) << __func__ << ": " << technology_name;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500172 Error e(Error::kOperationInitiated);
173 DBus::Tag *tag = new DBus::Tag();
174 manager_->EnableTechnology(technology_name, &e, GetMethodReplyCallback(tag));
175 ReturnResultOrDefer(tag, e, &error);
176 // TODO(ers): A reply will be sent to the client as soon as the first
177 // device of a given technology has finished being enabled. It would
178 // seem arguably more correct to wait until all the devices were enabled.
Chris Masoned7732e42011-05-20 11:08:56 -0700179}
180
Eric Shienbrood9a245532012-03-07 14:20:39 -0500181void ManagerDBusAdaptor::DisableTechnology(const string &technology_name,
182 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700183 SLOG(DBus, 2) << __func__ << ": " << technology_name;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500184 Error e(Error::kOperationInitiated);
185 DBus::Tag *tag = new DBus::Tag();
186 manager_->DisableTechnology(technology_name, &e, GetMethodReplyCallback(tag));
187 ReturnResultOrDefer(tag, e, &error);
188 // TODO(ers): A reply will be sent to the client as soon as the first
189 // device of a given technology has finished being disabled. It would
190 // seem arguably more correct to wait until all the devices were enabled.
Chris Masoned7732e42011-05-20 11:08:56 -0700191}
192
Darin Petkovb65c2452012-02-23 15:17:06 +0100193// Called, e.g., to get WiFiService handle for a hidden SSID.
Chris Masoned7732e42011-05-20 11:08:56 -0700194::DBus::Path ManagerDBusAdaptor::GetService(
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700195 const map<string, ::DBus::Variant> &args,
Chris Masoned7732e42011-05-20 11:08:56 -0700196 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700197 SLOG(DBus, 2) << __func__;
Darin Petkovb65c2452012-02-23 15:17:06 +0100198 ServiceRefPtr service;
199 KeyValueStore args_store;
200 Error e;
201 DBusAdaptor::ArgsToKeyValueStore(args, &args_store, &e);
202 if (e.IsSuccess()) {
203 service = manager_->GetService(args_store, &e);
204 }
205 if (e.ToDBusError(&error)) {
206 return "/"; // ensure return is syntactically valid
207 }
208 return service->GetRpcIdentifier();
Chris Masoned7732e42011-05-20 11:08:56 -0700209}
210
Darin Petkovb65c2452012-02-23 15:17:06 +0100211// Obsolete, use GetService instead.
212::DBus::Path ManagerDBusAdaptor::GetVPNService(
213 const map<string, ::DBus::Variant> &args,
214 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700215 SLOG(DBus, 2) << __func__;
Darin Petkovb65c2452012-02-23 15:17:06 +0100216 return GetService(args, error);
217}
218
219// Obsolete, use GetService instead.
Chris Masoned7732e42011-05-20 11:08:56 -0700220::DBus::Path ManagerDBusAdaptor::GetWifiService(
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700221 const map<string, ::DBus::Variant> &args,
Chris Masoned7732e42011-05-20 11:08:56 -0700222 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700223 SLOG(DBus, 2) << __func__;
Darin Petkovb65c2452012-02-23 15:17:06 +0100224 return GetService(args, error);
Chris Masoned7732e42011-05-20 11:08:56 -0700225}
226
Paul Stewart7f61e522012-03-22 11:13:45 -0700227
228void ManagerDBusAdaptor::ConfigureService(
229 const map<string, ::DBus::Variant> &args,
230 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700231 SLOG(DBus, 2) << __func__;
Paul Stewart7f61e522012-03-22 11:13:45 -0700232 KeyValueStore args_store;
233 Error e;
234 DBusAdaptor::ArgsToKeyValueStore(args, &args_store, &e);
235 if (e.IsSuccess()) {
236 manager_->ConfigureService(args_store, &e);
237 }
238 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700239}
240
mukesh agrawal1830fa12011-09-26 14:31:40 -0700241int32_t ManagerDBusAdaptor::GetDebugLevel(::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700242 SLOG(DBus, 2) << __func__;
Chris Masone7ccc8192011-05-24 14:54:49 -0700243 return logging::GetMinLogLevel();
Chris Masoned7732e42011-05-20 11:08:56 -0700244}
245
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700246void ManagerDBusAdaptor::SetDebugLevel(const int32_t &level,
mukesh agrawal1830fa12011-09-26 14:31:40 -0700247 ::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700248 SLOG(DBus, 2) << __func__ << ": " << level;
Ben Chanbc49ac72012-04-10 19:59:45 -0700249 if (level < logging::LOG_NUM_SEVERITIES) {
Chris Masone7ccc8192011-05-24 14:54:49 -0700250 logging::SetMinLogLevel(level);
Ben Chanbc49ac72012-04-10 19:59:45 -0700251 // Like VLOG, SLOG uses negative verbose level.
252 ScopeLogger::GetInstance()->set_verbose_level(-level);
253 } else {
Chris Masone7ccc8192011-05-24 14:54:49 -0700254 LOG(WARNING) << "Ignoring attempt to set log level to " << level;
Ben Chanbc49ac72012-04-10 19:59:45 -0700255 }
Chris Masoned7732e42011-05-20 11:08:56 -0700256}
257
mukesh agrawal1830fa12011-09-26 14:31:40 -0700258string ManagerDBusAdaptor::GetServiceOrder(::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700259 SLOG(DBus, 2) << __func__;
Paul Stewart22aa71b2011-09-16 12:15:11 -0700260 return manager_->GetTechnologyOrder();
Chris Masoned7732e42011-05-20 11:08:56 -0700261}
262
Paul Stewart22aa71b2011-09-16 12:15:11 -0700263void ManagerDBusAdaptor::SetServiceOrder(const string &order,
Chris Masoned7732e42011-05-20 11:08:56 -0700264 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700265 SLOG(DBus, 2) << __func__ << ": " << order;
Paul Stewart22aa71b2011-09-16 12:15:11 -0700266 Error e;
267 manager_->SetTechnologyOrder(order, &e);
268 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700269}
270
Elly Jones16227d32012-02-09 14:17:25 -0500271std::string ManagerDBusAdaptor::GetDebugTags(::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700272 SLOG(DBus, 2) << __func__;
Ben Chanbc49ac72012-04-10 19:59:45 -0700273 return ScopeLogger::GetInstance()->GetEnabledScopeNames();
Elly Jones16227d32012-02-09 14:17:25 -0500274}
275
Ben Chanbc49ac72012-04-10 19:59:45 -0700276void ManagerDBusAdaptor::SetDebugTags(const std::string &tags,
Elly Jones16227d32012-02-09 14:17:25 -0500277 ::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700278 SLOG(DBus, 2) << __func__ << ": " << tags;
Ben Chanbc49ac72012-04-10 19:59:45 -0700279 ScopeLogger::GetInstance()->EnableScopesByName(tags);
Elly Jones16227d32012-02-09 14:17:25 -0500280}
281
282std::string ManagerDBusAdaptor::ListDebugTags(::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700283 SLOG(DBus, 2) << __func__;
Ben Chanbc49ac72012-04-10 19:59:45 -0700284 return ScopeLogger::GetInstance()->GetAllScopeNames();
Elly Jones16227d32012-02-09 14:17:25 -0500285}
286
Chris Masoned7732e42011-05-20 11:08:56 -0700287} // namespace shill