blob: 27bba6402ed77b7499e41bae077080eaf36da835 [file] [log] [blame]
Chris Masoned7732e42011-05-20 11:08:56 -07001// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
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 Masone8fe2c7e2011-06-09 15:51:19 -07009#include <vector>
Chris Masoned7732e42011-05-20 11:08:56 -070010
Chris Masone7ccc8192011-05-24 14:54:49 -070011#include <base/logging.h>
Chris Masone8fe2c7e2011-06-09 15:51:19 -070012#include <dbus-c++/dbus.h>
13
mukesh agrawal32399322011-09-01 10:53:43 -070014#include "shill/device.h"
Chris Masone8fe2c7e2011-06-09 15:51:19 -070015#include "shill/error.h"
mukesh agrawal7a4e4002011-09-06 11:26:05 -070016#include "shill/key_value_store.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
27const char ManagerDBusAdaptor::kInterfaceName[] = SHILL_INTERFACE;
Chris Masoned7732e42011-05-20 11:08:56 -070028// static
Chris Masone19e30402011-07-19 15:48:47 -070029const char ManagerDBusAdaptor::kPath[] = "/";
Chris Masoned7732e42011-05-20 11:08:56 -070030
Chris Masoned0ceb8c2011-06-02 10:05:39 -070031ManagerDBusAdaptor::ManagerDBusAdaptor(DBus::Connection* conn, Manager *manager)
Chris Masoned7732e42011-05-20 11:08:56 -070032 : DBusAdaptor(conn, kPath),
33 manager_(manager) {
34}
Chris Masoneec6b18b2011-06-08 14:09:10 -070035
36ManagerDBusAdaptor::~ManagerDBusAdaptor() {
37 manager_ = NULL;
38}
Chris Masoned7732e42011-05-20 11:08:56 -070039
40void ManagerDBusAdaptor::UpdateRunning() {}
41
Chris Masone8fe2c7e2011-06-09 15:51:19 -070042void ManagerDBusAdaptor::EmitBoolChanged(const string &name, bool value) {
Chris Masoned0ceb8c2011-06-02 10:05:39 -070043 PropertyChanged(name, DBusAdaptor::BoolToVariant(value));
44}
45
Chris Masone8fe2c7e2011-06-09 15:51:19 -070046void ManagerDBusAdaptor::EmitUintChanged(const string &name,
Chris Masoned0ceb8c2011-06-02 10:05:39 -070047 uint32 value) {
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) {
52 PropertyChanged(name, DBusAdaptor::Int32ToVariant(value));
Chris Masoned0ceb8c2011-06-02 10:05:39 -070053}
54
Chris Masone8fe2c7e2011-06-09 15:51:19 -070055void ManagerDBusAdaptor::EmitStringChanged(const string &name,
56 const string &value) {
Chris Masoned0ceb8c2011-06-02 10:05:39 -070057 PropertyChanged(name, DBusAdaptor::StringToVariant(value));
58}
59
mukesh agrawal32399322011-09-01 10:53:43 -070060void ManagerDBusAdaptor::EmitRpcIdentifierArrayChanged(
61 const string &name,
62 const vector<string> &value) {
63 vector< ::DBus::Path> paths;
64 vector<string>::const_iterator it;
65 for (it = value.begin(); it != value.end(); ++it) {
66 paths.push_back(*it);
67 }
68
69 PropertyChanged(name, DBusAdaptor::PathArrayToVariant(paths));
70}
71
Chris Masone8fe2c7e2011-06-09 15:51:19 -070072void ManagerDBusAdaptor::EmitStateChanged(const string &new_state) {
Chris Masoned0ceb8c2011-06-02 10:05:39 -070073 StateChanged(new_state);
74}
75
Chris Masoned7732e42011-05-20 11:08:56 -070076map<string, ::DBus::Variant> ManagerDBusAdaptor::GetProperties(
77 ::DBus::Error &error) {
Chris Masonea8a2c252011-06-27 22:16:30 -070078 map<string, ::DBus::Variant> properties;
Chris Masone27c4aa52011-07-02 13:10:14 -070079 DBusAdaptor::GetProperties(manager_->store(), &properties, &error);
Chris Masonea8a2c252011-06-27 22:16:30 -070080 return properties;
Chris Masoned7732e42011-05-20 11:08:56 -070081}
82
Chris Masone8fe2c7e2011-06-09 15:51:19 -070083void ManagerDBusAdaptor::SetProperty(const string &name,
84 const ::DBus::Variant &value,
Chris Masoned7732e42011-05-20 11:08:56 -070085 ::DBus::Error &error) {
mukesh agrawalde29fa82011-09-16 16:16:36 -070086 if (DBusAdaptor::DispatchOnType(manager_->mutable_store(),
87 name,
88 value,
89 &error)) {
Chris Masone3bd3c8c2011-06-13 08:20:26 -070090 PropertyChanged(name, value);
91 }
Chris Masoned7732e42011-05-20 11:08:56 -070092}
93
mukesh agrawal1830fa12011-09-26 14:31:40 -070094string ManagerDBusAdaptor::GetState(::DBus::Error &/*error*/) {
Chris Masoned7732e42011-05-20 11:08:56 -070095 return string();
96}
97
Chris Masone8fe2c7e2011-06-09 15:51:19 -070098::DBus::Path ManagerDBusAdaptor::CreateProfile(const string &name,
mukesh agrawal1830fa12011-09-26 14:31:40 -070099 ::DBus::Error &/*error*/) {
mukesh agrawale5929bf2011-08-29 13:47:23 -0700100 NOTIMPLEMENTED();
101 // TODO(quiche): implement this
102 return ::DBus::Path("/" + name);
Chris Masoned7732e42011-05-20 11:08:56 -0700103}
104
mukesh agrawal1830fa12011-09-26 14:31:40 -0700105void ManagerDBusAdaptor::RemoveProfile(const string &/*name*/,
106 ::DBus::Error &/*error*/) {
Chris Masoned7732e42011-05-20 11:08:56 -0700107}
108
mukesh agrawale5929bf2011-08-29 13:47:23 -0700109::DBus::Path ManagerDBusAdaptor::PushProfile(const std::string &name,
mukesh agrawal1830fa12011-09-26 14:31:40 -0700110 ::DBus::Error &/*error*/) {
mukesh agrawale5929bf2011-08-29 13:47:23 -0700111 NOTIMPLEMENTED();
112 // TODO(quiche): implement this
113 return ::DBus::Path("/" + name);
Chris Masoneccc88812011-06-08 18:00:10 -0700114}
115
mukesh agrawal1830fa12011-09-26 14:31:40 -0700116void ManagerDBusAdaptor::PopProfile(const std::string &,
117 ::DBus::Error &/*error*/) {
Chris Masoneccc88812011-06-08 18:00:10 -0700118}
119
mukesh agrawal1830fa12011-09-26 14:31:40 -0700120void ManagerDBusAdaptor::PopAnyProfile(::DBus::Error &/*error*/) {
Chris Masoneccc88812011-06-08 18:00:10 -0700121}
122
mukesh agrawal32399322011-09-01 10:53:43 -0700123void ManagerDBusAdaptor::RequestScan(const string &technology,
Chris Masoned7732e42011-05-20 11:08:56 -0700124 ::DBus::Error &error) {
mukesh agrawal32399322011-09-01 10:53:43 -0700125 Error e;
126 manager_->RequestScan(technology, &e);
127 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700128}
129
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700130void ManagerDBusAdaptor::EnableTechnology(const string &,
mukesh agrawal1830fa12011-09-26 14:31:40 -0700131 ::DBus::Error &/*error*/) {
Chris Masoned7732e42011-05-20 11:08:56 -0700132}
133
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700134void ManagerDBusAdaptor::DisableTechnology(const string &,
mukesh agrawal1830fa12011-09-26 14:31:40 -0700135 ::DBus::Error &/*error*/) {
Chris Masoned7732e42011-05-20 11:08:56 -0700136}
137
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700138// deprecated synonym for GetWifiService
Chris Masoned7732e42011-05-20 11:08:56 -0700139::DBus::Path ManagerDBusAdaptor::GetService(
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700140 const map<string, ::DBus::Variant> &args,
Chris Masoned7732e42011-05-20 11:08:56 -0700141 ::DBus::Error &error) {
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700142 return GetWifiService(args, error);
Chris Masoned7732e42011-05-20 11:08:56 -0700143}
144
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700145// called, e.g., to get Service handle for a hidden SSID
Chris Masoned7732e42011-05-20 11:08:56 -0700146::DBus::Path ManagerDBusAdaptor::GetWifiService(
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700147 const map<string, ::DBus::Variant> &args,
Chris Masoned7732e42011-05-20 11:08:56 -0700148 ::DBus::Error &error) {
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700149 KeyValueStore args_store;
150 Error e;
151 WiFiServiceRefPtr service;
152 string ret;
153
154 DBusAdaptor::ArgsToKeyValueStore(args, &args_store, &e);
155 if (e.IsSuccess()) {
156 service = manager_->GetWifiService(args_store, &e);
157 }
158
159 if (e.ToDBusError(&error)) {
160 return "/"; // ensure return is syntactically valid
161 } else {
162 return service->GetRpcIdentifier();
163 }
Chris Masoned7732e42011-05-20 11:08:56 -0700164}
165
166void ManagerDBusAdaptor::ConfigureWifiService(
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700167 const map<string, ::DBus::Variant> &,
mukesh agrawal1830fa12011-09-26 14:31:40 -0700168 ::DBus::Error &/*error*/) {
Chris Masoned7732e42011-05-20 11:08:56 -0700169}
170
Chris Masoneccc88812011-06-08 18:00:10 -0700171::DBus::Path ManagerDBusAdaptor::GetVPNService(
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700172 const map<string, ::DBus::Variant> &,
mukesh agrawal1830fa12011-09-26 14:31:40 -0700173 ::DBus::Error &/*error*/) {
Chris Masoneccc88812011-06-08 18:00:10 -0700174 return ::DBus::Path();
175}
176
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700177void ManagerDBusAdaptor::RegisterAgent(const ::DBus::Path &,
mukesh agrawal1830fa12011-09-26 14:31:40 -0700178 ::DBus::Error &/*error*/) {
Chris Masoned7732e42011-05-20 11:08:56 -0700179}
180
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700181void ManagerDBusAdaptor::UnregisterAgent(const ::DBus::Path &,
mukesh agrawal1830fa12011-09-26 14:31:40 -0700182 ::DBus::Error &/*error*/) {
Chris Masoned7732e42011-05-20 11:08:56 -0700183}
184
mukesh agrawal1830fa12011-09-26 14:31:40 -0700185int32_t ManagerDBusAdaptor::GetDebugLevel(::DBus::Error &/*error*/) {
Chris Masone7ccc8192011-05-24 14:54:49 -0700186 return logging::GetMinLogLevel();
Chris Masoned7732e42011-05-20 11:08:56 -0700187}
188
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700189void ManagerDBusAdaptor::SetDebugLevel(const int32_t &level,
mukesh agrawal1830fa12011-09-26 14:31:40 -0700190 ::DBus::Error &/*error*/) {
Chris Masone7ccc8192011-05-24 14:54:49 -0700191 if (level < logging::LOG_NUM_SEVERITIES)
192 logging::SetMinLogLevel(level);
193 else
194 LOG(WARNING) << "Ignoring attempt to set log level to " << level;
Chris Masoned7732e42011-05-20 11:08:56 -0700195}
196
mukesh agrawal1830fa12011-09-26 14:31:40 -0700197string ManagerDBusAdaptor::GetServiceOrder(::DBus::Error &/*error*/) {
Paul Stewart22aa71b2011-09-16 12:15:11 -0700198 return manager_->GetTechnologyOrder();
Chris Masoned7732e42011-05-20 11:08:56 -0700199}
200
Paul Stewart22aa71b2011-09-16 12:15:11 -0700201void ManagerDBusAdaptor::SetServiceOrder(const string &order,
Chris Masoned7732e42011-05-20 11:08:56 -0700202 ::DBus::Error &error) {
Paul Stewart22aa71b2011-09-16 12:15:11 -0700203 Error e;
204 manager_->SetTechnologyOrder(order, &e);
205 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700206}
207
208} // namespace shill