blob: 8ad676361b16df6ef6eec66ee234155a147a8493 [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"
Chris Masonea82b7112011-05-25 15:16:29 -070014
Eric Shienbrood9a245532012-03-07 14:20:39 -050015using base::Bind;
Chris Masoned7732e42011-05-20 11:08:56 -070016using std::map;
17using std::string;
18
19namespace shill {
20
Chris Masoned7732e42011-05-20 11:08:56 -070021// static
Chris Masonea82b7112011-05-25 15:16:29 -070022const char DeviceDBusAdaptor::kPath[] = "/device/";
Chris Masoned7732e42011-05-20 11:08:56 -070023
Chris Masoneec6b18b2011-06-08 14:09:10 -070024DeviceDBusAdaptor::DeviceDBusAdaptor(DBus::Connection* conn, Device *device)
Chris Masonea82b7112011-05-25 15:16:29 -070025 : DBusAdaptor(conn, kPath + device->UniqueName()),
Chris Masone4e851612011-07-01 10:46:53 -070026 device_(device),
27 connection_name_(conn->unique_name()) {
Chris Masoned7732e42011-05-20 11:08:56 -070028}
Chris Masoned0ceb8c2011-06-02 10:05:39 -070029
Chris Masoneec6b18b2011-06-08 14:09:10 -070030DeviceDBusAdaptor::~DeviceDBusAdaptor() {
31 device_ = NULL;
32}
Chris Masone4e851612011-07-01 10:46:53 -070033const std::string &DeviceDBusAdaptor::GetRpcIdentifier() {
34 return path();
35}
36
37const std::string &DeviceDBusAdaptor::GetRpcConnectionIdentifier() {
38 return connection_name_;
39}
Chris Masoned7732e42011-05-20 11:08:56 -070040
41void DeviceDBusAdaptor::UpdateEnabled() {}
42
Chris Masoned0ceb8c2011-06-02 10:05:39 -070043void DeviceDBusAdaptor::EmitBoolChanged(const std::string& name, bool value) {
44 PropertyChanged(name, DBusAdaptor::BoolToVariant(value));
45}
46
47void DeviceDBusAdaptor::EmitUintChanged(const std::string& name, uint32 value) {
Chris Masone8fe2c7e2011-06-09 15:51:19 -070048 PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value));
Chris Masoned0ceb8c2011-06-02 10:05:39 -070049}
50
51void DeviceDBusAdaptor::EmitIntChanged(const std::string& name, int value) {
Chris Masone8fe2c7e2011-06-09 15:51:19 -070052 PropertyChanged(name, DBusAdaptor::Int32ToVariant(value));
Chris Masoned0ceb8c2011-06-02 10:05:39 -070053}
54
55void DeviceDBusAdaptor::EmitStringChanged(const std::string& name,
56 const std::string& value) {
57 PropertyChanged(name, DBusAdaptor::StringToVariant(value));
58}
59
Darin Petkov3cfbf212011-11-21 16:02:09 +010060void DeviceDBusAdaptor::EmitStringmapsChanged(const std::string &name,
61 const Stringmaps &value) {
62 PropertyChanged(name, DBusAdaptor::StringmapsToVariant(value));
63}
64
Darin Petkov63138a92012-02-06 14:09:15 +010065void DeviceDBusAdaptor::EmitKeyValueStoreChanged(const std::string &name,
66 const KeyValueStore &value) {
67 PropertyChanged(name, DBusAdaptor::KeyValueStoreToVariant(value));
68}
69
Chris Masoned7732e42011-05-20 11:08:56 -070070map<string, ::DBus::Variant> DeviceDBusAdaptor::GetProperties(
71 ::DBus::Error &error) {
Chris Masonea8a2c252011-06-27 22:16:30 -070072 map<string, ::DBus::Variant> properties;
Chris Masone27c4aa52011-07-02 13:10:14 -070073 DBusAdaptor::GetProperties(device_->store(), &properties, &error);
Chris Masonea8a2c252011-06-27 22:16:30 -070074 return properties;
Chris Masoned7732e42011-05-20 11:08:56 -070075}
76
mukesh agrawal4d0401c2012-01-06 16:05:31 -080077void DeviceDBusAdaptor::SetProperty(const string &name,
78 const ::DBus::Variant &value,
Chris Masoned7732e42011-05-20 11:08:56 -070079 ::DBus::Error &error) {
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -080080 DBusAdaptor::SetProperty(device_->mutable_store(), name, value, &error);
Chris Masoned7732e42011-05-20 11:08:56 -070081}
82
mukesh agrawal4d0401c2012-01-06 16:05:31 -080083void DeviceDBusAdaptor::ClearProperty(const std::string &name,
mukesh agrawal8abd2f62012-01-30 14:56:14 -080084 ::DBus::Error &error) {
85 DBusAdaptor::ClearProperty(device_->mutable_store(), name, &error);
Chris Masoneccc88812011-06-08 18:00:10 -070086}
87
Eric Shienbrood9a245532012-03-07 14:20:39 -050088void DeviceDBusAdaptor::Enable(::DBus::Error &error) {
89 Error e(Error::kOperationInitiated);
90 DBus::Tag *tag = new DBus::Tag();
91 device_->SetEnabledPersistent(true, &e, GetMethodReplyCallback(tag));
92 ReturnResultOrDefer(tag, e, &error);
93}
94
95void DeviceDBusAdaptor::Disable(::DBus::Error &error) {
96 Error e(Error::kOperationInitiated);
97 DBus::Tag *tag = new DBus::Tag();
98 device_->SetEnabledPersistent(false, &e, GetMethodReplyCallback(tag));
99 ReturnResultOrDefer(tag, e, &error);
100}
101
Chris Masoned7732e42011-05-20 11:08:56 -0700102void DeviceDBusAdaptor::ProposeScan(::DBus::Error &error) {
Darin Petkovc0865312011-09-16 15:31:20 -0700103 Error e;
104 device_->Scan(&e);
105 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700106}
107
108::DBus::Path DeviceDBusAdaptor::AddIPConfig(const string& ,
mukesh agrawal1830fa12011-09-26 14:31:40 -0700109 ::DBus::Error &/*error*/) {
Darin Petkovfd164b82012-02-10 14:11:52 +0100110 return "/";
Chris Masoned7732e42011-05-20 11:08:56 -0700111}
112
Darin Petkov9ae310f2011-08-30 15:41:13 -0700113void DeviceDBusAdaptor::Register(const string &network_id,
114 ::DBus::Error &error) {
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500115 VLOG(2) << __func__ << "(" << network_id << ")";
Eric Shienbrood9a245532012-03-07 14:20:39 -0500116 Error e(Error::kOperationInitiated);
117 DBus::Tag *tag = new DBus::Tag();
118 device_->RegisterOnNetwork(network_id, &e, GetMethodReplyCallback(tag));
119 ReturnResultOrDefer(tag, e, &error);
Chris Masoneccc88812011-06-08 18:00:10 -0700120}
121
Darin Petkovc64fe5e2012-01-11 12:46:13 +0100122void DeviceDBusAdaptor::RequirePin(
123 const string &pin, const bool &require, DBus::Error &error) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500124 Error e(Error::kOperationInitiated);
125 DBus::Tag *tag = new DBus::Tag();
126 device_->RequirePIN(pin, require, &e, GetMethodReplyCallback(tag));
127 ReturnResultOrDefer(tag, e, &error);
Chris Masoneccc88812011-06-08 18:00:10 -0700128}
129
Darin Petkovc64fe5e2012-01-11 12:46:13 +0100130void DeviceDBusAdaptor::EnterPin(const string &pin, DBus::Error &error) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500131 Error e(Error::kOperationInitiated);
132 DBus::Tag *tag = new DBus::Tag();
133 device_->EnterPIN(pin, &e, GetMethodReplyCallback(tag));
134 ReturnResultOrDefer(tag, e, &error);
Chris Masoneccc88812011-06-08 18:00:10 -0700135}
136
Darin Petkovc64fe5e2012-01-11 12:46:13 +0100137void DeviceDBusAdaptor::UnblockPin(
138 const string &unblock_code, const string &pin, DBus::Error &error) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500139 Error e(Error::kOperationInitiated);
140 DBus::Tag *tag = new DBus::Tag();
141 device_->UnblockPIN(unblock_code, pin, &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::ChangePin(
146 const string &old_pin, const string &new_pin, DBus::Error &error) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500147 Error e;
148 DBus::Tag *tag = new DBus::Tag();
149 device_->ChangePIN(old_pin, new_pin, &e, GetMethodReplyCallback(tag));
150 ReturnResultOrDefer(tag, e, &error);
Chris Masoneccc88812011-06-08 18:00:10 -0700151}
152
Chris Masoned7732e42011-05-20 11:08:56 -0700153} // namespace shill