blob: 7049b202036b928eb0f08968d078bac4431ec1c9 [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
Paul Stewart28fbfdf2011-05-31 09:37:38 -07005#include "shill/device.h"
Chris Masoned7732e42011-05-20 11:08:56 -07006#include "shill/device_dbus_adaptor.h"
7
8#include <map>
9#include <string>
10
Chris Masonea82b7112011-05-25 15:16:29 -070011#include "shill/device.h"
Chris Masone8fe2c7e2011-06-09 15:51:19 -070012#include "shill/error.h"
Chris Masonea82b7112011-05-25 15:16:29 -070013
Chris Masoned7732e42011-05-20 11:08:56 -070014using std::map;
15using std::string;
16
17namespace shill {
18
Chris Masoned7732e42011-05-20 11:08:56 -070019// static
Chris Masonea82b7112011-05-25 15:16:29 -070020const char DeviceDBusAdaptor::kInterfaceName[] = SHILL_INTERFACE;
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
Chris Masoned7732e42011-05-20 11:08:56 -070088void DeviceDBusAdaptor::ProposeScan(::DBus::Error &error) {
Darin Petkovc0865312011-09-16 15:31:20 -070089 Error e;
90 device_->Scan(&e);
91 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -070092}
93
94::DBus::Path DeviceDBusAdaptor::AddIPConfig(const string& ,
mukesh agrawal1830fa12011-09-26 14:31:40 -070095 ::DBus::Error &/*error*/) {
Darin Petkovfd164b82012-02-10 14:11:52 +010096 return "/";
Chris Masoned7732e42011-05-20 11:08:56 -070097}
98
Darin Petkov9ae310f2011-08-30 15:41:13 -070099void DeviceDBusAdaptor::Register(const string &network_id,
100 ::DBus::Error &error) {
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500101 VLOG(2) << __func__ << "(" << network_id << ")";
102 Returner *returner = Returner::Create(this);
103 device_->RegisterOnNetwork(network_id, returner);
104 returner->DelayOrReturn(&error);
Chris Masoneccc88812011-06-08 18:00:10 -0700105}
106
Darin Petkovc64fe5e2012-01-11 12:46:13 +0100107void DeviceDBusAdaptor::RequirePin(
108 const string &pin, const bool &require, DBus::Error &error) {
109 VLOG(2) << __func__;
110 Returner *returner = Returner::Create(this);
111 device_->RequirePIN(pin, require, returner);
112 returner->DelayOrReturn(&error);
Chris Masoneccc88812011-06-08 18:00:10 -0700113}
114
Darin Petkovc64fe5e2012-01-11 12:46:13 +0100115void DeviceDBusAdaptor::EnterPin(const string &pin, DBus::Error &error) {
Darin Petkove5bc2cb2011-12-07 14:47:32 +0100116 VLOG(2) << __func__;
117 Returner *returner = Returner::Create(this);
118 device_->EnterPIN(pin, returner);
119 returner->DelayOrReturn(&error);
Chris Masoneccc88812011-06-08 18:00:10 -0700120}
121
Darin Petkovc64fe5e2012-01-11 12:46:13 +0100122void DeviceDBusAdaptor::UnblockPin(
123 const string &unblock_code, const string &pin, DBus::Error &error) {
124 VLOG(2) << __func__;
125 Returner *returner = Returner::Create(this);
126 device_->UnblockPIN(unblock_code, pin, returner);
127 returner->DelayOrReturn(&error);
Chris Masoneccc88812011-06-08 18:00:10 -0700128}
129
Darin Petkovc64fe5e2012-01-11 12:46:13 +0100130void DeviceDBusAdaptor::ChangePin(
131 const string &old_pin, const string &new_pin, DBus::Error &error) {
132 VLOG(2) << __func__;
133 Returner *returner = Returner::Create(this);
134 device_->ChangePIN(old_pin, new_pin, returner);
135 returner->DelayOrReturn(&error);
Chris Masoneccc88812011-06-08 18:00:10 -0700136}
137
Chris Masoned7732e42011-05-20 11:08:56 -0700138} // namespace shill