blob: d7068bc9be0da9ed32c6faf29d8b61afd0f7a4a2 [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/service_dbus_adaptor.h"
6
7#include <map>
8#include <string>
9
Chris Masone8fe2c7e2011-06-09 15:51:19 -070010#include "shill/error.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -070011#include "shill/logging.h"
Chris Masonea82b7112011-05-25 15:16:29 -070012#include "shill/service.h"
13
Chris Masoned7732e42011-05-20 11:08:56 -070014using std::map;
15using std::string;
Paul Stewartbcb2c962012-10-31 10:52:10 -070016using std::vector;
Chris Masoned7732e42011-05-20 11:08:56 -070017
18namespace shill {
19
Chris Masoned7732e42011-05-20 11:08:56 -070020// static
Chris Masonea82b7112011-05-25 15:16:29 -070021const char ServiceDBusAdaptor::kPath[] = "/service/";
Chris Masoned7732e42011-05-20 11:08:56 -070022
Chris Masoneec6b18b2011-06-08 14:09:10 -070023ServiceDBusAdaptor::ServiceDBusAdaptor(DBus::Connection* conn, Service *service)
Darin Petkov457728b2013-01-09 09:49:08 +010024 : DBusAdaptor(conn, kPath + service->unique_name()),
Chris Masoned7732e42011-05-20 11:08:56 -070025 service_(service) {}
Chris Masoneec6b18b2011-06-08 14:09:10 -070026
27ServiceDBusAdaptor::~ServiceDBusAdaptor() {
28 service_ = NULL;
29}
Chris Masoned7732e42011-05-20 11:08:56 -070030
31void ServiceDBusAdaptor::UpdateConnected() {}
32
Darin Petkovd78ee7e2012-01-12 11:21:10 +010033void ServiceDBusAdaptor::EmitBoolChanged(const string &name, bool value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070034 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masoned0ceb8c2011-06-02 10:05:39 -070035 PropertyChanged(name, DBusAdaptor::BoolToVariant(value));
36}
37
Darin Petkovd78ee7e2012-01-12 11:21:10 +010038void ServiceDBusAdaptor::EmitUint8Changed(const string &name, uint8 value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070039 SLOG(DBus, 2) << __func__ << ": " << name;
Darin Petkovd78ee7e2012-01-12 11:21:10 +010040 PropertyChanged(name, DBusAdaptor::ByteToVariant(value));
41}
42
mukesh agrawale1d90e92012-02-15 17:36:08 -080043void ServiceDBusAdaptor::EmitUint16Changed(const string &name, uint16 value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070044 SLOG(DBus, 2) << __func__ << ": " << name;
mukesh agrawale1d90e92012-02-15 17:36:08 -080045 PropertyChanged(name, DBusAdaptor::Uint16ToVariant(value));
46}
47
Darin Petkovd78ee7e2012-01-12 11:21:10 +010048void ServiceDBusAdaptor::EmitUintChanged(const string &name, uint32 value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070049 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070050 PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value));
Chris Masoned0ceb8c2011-06-02 10:05:39 -070051}
52
Darin Petkovd78ee7e2012-01-12 11:21:10 +010053void ServiceDBusAdaptor::EmitIntChanged(const string &name, int value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070054 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070055 PropertyChanged(name, DBusAdaptor::Int32ToVariant(value));
Chris Masoned0ceb8c2011-06-02 10:05:39 -070056}
57
Paul Stewart1e3bc4962012-09-14 12:20:22 -070058void ServiceDBusAdaptor::EmitRpcIdentifierChanged(const string &name,
59 const string &value) {
60 SLOG(DBus, 2) << __func__ << ": " << name;
61 PropertyChanged(name, DBusAdaptor::PathToVariant(value));
62}
63
Darin Petkovd78ee7e2012-01-12 11:21:10 +010064void ServiceDBusAdaptor::EmitStringChanged(const string &name,
65 const string &value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070066 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masoned0ceb8c2011-06-02 10:05:39 -070067 PropertyChanged(name, DBusAdaptor::StringToVariant(value));
Darin Petkov9cb02682012-01-28 00:17:38 +010068}
Chris Masoned0ceb8c2011-06-02 10:05:39 -070069
Darin Petkov9cb02682012-01-28 00:17:38 +010070void ServiceDBusAdaptor::EmitStringmapChanged(const string &name,
71 const Stringmap &value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070072 SLOG(DBus, 2) << __func__ << ": " << name;
Darin Petkov9cb02682012-01-28 00:17:38 +010073 PropertyChanged(name, DBusAdaptor::StringmapToVariant(value));
Chris Masoned0ceb8c2011-06-02 10:05:39 -070074}
75
Chris Masoned7732e42011-05-20 11:08:56 -070076map<string, ::DBus::Variant> ServiceDBusAdaptor::GetProperties(
77 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070078 SLOG(DBus, 2) << __func__;
Chris Masonea8a2c252011-06-27 22:16:30 -070079 map<string, ::DBus::Variant> properties;
Chris Masone27c4aa52011-07-02 13:10:14 -070080 DBusAdaptor::GetProperties(service_->store(), &properties, &error);
Chris Masonea8a2c252011-06-27 22:16:30 -070081 return properties;
Chris Masoned7732e42011-05-20 11:08:56 -070082}
83
mukesh agrawal4d0401c2012-01-06 16:05:31 -080084void ServiceDBusAdaptor::SetProperty(const string &name,
85 const ::DBus::Variant &value,
Chris Masoned7732e42011-05-20 11:08:56 -070086 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070087 SLOG(DBus, 2) << __func__ << ": " << name;
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -080088 DBusAdaptor::SetProperty(service_->mutable_store(), name, value, &error);
Chris Masoned7732e42011-05-20 11:08:56 -070089}
90
mukesh agrawal4d0401c2012-01-06 16:05:31 -080091void ServiceDBusAdaptor::ClearProperty(const string &name,
mukesh agrawal8abd2f62012-01-30 14:56:14 -080092 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070093 SLOG(DBus, 2) << __func__ << ": " << name;
mukesh agrawal8abd2f62012-01-30 14:56:14 -080094 DBusAdaptor::ClearProperty(service_->mutable_store(), name, &error);
Paul Stewartd215af62012-04-24 23:25:50 -070095 if (!error.is_set()) {
96 service_->OnPropertyChanged(name);
97 }
Chris Masoned7732e42011-05-20 11:08:56 -070098}
99
Paul Stewartbcb2c962012-10-31 10:52:10 -0700100vector<bool> ServiceDBusAdaptor::ClearProperties(const vector<string> &names,
101 ::DBus::Error &/*error*/) {
102 SLOG(DBus, 2) << __func__;
103 vector<bool> results;
104 vector<string>::const_iterator it;
105 for (it = names.begin(); it != names.end(); ++it) {
106 ::DBus::Error error;
107 ClearProperty(*it, error);
108 results.push_back(!error.is_set());
109 }
110 return results;
111}
112
Chris Masoned7732e42011-05-20 11:08:56 -0700113void ServiceDBusAdaptor::Connect(::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700114 SLOG(DBus, 2) << __func__;
Darin Petkov4d6d9412011-08-24 13:19:54 -0700115 Error e;
mukesh agrawaldc7b8442012-09-27 13:48:14 -0700116 service_->Connect(&e, "D-Bus RPC");
Darin Petkov4d6d9412011-08-24 13:19:54 -0700117 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700118}
119
mukesh agrawal0ed0f2e2011-12-05 20:36:17 +0000120void ServiceDBusAdaptor::Disconnect(::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700121 SLOG(DBus, 2) << __func__;
mukesh agrawal0ed0f2e2011-12-05 20:36:17 +0000122 Error e;
Christopher Wileyabd3b502012-09-26 13:08:52 -0700123 service_->UserInitiatedDisconnect(&e);
mukesh agrawal0ed0f2e2011-12-05 20:36:17 +0000124 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700125}
126
Albert Chaulk0e1cdea2013-02-27 15:32:55 -0800127void ServiceDBusAdaptor::Remove(::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700128 SLOG(DBus, 2) << __func__;
Albert Chaulk0e1cdea2013-02-27 15:32:55 -0800129 Error e;
130 service_->Remove(&e);
131 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700132}
133
134void ServiceDBusAdaptor::MoveBefore(const ::DBus::Path& ,
mukesh agrawal1830fa12011-09-26 14:31:40 -0700135 ::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700136 SLOG(DBus, 2) << __func__;
Chris Masoned7732e42011-05-20 11:08:56 -0700137}
138
139void ServiceDBusAdaptor::MoveAfter(const ::DBus::Path& ,
mukesh agrawal1830fa12011-09-26 14:31:40 -0700140 ::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700141 SLOG(DBus, 2) << __func__;
Chris Masoned7732e42011-05-20 11:08:56 -0700142}
143
Darin Petkovc408e692011-08-17 13:47:15 -0700144void ServiceDBusAdaptor::ActivateCellularModem(const string &carrier,
Chris Masoned7732e42011-05-20 11:08:56 -0700145 ::DBus::Error &error) {
Ben Chanfad4a0b2012-04-18 15:49:59 -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 service_->ActivateCellularModem(carrier, &e, GetMethodReplyCallback(tag));
150 ReturnResultOrDefer(tag, e, &error);
Chris Masoned7732e42011-05-20 11:08:56 -0700151}
152
Ben Chan5d924542013-02-14 17:49:08 -0800153void ServiceDBusAdaptor::CompleteCellularActivation(::DBus::Error &error) {
154 SLOG(DBus, 2) << __func__;
155 Error e;
156 service_->CompleteCellularActivation(&e);
157 e.ToDBusError(&error);
158}
159
Paul Stewart967eaeb2013-04-25 19:53:07 -0700160map<::DBus::Path, string> ServiceDBusAdaptor::GetLoadableProfileEntries(
161 ::DBus::Error &error) {
162 SLOG(DBus, 2) << __func__;
163 map<string, string> profile_entry_strings =
164 service_->GetLoadableProfileEntries();
165 map<::DBus::Path, string> profile_entries;
166 for (const auto &entry : profile_entry_strings) {
167 profile_entries[::DBus::Path(entry.first)] = entry.second;
168 }
169 return profile_entries;
170}
171
Chris Masoned7732e42011-05-20 11:08:56 -0700172} // namespace shill