blob: c59cd25015aad0486cff8267d13c9c03c8e6c591 [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
Chris Masoned7732e42011-05-20 11:08:56 -070065map<string, ::DBus::Variant> DeviceDBusAdaptor::GetProperties(
66 ::DBus::Error &error) {
Chris Masonea8a2c252011-06-27 22:16:30 -070067 map<string, ::DBus::Variant> properties;
Chris Masone27c4aa52011-07-02 13:10:14 -070068 DBusAdaptor::GetProperties(device_->store(), &properties, &error);
Chris Masonea8a2c252011-06-27 22:16:30 -070069 return properties;
Chris Masoned7732e42011-05-20 11:08:56 -070070}
71
mukesh agrawal4d0401c2012-01-06 16:05:31 -080072void DeviceDBusAdaptor::SetProperty(const string &name,
73 const ::DBus::Variant &value,
Chris Masoned7732e42011-05-20 11:08:56 -070074 ::DBus::Error &error) {
mukesh agrawalde29fa82011-09-16 16:16:36 -070075 DBusAdaptor::DispatchOnType(device_->mutable_store(), name, value, &error);
Chris Masoned7732e42011-05-20 11:08:56 -070076}
77
mukesh agrawal4d0401c2012-01-06 16:05:31 -080078void DeviceDBusAdaptor::ClearProperty(const std::string &name,
mukesh agrawal1830fa12011-09-26 14:31:40 -070079 ::DBus::Error &/*error*/) {
mukesh agrawal4d0401c2012-01-06 16:05:31 -080080 NOTIMPLEMENTED() << " Ignoring request to clear " << name
81 << " property of Device " << device_->FriendlyName();
Chris Masoneccc88812011-06-08 18:00:10 -070082}
83
Chris Masoned7732e42011-05-20 11:08:56 -070084void DeviceDBusAdaptor::ProposeScan(::DBus::Error &error) {
Darin Petkovc0865312011-09-16 15:31:20 -070085 Error e;
86 device_->Scan(&e);
87 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -070088}
89
90::DBus::Path DeviceDBusAdaptor::AddIPConfig(const string& ,
mukesh agrawal1830fa12011-09-26 14:31:40 -070091 ::DBus::Error &/*error*/) {
Chris Masoned7732e42011-05-20 11:08:56 -070092 return ::DBus::Path();
93}
94
Darin Petkov9ae310f2011-08-30 15:41:13 -070095void DeviceDBusAdaptor::Register(const string &network_id,
96 ::DBus::Error &error) {
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050097 VLOG(2) << __func__ << "(" << network_id << ")";
98 Returner *returner = Returner::Create(this);
99 device_->RegisterOnNetwork(network_id, returner);
100 returner->DelayOrReturn(&error);
Chris Masoneccc88812011-06-08 18:00:10 -0700101}
102
Darin Petkovc64fe5e2012-01-11 12:46:13 +0100103void DeviceDBusAdaptor::RequirePin(
104 const string &pin, const bool &require, DBus::Error &error) {
105 VLOG(2) << __func__;
106 Returner *returner = Returner::Create(this);
107 device_->RequirePIN(pin, require, returner);
108 returner->DelayOrReturn(&error);
Chris Masoneccc88812011-06-08 18:00:10 -0700109}
110
Darin Petkovc64fe5e2012-01-11 12:46:13 +0100111void DeviceDBusAdaptor::EnterPin(const string &pin, DBus::Error &error) {
Darin Petkove5bc2cb2011-12-07 14:47:32 +0100112 VLOG(2) << __func__;
113 Returner *returner = Returner::Create(this);
114 device_->EnterPIN(pin, returner);
115 returner->DelayOrReturn(&error);
Chris Masoneccc88812011-06-08 18:00:10 -0700116}
117
Darin Petkovc64fe5e2012-01-11 12:46:13 +0100118void DeviceDBusAdaptor::UnblockPin(
119 const string &unblock_code, const string &pin, DBus::Error &error) {
120 VLOG(2) << __func__;
121 Returner *returner = Returner::Create(this);
122 device_->UnblockPIN(unblock_code, pin, returner);
123 returner->DelayOrReturn(&error);
Chris Masoneccc88812011-06-08 18:00:10 -0700124}
125
Darin Petkovc64fe5e2012-01-11 12:46:13 +0100126void DeviceDBusAdaptor::ChangePin(
127 const string &old_pin, const string &new_pin, DBus::Error &error) {
128 VLOG(2) << __func__;
129 Returner *returner = Returner::Create(this);
130 device_->ChangePIN(old_pin, new_pin, returner);
131 returner->DelayOrReturn(&error);
Chris Masoneccc88812011-06-08 18:00:10 -0700132}
133
Chris Masoned7732e42011-05-20 11:08:56 -0700134} // namespace shill