blob: 5803c967df46c6a1b11cfd18bad58458429af5a1 [file] [log] [blame]
mukesh agrawal4d0401c2012-01-06 16:05:31 -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/device_dbus_adaptor.h"
6
7#include <map>
8#include <string>
9
Eric Shienbrood9a245532012-03-07 14:20:39 -050010#include <base/bind.h>
11
Chris Masonea82b7112011-05-25 15:16:29 -070012#include "shill/device.h"
Chris Masone8fe2c7e2011-06-09 15:51:19 -070013#include "shill/error.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -070014#include "shill/logging.h"
Chris Masonea82b7112011-05-25 15:16:29 -070015
Eric Shienbrood9a245532012-03-07 14:20:39 -050016using base::Bind;
Chris Masoned7732e42011-05-20 11:08:56 -070017using std::map;
18using std::string;
19
20namespace shill {
21
Chris Masoned7732e42011-05-20 11:08:56 -070022// static
Chris Masonea82b7112011-05-25 15:16:29 -070023const char DeviceDBusAdaptor::kPath[] = "/device/";
Chris Masoned7732e42011-05-20 11:08:56 -070024
Chris Masoneec6b18b2011-06-08 14:09:10 -070025DeviceDBusAdaptor::DeviceDBusAdaptor(DBus::Connection* conn, Device *device)
Chris Masonea82b7112011-05-25 15:16:29 -070026 : DBusAdaptor(conn, kPath + device->UniqueName()),
Chris Masone4e851612011-07-01 10:46:53 -070027 device_(device),
28 connection_name_(conn->unique_name()) {
Chris Masoned7732e42011-05-20 11:08:56 -070029}
Chris Masoned0ceb8c2011-06-02 10:05:39 -070030
Chris Masoneec6b18b2011-06-08 14:09:10 -070031DeviceDBusAdaptor::~DeviceDBusAdaptor() {
32 device_ = NULL;
33}
Chris Masone4e851612011-07-01 10:46:53 -070034const std::string &DeviceDBusAdaptor::GetRpcIdentifier() {
35 return path();
36}
37
38const std::string &DeviceDBusAdaptor::GetRpcConnectionIdentifier() {
39 return connection_name_;
40}
Chris Masoned7732e42011-05-20 11:08:56 -070041
42void DeviceDBusAdaptor::UpdateEnabled() {}
43
Chris Masoned0ceb8c2011-06-02 10:05:39 -070044void DeviceDBusAdaptor::EmitBoolChanged(const std::string& name, bool value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070045 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masoned0ceb8c2011-06-02 10:05:39 -070046 PropertyChanged(name, DBusAdaptor::BoolToVariant(value));
47}
48
49void DeviceDBusAdaptor::EmitUintChanged(const std::string& name, uint32 value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070050 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070051 PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value));
Chris Masoned0ceb8c2011-06-02 10:05:39 -070052}
53
54void DeviceDBusAdaptor::EmitIntChanged(const std::string& name, int value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070055 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070056 PropertyChanged(name, DBusAdaptor::Int32ToVariant(value));
Chris Masoned0ceb8c2011-06-02 10:05:39 -070057}
58
59void DeviceDBusAdaptor::EmitStringChanged(const std::string& name,
60 const std::string& value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070061 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masoned0ceb8c2011-06-02 10:05:39 -070062 PropertyChanged(name, DBusAdaptor::StringToVariant(value));
63}
64
Darin Petkov3cfbf212011-11-21 16:02:09 +010065void DeviceDBusAdaptor::EmitStringmapsChanged(const std::string &name,
66 const Stringmaps &value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070067 SLOG(DBus, 2) << __func__ << ": " << name;
Darin Petkov3cfbf212011-11-21 16:02:09 +010068 PropertyChanged(name, DBusAdaptor::StringmapsToVariant(value));
69}
70
Darin Petkov63138a92012-02-06 14:09:15 +010071void DeviceDBusAdaptor::EmitKeyValueStoreChanged(const std::string &name,
72 const KeyValueStore &value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070073 SLOG(DBus, 2) << __func__ << ": " << name;
Darin Petkov63138a92012-02-06 14:09:15 +010074 PropertyChanged(name, DBusAdaptor::KeyValueStoreToVariant(value));
75}
76
Chris Masoned7732e42011-05-20 11:08:56 -070077map<string, ::DBus::Variant> DeviceDBusAdaptor::GetProperties(
78 ::DBus::Error &error) {
mukesh agrawal465331c2012-05-30 11:26:11 -070079 SLOG(DBus, 2) << __func__ << " " << device_->FriendlyName();
Chris Masonea8a2c252011-06-27 22:16:30 -070080 map<string, ::DBus::Variant> properties;
Chris Masone27c4aa52011-07-02 13:10:14 -070081 DBusAdaptor::GetProperties(device_->store(), &properties, &error);
Chris Masonea8a2c252011-06-27 22:16:30 -070082 return properties;
Chris Masoned7732e42011-05-20 11:08:56 -070083}
84
mukesh agrawal4d0401c2012-01-06 16:05:31 -080085void DeviceDBusAdaptor::SetProperty(const string &name,
86 const ::DBus::Variant &value,
Chris Masoned7732e42011-05-20 11:08:56 -070087 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070088 SLOG(DBus, 2) << __func__ << ": " << name;
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -080089 DBusAdaptor::SetProperty(device_->mutable_store(), name, value, &error);
Chris Masoned7732e42011-05-20 11:08:56 -070090}
91
mukesh agrawal4d0401c2012-01-06 16:05:31 -080092void DeviceDBusAdaptor::ClearProperty(const std::string &name,
mukesh agrawal8abd2f62012-01-30 14:56:14 -080093 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070094 SLOG(DBus, 2) << __func__ << ": " << name;
mukesh agrawal8abd2f62012-01-30 14:56:14 -080095 DBusAdaptor::ClearProperty(device_->mutable_store(), name, &error);
Chris Masoneccc88812011-06-08 18:00:10 -070096}
97
Eric Shienbrood9a245532012-03-07 14:20:39 -050098void DeviceDBusAdaptor::Enable(::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070099 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500100 Error e(Error::kOperationInitiated);
101 DBus::Tag *tag = new DBus::Tag();
102 device_->SetEnabledPersistent(true, &e, GetMethodReplyCallback(tag));
103 ReturnResultOrDefer(tag, e, &error);
104}
105
106void DeviceDBusAdaptor::Disable(::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700107 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500108 Error e(Error::kOperationInitiated);
109 DBus::Tag *tag = new DBus::Tag();
110 device_->SetEnabledPersistent(false, &e, GetMethodReplyCallback(tag));
111 ReturnResultOrDefer(tag, e, &error);
112}
113
Chris Masoned7732e42011-05-20 11:08:56 -0700114void DeviceDBusAdaptor::ProposeScan(::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700115 SLOG(DBus, 2) << __func__;
Darin Petkovc0865312011-09-16 15:31:20 -0700116 Error e;
Wade Guthrie68d41092013-04-02 12:56:02 -0700117 // User scan requests, which are the likely source of DBus requests, probably
118 // aren't time-critical so we might as well perform a complete scan. It
119 // also provides a failsafe for progressive scan.
120 device_->Scan(Device::kFullScan, &e);
Darin Petkovc0865312011-09-16 15:31:20 -0700121 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700122}
123
124::DBus::Path DeviceDBusAdaptor::AddIPConfig(const string& ,
Paul Stewart624b9a22012-05-21 14:17:35 -0700125 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700126 SLOG(DBus, 2) << __func__;
Paul Stewart624b9a22012-05-21 14:17:35 -0700127 Error e(Error::kNotSupported, "This function is deprecated in shill");
128 e.ToDBusError(&error);
Darin Petkovfd164b82012-02-10 14:11:52 +0100129 return "/";
Chris Masoned7732e42011-05-20 11:08:56 -0700130}
131
Darin Petkov9ae310f2011-08-30 15:41:13 -0700132void DeviceDBusAdaptor::Register(const string &network_id,
133 ::DBus::Error &error) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700134 SLOG(DBus, 2) << __func__ << "(" << network_id << ")";
Eric Shienbrood9a245532012-03-07 14:20:39 -0500135 Error e(Error::kOperationInitiated);
136 DBus::Tag *tag = new DBus::Tag();
137 device_->RegisterOnNetwork(network_id, &e, GetMethodReplyCallback(tag));
138 ReturnResultOrDefer(tag, e, &error);
Chris Masoneccc88812011-06-08 18:00:10 -0700139}
140
Darin Petkovc64fe5e2012-01-11 12:46:13 +0100141void DeviceDBusAdaptor::RequirePin(
142 const string &pin, const bool &require, DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700143 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500144 Error e(Error::kOperationInitiated);
145 DBus::Tag *tag = new DBus::Tag();
146 device_->RequirePIN(pin, require, &e, GetMethodReplyCallback(tag));
147 ReturnResultOrDefer(tag, e, &error);
Chris Masoneccc88812011-06-08 18:00:10 -0700148}
149
Darin Petkovc64fe5e2012-01-11 12:46:13 +0100150void DeviceDBusAdaptor::EnterPin(const string &pin, DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700151 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500152 Error e(Error::kOperationInitiated);
153 DBus::Tag *tag = new DBus::Tag();
154 device_->EnterPIN(pin, &e, GetMethodReplyCallback(tag));
155 ReturnResultOrDefer(tag, e, &error);
Chris Masoneccc88812011-06-08 18:00:10 -0700156}
157
Darin Petkovc64fe5e2012-01-11 12:46:13 +0100158void DeviceDBusAdaptor::UnblockPin(
159 const string &unblock_code, const string &pin, DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700160 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500161 Error e(Error::kOperationInitiated);
162 DBus::Tag *tag = new DBus::Tag();
163 device_->UnblockPIN(unblock_code, pin, &e, GetMethodReplyCallback(tag));
164 ReturnResultOrDefer(tag, e, &error);
Chris Masoneccc88812011-06-08 18:00:10 -0700165}
166
Darin Petkovc64fe5e2012-01-11 12:46:13 +0100167void DeviceDBusAdaptor::ChangePin(
168 const string &old_pin, const string &new_pin, DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700169 SLOG(DBus, 2) << __func__;
Darin Petkovc37a9c42012-09-06 15:28:22 +0200170 Error e(Error::kOperationInitiated);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500171 DBus::Tag *tag = new DBus::Tag();
172 device_->ChangePIN(old_pin, new_pin, &e, GetMethodReplyCallback(tag));
173 ReturnResultOrDefer(tag, e, &error);
Chris Masoneccc88812011-06-08 18:00:10 -0700174}
175
Ben Chanad663e12013-01-08 01:58:47 -0800176void DeviceDBusAdaptor::Reset(::DBus::Error &error) {
177 SLOG(DBus, 2) << __func__;
178 Error e(Error::kOperationInitiated);
179 DBus::Tag *tag = new DBus::Tag();
180 device_->Reset(&e, GetMethodReplyCallback(tag));
181 ReturnResultOrDefer(tag, e, &error);
182}
183
Paul Stewart6ff27f52012-07-11 06:51:41 -0700184void DeviceDBusAdaptor::ResetByteCounters(DBus::Error &error) {
185 device_->ResetByteCounters();
186}
187
Darin Petkovc37a9c42012-09-06 15:28:22 +0200188void DeviceDBusAdaptor::SetCarrier(const string &carrier, DBus::Error &error) {
189 SLOG(DBus, 2) << __func__ << "(" << carrier << ")";
190 Error e(Error::kOperationInitiated);
191 DBus::Tag *tag = new DBus::Tag();
192 device_->SetCarrier(carrier, &e, GetMethodReplyCallback(tag));
193 ReturnResultOrDefer(tag, e, &error);
194}
195
Chris Masoned7732e42011-05-20 11:08:56 -0700196} // namespace shill