blob: a09608140be980e2ea2428ecc2d1a6951d107f0b [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) {
Chris Masoned0ceb8c2011-06-02 10:05:39 -070041 PropertyChanged(name, DBusAdaptor::BoolToVariant(value));
42}
43
Chris Masone8fe2c7e2011-06-09 15:51:19 -070044void ManagerDBusAdaptor::EmitUintChanged(const string &name,
Chris Masoned0ceb8c2011-06-02 10:05:39 -070045 uint32 value) {
Chris Masone8fe2c7e2011-06-09 15:51:19 -070046 PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value));
Chris Masoned0ceb8c2011-06-02 10:05:39 -070047}
48
Chris Masone8fe2c7e2011-06-09 15:51:19 -070049void ManagerDBusAdaptor::EmitIntChanged(const string &name, int value) {
50 PropertyChanged(name, DBusAdaptor::Int32ToVariant(value));
Chris Masoned0ceb8c2011-06-02 10:05:39 -070051}
52
Chris Masone8fe2c7e2011-06-09 15:51:19 -070053void ManagerDBusAdaptor::EmitStringChanged(const string &name,
54 const string &value) {
Chris Masoned0ceb8c2011-06-02 10:05:39 -070055 PropertyChanged(name, DBusAdaptor::StringToVariant(value));
56}
57
Gaurav Shah435de2c2011-11-17 19:01:07 -080058void ManagerDBusAdaptor::EmitStringsChanged(const string &name,
59 const vector<string> &value) {
60 PropertyChanged(name, DBusAdaptor::StringsToVariant(value));
61}
62
mukesh agrawal32399322011-09-01 10:53:43 -070063void 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 agrawal2366eed2012-03-20 18:21:50 -070072 PropertyChanged(name, DBusAdaptor::PathsToVariant(paths));
mukesh agrawal32399322011-09-01 10:53:43 -070073}
74
Chris Masone8fe2c7e2011-06-09 15:51:19 -070075void ManagerDBusAdaptor::EmitStateChanged(const string &new_state) {
Chris Masoned0ceb8c2011-06-02 10:05:39 -070076 StateChanged(new_state);
77}
78
Chris Masoned7732e42011-05-20 11:08:56 -070079map<string, ::DBus::Variant> ManagerDBusAdaptor::GetProperties(
80 ::DBus::Error &error) {
Chris Masonea8a2c252011-06-27 22:16:30 -070081 map<string, ::DBus::Variant> properties;
Chris Masone27c4aa52011-07-02 13:10:14 -070082 DBusAdaptor::GetProperties(manager_->store(), &properties, &error);
Chris Masonea8a2c252011-06-27 22:16:30 -070083 return properties;
Chris Masoned7732e42011-05-20 11:08:56 -070084}
85
Chris Masone8fe2c7e2011-06-09 15:51:19 -070086void ManagerDBusAdaptor::SetProperty(const string &name,
87 const ::DBus::Variant &value,
Chris Masoned7732e42011-05-20 11:08:56 -070088 ::DBus::Error &error) {
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -080089 if (DBusAdaptor::SetProperty(manager_->mutable_store(),
90 name,
91 value,
92 &error)) {
Chris Masone3bd3c8c2011-06-13 08:20:26 -070093 PropertyChanged(name, value);
94 }
Chris Masoned7732e42011-05-20 11:08:56 -070095}
96
mukesh agrawal1830fa12011-09-26 14:31:40 -070097string ManagerDBusAdaptor::GetState(::DBus::Error &/*error*/) {
Chris Masoned7732e42011-05-20 11:08:56 -070098 return string();
99}
100
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700101::DBus::Path ManagerDBusAdaptor::CreateProfile(const string &name,
Paul Stewart19c871d2011-12-15 16:10:13 -0800102 ::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 Masoned7732e42011-05-20 11:08:56 -0700108}
109
Paul Stewarte73d05c2012-03-29 16:26:05 -0700110void ManagerDBusAdaptor::RemoveProfile(const string &name,
111 ::DBus::Error &error) {
112 Error e;
113 manager_->RemoveProfile(name, &e);
114 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700115}
116
mukesh agrawale5929bf2011-08-29 13:47:23 -0700117::DBus::Path ManagerDBusAdaptor::PushProfile(const std::string &name,
Paul Stewart19c871d2011-12-15 16:10:13 -0800118 ::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 Masoneccc88812011-06-08 18:00:10 -0700124}
125
Paul Stewart19c871d2011-12-15 16:10:13 -0800126void ManagerDBusAdaptor::PopProfile(const std::string &name,
127 ::DBus::Error &error) {
128 Error e;
129 manager_->PopProfile(name, &e);
130 e.ToDBusError(&error);
Chris Masoneccc88812011-06-08 18:00:10 -0700131}
132
Paul Stewart19c871d2011-12-15 16:10:13 -0800133void ManagerDBusAdaptor::PopAnyProfile(::DBus::Error &error) {
134 Error e;
135 manager_->PopAnyProfile(&e);
136 e.ToDBusError(&error);
Chris Masoneccc88812011-06-08 18:00:10 -0700137}
138
Paul Stewartc681fa02012-03-02 19:40:04 -0800139void ManagerDBusAdaptor::RecheckPortal(::DBus::Error &error) {
140 Error e;
141 manager_->RecheckPortal(&e);
142 e.ToDBusError(&error);
143}
144
mukesh agrawal32399322011-09-01 10:53:43 -0700145void ManagerDBusAdaptor::RequestScan(const string &technology,
Chris Masoned7732e42011-05-20 11:08:56 -0700146 ::DBus::Error &error) {
mukesh agrawal32399322011-09-01 10:53:43 -0700147 Error e;
148 manager_->RequestScan(technology, &e);
149 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700150}
151
Eric Shienbrood9a245532012-03-07 14:20:39 -0500152void 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 Masoned7732e42011-05-20 11:08:56 -0700161}
162
Eric Shienbrood9a245532012-03-07 14:20:39 -0500163void 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 Masoned7732e42011-05-20 11:08:56 -0700172}
173
Darin Petkovb65c2452012-02-23 15:17:06 +0100174// Called, e.g., to get WiFiService handle for a hidden SSID.
Chris Masoned7732e42011-05-20 11:08:56 -0700175::DBus::Path ManagerDBusAdaptor::GetService(
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700176 const map<string, ::DBus::Variant> &args,
Chris Masoned7732e42011-05-20 11:08:56 -0700177 ::DBus::Error &error) {
Darin Petkovb65c2452012-02-23 15:17:06 +0100178 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 Masoned7732e42011-05-20 11:08:56 -0700189}
190
Darin Petkovb65c2452012-02-23 15:17:06 +0100191// 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 Masoned7732e42011-05-20 11:08:56 -0700199::DBus::Path ManagerDBusAdaptor::GetWifiService(
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700200 const map<string, ::DBus::Variant> &args,
Chris Masoned7732e42011-05-20 11:08:56 -0700201 ::DBus::Error &error) {
Darin Petkovb65c2452012-02-23 15:17:06 +0100202 return GetService(args, error);
Chris Masoned7732e42011-05-20 11:08:56 -0700203}
204
Paul Stewart7f61e522012-03-22 11:13:45 -0700205
206void 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 Masoned7732e42011-05-20 11:08:56 -0700216}
217
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700218void ManagerDBusAdaptor::RegisterAgent(const ::DBus::Path &,
mukesh agrawal1830fa12011-09-26 14:31:40 -0700219 ::DBus::Error &/*error*/) {
Chris Masoned7732e42011-05-20 11:08:56 -0700220}
221
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700222void ManagerDBusAdaptor::UnregisterAgent(const ::DBus::Path &,
mukesh agrawal1830fa12011-09-26 14:31:40 -0700223 ::DBus::Error &/*error*/) {
Chris Masoned7732e42011-05-20 11:08:56 -0700224}
225
mukesh agrawal1830fa12011-09-26 14:31:40 -0700226int32_t ManagerDBusAdaptor::GetDebugLevel(::DBus::Error &/*error*/) {
Chris Masone7ccc8192011-05-24 14:54:49 -0700227 return logging::GetMinLogLevel();
Chris Masoned7732e42011-05-20 11:08:56 -0700228}
229
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700230void ManagerDBusAdaptor::SetDebugLevel(const int32_t &level,
mukesh agrawal1830fa12011-09-26 14:31:40 -0700231 ::DBus::Error &/*error*/) {
Ben Chanbc49ac72012-04-10 19:59:45 -0700232 if (level < logging::LOG_NUM_SEVERITIES) {
Chris Masone7ccc8192011-05-24 14:54:49 -0700233 logging::SetMinLogLevel(level);
Ben Chanbc49ac72012-04-10 19:59:45 -0700234 // Like VLOG, SLOG uses negative verbose level.
235 ScopeLogger::GetInstance()->set_verbose_level(-level);
236 } else {
Chris Masone7ccc8192011-05-24 14:54:49 -0700237 LOG(WARNING) << "Ignoring attempt to set log level to " << level;
Ben Chanbc49ac72012-04-10 19:59:45 -0700238 }
Chris Masoned7732e42011-05-20 11:08:56 -0700239}
240
mukesh agrawal1830fa12011-09-26 14:31:40 -0700241string ManagerDBusAdaptor::GetServiceOrder(::DBus::Error &/*error*/) {
Paul Stewart22aa71b2011-09-16 12:15:11 -0700242 return manager_->GetTechnologyOrder();
Chris Masoned7732e42011-05-20 11:08:56 -0700243}
244
Paul Stewart22aa71b2011-09-16 12:15:11 -0700245void ManagerDBusAdaptor::SetServiceOrder(const string &order,
Chris Masoned7732e42011-05-20 11:08:56 -0700246 ::DBus::Error &error) {
Paul Stewart22aa71b2011-09-16 12:15:11 -0700247 Error e;
248 manager_->SetTechnologyOrder(order, &e);
249 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700250}
251
Elly Jones16227d32012-02-09 14:17:25 -0500252std::string ManagerDBusAdaptor::GetDebugTags(::DBus::Error &/*error*/) {
Ben Chanbc49ac72012-04-10 19:59:45 -0700253 return ScopeLogger::GetInstance()->GetEnabledScopeNames();
Elly Jones16227d32012-02-09 14:17:25 -0500254}
255
Ben Chanbc49ac72012-04-10 19:59:45 -0700256void ManagerDBusAdaptor::SetDebugTags(const std::string &tags,
Elly Jones16227d32012-02-09 14:17:25 -0500257 ::DBus::Error &/*error*/) {
Ben Chanbc49ac72012-04-10 19:59:45 -0700258 ScopeLogger::GetInstance()->EnableScopesByName(tags);
Elly Jones16227d32012-02-09 14:17:25 -0500259}
260
261std::string ManagerDBusAdaptor::ListDebugTags(::DBus::Error &/*error*/) {
Ben Chanbc49ac72012-04-10 19:59:45 -0700262 return ScopeLogger::GetInstance()->GetAllScopeNames();
Elly Jones16227d32012-02-09 14:17:25 -0500263}
264
Chris Masoned7732e42011-05-20 11:08:56 -0700265} // namespace shill