blob: 1b640c2dd89c3f8517a645acddaaa8fe678481d5 [file] [log] [blame]
Chris Masoned7732e42011-05-20 11:08:56 -07001// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
2// 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
Chris Masoned7732e42011-05-20 11:08:56 -070060map<string, ::DBus::Variant> DeviceDBusAdaptor::GetProperties(
61 ::DBus::Error &error) {
Chris Masonea8a2c252011-06-27 22:16:30 -070062 map<string, ::DBus::Variant> properties;
Chris Masone27c4aa52011-07-02 13:10:14 -070063 DBusAdaptor::GetProperties(device_->store(), &properties, &error);
Chris Masonea8a2c252011-06-27 22:16:30 -070064 return properties;
Chris Masoned7732e42011-05-20 11:08:56 -070065}
66
Chris Masone8fe2c7e2011-06-09 15:51:19 -070067void DeviceDBusAdaptor::SetProperty(const string& name,
68 const ::DBus::Variant& value,
Chris Masoned7732e42011-05-20 11:08:56 -070069 ::DBus::Error &error) {
mukesh agrawalde29fa82011-09-16 16:16:36 -070070 DBusAdaptor::DispatchOnType(device_->mutable_store(), name, value, &error);
Chris Masoned7732e42011-05-20 11:08:56 -070071}
72
Chris Masoneccc88812011-06-08 18:00:10 -070073void DeviceDBusAdaptor::ClearProperty(const std::string& ,
74 ::DBus::Error &error) {
75}
76
Chris Masoned7732e42011-05-20 11:08:56 -070077void DeviceDBusAdaptor::ProposeScan(::DBus::Error &error) {
78}
79
80::DBus::Path DeviceDBusAdaptor::AddIPConfig(const string& ,
81 ::DBus::Error &error) {
82 return ::DBus::Path();
83}
84
Darin Petkov9ae310f2011-08-30 15:41:13 -070085void DeviceDBusAdaptor::Register(const string &network_id,
86 ::DBus::Error &error) {
87 Error e;
88 device_->RegisterOnNetwork(network_id, &e);
89 e.ToDBusError(&error);
Chris Masoneccc88812011-06-08 18:00:10 -070090}
91
Darin Petkove42e1012011-08-31 12:35:04 -070092void DeviceDBusAdaptor::RequirePin(const string &pin,
93 const bool &require,
Chris Masoneccc88812011-06-08 18:00:10 -070094 ::DBus::Error &error) {
Darin Petkove42e1012011-08-31 12:35:04 -070095 Error e;
96 device_->RequirePIN(pin, require, &e);
97 e.ToDBusError(&error);
Chris Masoneccc88812011-06-08 18:00:10 -070098}
99
Darin Petkove42e1012011-08-31 12:35:04 -0700100void DeviceDBusAdaptor::EnterPin(const string &pin, ::DBus::Error &error) {
101 Error e;
102 device_->EnterPIN(pin, &e);
103 e.ToDBusError(&error);
Chris Masoneccc88812011-06-08 18:00:10 -0700104}
105
Darin Petkove42e1012011-08-31 12:35:04 -0700106void DeviceDBusAdaptor::UnblockPin(const string &unblock_code,
107 const string &pin,
Chris Masoneccc88812011-06-08 18:00:10 -0700108 ::DBus::Error &error) {
Darin Petkove42e1012011-08-31 12:35:04 -0700109 Error e;
110 device_->UnblockPIN(unblock_code, pin, &e);
111 e.ToDBusError(&error);
Chris Masoneccc88812011-06-08 18:00:10 -0700112}
113
Darin Petkove42e1012011-08-31 12:35:04 -0700114void DeviceDBusAdaptor::ChangePin(const string &old_pin,
115 const string &new_pin,
Chris Masoneccc88812011-06-08 18:00:10 -0700116 ::DBus::Error &error) {
Darin Petkove42e1012011-08-31 12:35:04 -0700117 Error e;
118 device_->ChangePIN(old_pin, new_pin, &e);
119 e.ToDBusError(&error);
Chris Masoneccc88812011-06-08 18:00:10 -0700120}
121
Chris Masoned7732e42011-05-20 11:08:56 -0700122} // namespace shill