blob: e93b61560cca4384204cee426de54d454aa96197 [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"
Christopher Wileyb691efd2012-08-09 13:51:51 -070016#include "shill/logging.h"
Chris Masone8fe2c7e2011-06-09 15:51:19 -070017#include "shill/manager.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
Paul Stewart49739c02012-08-08 17:24:03 -070068void ManagerDBusAdaptor::EmitRpcIdentifierChanged(
69 const string &name,
70 const string &value) {
71 SLOG(DBus, 2) << __func__ << ": " << name;
72 PropertyChanged(name, DBusAdaptor::PathToVariant(value));
73}
74
mukesh agrawal32399322011-09-01 10:53:43 -070075void ManagerDBusAdaptor::EmitRpcIdentifierArrayChanged(
76 const string &name,
77 const vector<string> &value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070078 SLOG(DBus, 2) << __func__ << ": " << name;
mukesh agrawal32399322011-09-01 10:53:43 -070079 vector< ::DBus::Path> paths;
80 vector<string>::const_iterator it;
81 for (it = value.begin(); it != value.end(); ++it) {
82 paths.push_back(*it);
83 }
84
mukesh agrawal2366eed2012-03-20 18:21:50 -070085 PropertyChanged(name, DBusAdaptor::PathsToVariant(paths));
mukesh agrawal32399322011-09-01 10:53:43 -070086}
87
Chris Masone8fe2c7e2011-06-09 15:51:19 -070088void ManagerDBusAdaptor::EmitStateChanged(const string &new_state) {
mukesh agrawal06175d72012-04-23 16:46:01 -070089 SLOG(DBus, 2) << __func__;
Chris Masoned0ceb8c2011-06-02 10:05:39 -070090 StateChanged(new_state);
91}
92
Chris Masoned7732e42011-05-20 11:08:56 -070093map<string, ::DBus::Variant> ManagerDBusAdaptor::GetProperties(
94 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070095 SLOG(DBus, 2) << __func__;
Chris Masonea8a2c252011-06-27 22:16:30 -070096 map<string, ::DBus::Variant> properties;
Chris Masone27c4aa52011-07-02 13:10:14 -070097 DBusAdaptor::GetProperties(manager_->store(), &properties, &error);
Chris Masonea8a2c252011-06-27 22:16:30 -070098 return properties;
Chris Masoned7732e42011-05-20 11:08:56 -070099}
100
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700101void ManagerDBusAdaptor::SetProperty(const string &name,
102 const ::DBus::Variant &value,
Chris Masoned7732e42011-05-20 11:08:56 -0700103 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700104 SLOG(DBus, 2) << __func__ << ": " << name;
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -0800105 if (DBusAdaptor::SetProperty(manager_->mutable_store(),
106 name,
107 value,
108 &error)) {
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700109 PropertyChanged(name, value);
110 }
Chris Masoned7732e42011-05-20 11:08:56 -0700111}
112
mukesh agrawal1830fa12011-09-26 14:31:40 -0700113string ManagerDBusAdaptor::GetState(::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700114 SLOG(DBus, 2) << __func__;
Paul Stewart38fd24c2012-04-25 14:06:29 -0700115 return manager_->CalculateState(NULL);
Chris Masoned7732e42011-05-20 11:08:56 -0700116}
117
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700118::DBus::Path ManagerDBusAdaptor::CreateProfile(const string &name,
Paul Stewart19c871d2011-12-15 16:10:13 -0800119 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700120 SLOG(DBus, 2) << __func__ << ": " << name;
Paul Stewart19c871d2011-12-15 16:10:13 -0800121 Error e;
122 string path;
123 manager_->CreateProfile(name, &path, &e);
124 e.ToDBusError(&error);
125 return ::DBus::Path(path);
Chris Masoned7732e42011-05-20 11:08:56 -0700126}
127
Paul Stewarte73d05c2012-03-29 16:26:05 -0700128void ManagerDBusAdaptor::RemoveProfile(const string &name,
129 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700130 SLOG(DBus, 2) << __func__ << ": " << name;
Paul Stewarte73d05c2012-03-29 16:26:05 -0700131 Error e;
132 manager_->RemoveProfile(name, &e);
133 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700134}
135
mukesh agrawale5929bf2011-08-29 13:47:23 -0700136::DBus::Path ManagerDBusAdaptor::PushProfile(const std::string &name,
Paul Stewart19c871d2011-12-15 16:10:13 -0800137 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700138 SLOG(DBus, 2) << __func__ << ": " << name;
Paul Stewart19c871d2011-12-15 16:10:13 -0800139 Error e;
140 string path;
141 manager_->PushProfile(name, &path, &e);
142 e.ToDBusError(&error);
143 return ::DBus::Path(path);
Chris Masoneccc88812011-06-08 18:00:10 -0700144}
145
Paul Stewart19c871d2011-12-15 16:10:13 -0800146void ManagerDBusAdaptor::PopProfile(const std::string &name,
147 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700148 SLOG(DBus, 2) << __func__ << ": " << name;
Paul Stewart19c871d2011-12-15 16:10:13 -0800149 Error e;
150 manager_->PopProfile(name, &e);
151 e.ToDBusError(&error);
Chris Masoneccc88812011-06-08 18:00:10 -0700152}
153
Paul Stewart19c871d2011-12-15 16:10:13 -0800154void ManagerDBusAdaptor::PopAnyProfile(::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700155 SLOG(DBus, 2) << __func__;
Paul Stewart19c871d2011-12-15 16:10:13 -0800156 Error e;
157 manager_->PopAnyProfile(&e);
158 e.ToDBusError(&error);
Chris Masoneccc88812011-06-08 18:00:10 -0700159}
160
Paul Stewartc681fa02012-03-02 19:40:04 -0800161void ManagerDBusAdaptor::RecheckPortal(::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700162 SLOG(DBus, 2) << __func__;
Paul Stewartc681fa02012-03-02 19:40:04 -0800163 Error e;
164 manager_->RecheckPortal(&e);
165 e.ToDBusError(&error);
166}
167
mukesh agrawal32399322011-09-01 10:53:43 -0700168void ManagerDBusAdaptor::RequestScan(const string &technology,
Chris Masoned7732e42011-05-20 11:08:56 -0700169 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700170 SLOG(DBus, 2) << __func__ << ": " << technology;
mukesh agrawal32399322011-09-01 10:53:43 -0700171 Error e;
172 manager_->RequestScan(technology, &e);
173 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700174}
175
Eric Shienbrood9a245532012-03-07 14:20:39 -0500176void ManagerDBusAdaptor::EnableTechnology(const string &technology_name,
177 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700178 SLOG(DBus, 2) << __func__ << ": " << technology_name;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500179 Error e(Error::kOperationInitiated);
180 DBus::Tag *tag = new DBus::Tag();
181 manager_->EnableTechnology(technology_name, &e, GetMethodReplyCallback(tag));
182 ReturnResultOrDefer(tag, e, &error);
183 // TODO(ers): A reply will be sent to the client as soon as the first
184 // device of a given technology has finished being enabled. It would
185 // seem arguably more correct to wait until all the devices were enabled.
Chris Masoned7732e42011-05-20 11:08:56 -0700186}
187
Eric Shienbrood9a245532012-03-07 14:20:39 -0500188void ManagerDBusAdaptor::DisableTechnology(const string &technology_name,
189 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700190 SLOG(DBus, 2) << __func__ << ": " << technology_name;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500191 Error e(Error::kOperationInitiated);
192 DBus::Tag *tag = new DBus::Tag();
193 manager_->DisableTechnology(technology_name, &e, GetMethodReplyCallback(tag));
194 ReturnResultOrDefer(tag, e, &error);
195 // TODO(ers): A reply will be sent to the client as soon as the first
196 // device of a given technology has finished being disabled. It would
197 // seem arguably more correct to wait until all the devices were enabled.
Chris Masoned7732e42011-05-20 11:08:56 -0700198}
199
Darin Petkovb65c2452012-02-23 15:17:06 +0100200// Called, e.g., to get WiFiService handle for a hidden SSID.
Chris Masoned7732e42011-05-20 11:08:56 -0700201::DBus::Path ManagerDBusAdaptor::GetService(
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700202 const map<string, ::DBus::Variant> &args,
Chris Masoned7732e42011-05-20 11:08:56 -0700203 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700204 SLOG(DBus, 2) << __func__;
Darin Petkovb65c2452012-02-23 15:17:06 +0100205 ServiceRefPtr service;
206 KeyValueStore args_store;
207 Error e;
208 DBusAdaptor::ArgsToKeyValueStore(args, &args_store, &e);
209 if (e.IsSuccess()) {
210 service = manager_->GetService(args_store, &e);
211 }
212 if (e.ToDBusError(&error)) {
213 return "/"; // ensure return is syntactically valid
214 }
215 return service->GetRpcIdentifier();
Chris Masoned7732e42011-05-20 11:08:56 -0700216}
217
Darin Petkovb65c2452012-02-23 15:17:06 +0100218// Obsolete, use GetService instead.
219::DBus::Path ManagerDBusAdaptor::GetVPNService(
220 const map<string, ::DBus::Variant> &args,
221 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700222 SLOG(DBus, 2) << __func__;
Darin Petkovb65c2452012-02-23 15:17:06 +0100223 return GetService(args, error);
224}
225
226// Obsolete, use GetService instead.
Chris Masoned7732e42011-05-20 11:08:56 -0700227::DBus::Path ManagerDBusAdaptor::GetWifiService(
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700228 const map<string, ::DBus::Variant> &args,
Chris Masoned7732e42011-05-20 11:08:56 -0700229 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700230 SLOG(DBus, 2) << __func__;
Darin Petkovb65c2452012-02-23 15:17:06 +0100231 return GetService(args, error);
Chris Masoned7732e42011-05-20 11:08:56 -0700232}
233
Paul Stewart7f61e522012-03-22 11:13:45 -0700234
235void ManagerDBusAdaptor::ConfigureService(
236 const map<string, ::DBus::Variant> &args,
237 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700238 SLOG(DBus, 2) << __func__;
Paul Stewart7f61e522012-03-22 11:13:45 -0700239 KeyValueStore args_store;
240 Error e;
241 DBusAdaptor::ArgsToKeyValueStore(args, &args_store, &e);
242 if (e.IsSuccess()) {
243 manager_->ConfigureService(args_store, &e);
244 }
245 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700246}
247
mukesh agrawal1830fa12011-09-26 14:31:40 -0700248int32_t ManagerDBusAdaptor::GetDebugLevel(::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700249 SLOG(DBus, 2) << __func__;
Chris Masone7ccc8192011-05-24 14:54:49 -0700250 return logging::GetMinLogLevel();
Chris Masoned7732e42011-05-20 11:08:56 -0700251}
252
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700253void ManagerDBusAdaptor::SetDebugLevel(const int32_t &level,
mukesh agrawal1830fa12011-09-26 14:31:40 -0700254 ::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700255 SLOG(DBus, 2) << __func__ << ": " << level;
Ben Chanbc49ac72012-04-10 19:59:45 -0700256 if (level < logging::LOG_NUM_SEVERITIES) {
Chris Masone7ccc8192011-05-24 14:54:49 -0700257 logging::SetMinLogLevel(level);
Ben Chanbc49ac72012-04-10 19:59:45 -0700258 // Like VLOG, SLOG uses negative verbose level.
259 ScopeLogger::GetInstance()->set_verbose_level(-level);
260 } else {
Chris Masone7ccc8192011-05-24 14:54:49 -0700261 LOG(WARNING) << "Ignoring attempt to set log level to " << level;
Ben Chanbc49ac72012-04-10 19:59:45 -0700262 }
Chris Masoned7732e42011-05-20 11:08:56 -0700263}
264
mukesh agrawal1830fa12011-09-26 14:31:40 -0700265string ManagerDBusAdaptor::GetServiceOrder(::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700266 SLOG(DBus, 2) << __func__;
Paul Stewart22aa71b2011-09-16 12:15:11 -0700267 return manager_->GetTechnologyOrder();
Chris Masoned7732e42011-05-20 11:08:56 -0700268}
269
Paul Stewart22aa71b2011-09-16 12:15:11 -0700270void ManagerDBusAdaptor::SetServiceOrder(const string &order,
Chris Masoned7732e42011-05-20 11:08:56 -0700271 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700272 SLOG(DBus, 2) << __func__ << ": " << order;
Paul Stewart22aa71b2011-09-16 12:15:11 -0700273 Error e;
274 manager_->SetTechnologyOrder(order, &e);
275 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700276}
277
Elly Jones16227d32012-02-09 14:17:25 -0500278std::string ManagerDBusAdaptor::GetDebugTags(::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700279 SLOG(DBus, 2) << __func__;
Ben Chanbc49ac72012-04-10 19:59:45 -0700280 return ScopeLogger::GetInstance()->GetEnabledScopeNames();
Elly Jones16227d32012-02-09 14:17:25 -0500281}
282
Ben Chanbc49ac72012-04-10 19:59:45 -0700283void ManagerDBusAdaptor::SetDebugTags(const std::string &tags,
Elly Jones16227d32012-02-09 14:17:25 -0500284 ::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700285 SLOG(DBus, 2) << __func__ << ": " << tags;
Ben Chanbc49ac72012-04-10 19:59:45 -0700286 ScopeLogger::GetInstance()->EnableScopesByName(tags);
Elly Jones16227d32012-02-09 14:17:25 -0500287}
288
289std::string ManagerDBusAdaptor::ListDebugTags(::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700290 SLOG(DBus, 2) << __func__;
Ben Chanbc49ac72012-04-10 19:59:45 -0700291 return ScopeLogger::GetInstance()->GetAllScopeNames();
Elly Jones16227d32012-02-09 14:17:25 -0500292}
293
Chris Masoned7732e42011-05-20 11:08:56 -0700294} // namespace shill