blob: a505891283c047c4be539a93592eab09fb882315 [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"
Ben Chanfad4a0b2012-04-18 15:49:59 -070014#include "shill/scope_logger.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 agrawal06175d72012-04-23 16:46:01 -070079 SLOG(DBus, 2) << __func__;
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;
117 device_->Scan(&e);
118 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700119}
120
121::DBus::Path DeviceDBusAdaptor::AddIPConfig(const string& ,
mukesh agrawal1830fa12011-09-26 14:31:40 -0700122 ::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700123 SLOG(DBus, 2) << __func__;
Darin Petkovfd164b82012-02-10 14:11:52 +0100124 return "/";
Chris Masoned7732e42011-05-20 11:08:56 -0700125}
126
Darin Petkov9ae310f2011-08-30 15:41:13 -0700127void DeviceDBusAdaptor::Register(const string &network_id,
128 ::DBus::Error &error) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700129 SLOG(DBus, 2) << __func__ << "(" << network_id << ")";
Eric Shienbrood9a245532012-03-07 14:20:39 -0500130 Error e(Error::kOperationInitiated);
131 DBus::Tag *tag = new DBus::Tag();
132 device_->RegisterOnNetwork(network_id, &e, GetMethodReplyCallback(tag));
133 ReturnResultOrDefer(tag, e, &error);
Chris Masoneccc88812011-06-08 18:00:10 -0700134}
135
Darin Petkovc64fe5e2012-01-11 12:46:13 +0100136void DeviceDBusAdaptor::RequirePin(
137 const string &pin, const bool &require, DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700138 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500139 Error e(Error::kOperationInitiated);
140 DBus::Tag *tag = new DBus::Tag();
141 device_->RequirePIN(pin, require, &e, GetMethodReplyCallback(tag));
142 ReturnResultOrDefer(tag, e, &error);
Chris Masoneccc88812011-06-08 18:00:10 -0700143}
144
Darin Petkovc64fe5e2012-01-11 12:46:13 +0100145void DeviceDBusAdaptor::EnterPin(const string &pin, DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700146 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500147 Error e(Error::kOperationInitiated);
148 DBus::Tag *tag = new DBus::Tag();
149 device_->EnterPIN(pin, &e, GetMethodReplyCallback(tag));
150 ReturnResultOrDefer(tag, e, &error);
Chris Masoneccc88812011-06-08 18:00:10 -0700151}
152
Darin Petkovc64fe5e2012-01-11 12:46:13 +0100153void DeviceDBusAdaptor::UnblockPin(
154 const string &unblock_code, const string &pin, DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700155 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500156 Error e(Error::kOperationInitiated);
157 DBus::Tag *tag = new DBus::Tag();
158 device_->UnblockPIN(unblock_code, pin, &e, GetMethodReplyCallback(tag));
159 ReturnResultOrDefer(tag, e, &error);
Chris Masoneccc88812011-06-08 18:00:10 -0700160}
161
Darin Petkovc64fe5e2012-01-11 12:46:13 +0100162void DeviceDBusAdaptor::ChangePin(
163 const string &old_pin, const string &new_pin, DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700164 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500165 Error e;
166 DBus::Tag *tag = new DBus::Tag();
167 device_->ChangePIN(old_pin, new_pin, &e, GetMethodReplyCallback(tag));
168 ReturnResultOrDefer(tag, e, &error);
Chris Masoneccc88812011-06-08 18:00:10 -0700169}
170
Chris Masoned7732e42011-05-20 11:08:56 -0700171} // namespace shill