blob: 93184019c02f7e15e183746dd7b3a876b2294454 [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
94string ManagerDBusAdaptor::GetState(::DBus::Error &error) {
95 return string();
96}
97
Chris Masone8fe2c7e2011-06-09 15:51:19 -070098::DBus::Path ManagerDBusAdaptor::CreateProfile(const string &name,
Chris Masoned7732e42011-05-20 11:08:56 -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
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700105void ManagerDBusAdaptor::RemoveProfile(const string &name,
Chris Masoned7732e42011-05-20 11:08:56 -0700106 ::DBus::Error &error) {
107}
108
mukesh agrawale5929bf2011-08-29 13:47:23 -0700109::DBus::Path ManagerDBusAdaptor::PushProfile(const std::string &name,
Chris Masoneccc88812011-06-08 18:00:10 -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
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700116void ManagerDBusAdaptor::PopProfile(const std::string &, ::DBus::Error &error) {
Chris Masoneccc88812011-06-08 18:00:10 -0700117}
118
119void ManagerDBusAdaptor::PopAnyProfile(::DBus::Error &error) {
120}
121
mukesh agrawal32399322011-09-01 10:53:43 -0700122void ManagerDBusAdaptor::RequestScan(const string &technology,
Chris Masoned7732e42011-05-20 11:08:56 -0700123 ::DBus::Error &error) {
mukesh agrawal32399322011-09-01 10:53:43 -0700124 Error e;
125 manager_->RequestScan(technology, &e);
126 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700127}
128
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700129void ManagerDBusAdaptor::EnableTechnology(const string &,
Chris Masoned7732e42011-05-20 11:08:56 -0700130 ::DBus::Error &error) {
131}
132
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700133void ManagerDBusAdaptor::DisableTechnology(const string &,
Chris Masoned7732e42011-05-20 11:08:56 -0700134 ::DBus::Error &error) {
135}
136
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700137// deprecated synonym for GetWifiService
Chris Masoned7732e42011-05-20 11:08:56 -0700138::DBus::Path ManagerDBusAdaptor::GetService(
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700139 const map<string, ::DBus::Variant> &args,
Chris Masoned7732e42011-05-20 11:08:56 -0700140 ::DBus::Error &error) {
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700141 return GetWifiService(args, error);
Chris Masoned7732e42011-05-20 11:08:56 -0700142}
143
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700144// called, e.g., to get Service handle for a hidden SSID
Chris Masoned7732e42011-05-20 11:08:56 -0700145::DBus::Path ManagerDBusAdaptor::GetWifiService(
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700146 const map<string, ::DBus::Variant> &args,
Chris Masoned7732e42011-05-20 11:08:56 -0700147 ::DBus::Error &error) {
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700148 KeyValueStore args_store;
149 Error e;
150 WiFiServiceRefPtr service;
151 string ret;
152
153 DBusAdaptor::ArgsToKeyValueStore(args, &args_store, &e);
154 if (e.IsSuccess()) {
155 service = manager_->GetWifiService(args_store, &e);
156 }
157
158 if (e.ToDBusError(&error)) {
159 return "/"; // ensure return is syntactically valid
160 } else {
161 return service->GetRpcIdentifier();
162 }
Chris Masoned7732e42011-05-20 11:08:56 -0700163}
164
165void ManagerDBusAdaptor::ConfigureWifiService(
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700166 const map<string, ::DBus::Variant> &,
Chris Masoned7732e42011-05-20 11:08:56 -0700167 ::DBus::Error &error) {
168}
169
Chris Masoneccc88812011-06-08 18:00:10 -0700170::DBus::Path ManagerDBusAdaptor::GetVPNService(
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700171 const map<string, ::DBus::Variant> &,
Chris Masoneccc88812011-06-08 18:00:10 -0700172 ::DBus::Error &error) {
173 return ::DBus::Path();
174}
175
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700176void ManagerDBusAdaptor::RegisterAgent(const ::DBus::Path &,
Chris Masoned7732e42011-05-20 11:08:56 -0700177 ::DBus::Error &error) {
178}
179
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700180void ManagerDBusAdaptor::UnregisterAgent(const ::DBus::Path &,
Chris Masoned7732e42011-05-20 11:08:56 -0700181 ::DBus::Error &error) {
182}
183
Chris Masone7ccc8192011-05-24 14:54:49 -0700184int32_t ManagerDBusAdaptor::GetDebugLevel(::DBus::Error &error) {
185 return logging::GetMinLogLevel();
Chris Masoned7732e42011-05-20 11:08:56 -0700186}
187
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700188void ManagerDBusAdaptor::SetDebugLevel(const int32_t &level,
Chris Masoned7732e42011-05-20 11:08:56 -0700189 ::DBus::Error &error) {
Chris Masone7ccc8192011-05-24 14:54:49 -0700190 if (level < logging::LOG_NUM_SEVERITIES)
191 logging::SetMinLogLevel(level);
192 else
193 LOG(WARNING) << "Ignoring attempt to set log level to " << level;
Chris Masoned7732e42011-05-20 11:08:56 -0700194}
195
196string ManagerDBusAdaptor::GetServiceOrder(::DBus::Error &error) {
197 return string();
198}
199
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700200void ManagerDBusAdaptor::SetServiceOrder(const string &,
Chris Masoned7732e42011-05-20 11:08:56 -0700201 ::DBus::Error &error) {
202}
203
204} // namespace shill