blob: 1dcc351fc20d249d66609640e5ead44521586685 [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
mukesh agrawale7c7e652013-06-18 17:19:39 -070048void ServiceDBusAdaptor::EmitUint16sChanged(const string &name,
49 const Uint16s &value) {
50 SLOG(DBus, 2) << __func__ << ": " << name;
51 PropertyChanged(name, DBusAdaptor::Uint16sToVariant(value));
52}
53
Darin Petkovd78ee7e2012-01-12 11:21:10 +010054void ServiceDBusAdaptor::EmitUintChanged(const string &name, uint32 value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070055 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070056 PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value));
Chris Masoned0ceb8c2011-06-02 10:05:39 -070057}
58
Darin Petkovd78ee7e2012-01-12 11:21:10 +010059void ServiceDBusAdaptor::EmitIntChanged(const string &name, int value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070060 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070061 PropertyChanged(name, DBusAdaptor::Int32ToVariant(value));
Chris Masoned0ceb8c2011-06-02 10:05:39 -070062}
63
Paul Stewart1e3bc4962012-09-14 12:20:22 -070064void ServiceDBusAdaptor::EmitRpcIdentifierChanged(const string &name,
65 const string &value) {
66 SLOG(DBus, 2) << __func__ << ": " << name;
67 PropertyChanged(name, DBusAdaptor::PathToVariant(value));
68}
69
Darin Petkovd78ee7e2012-01-12 11:21:10 +010070void ServiceDBusAdaptor::EmitStringChanged(const string &name,
71 const string &value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070072 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masoned0ceb8c2011-06-02 10:05:39 -070073 PropertyChanged(name, DBusAdaptor::StringToVariant(value));
Darin Petkov9cb02682012-01-28 00:17:38 +010074}
Chris Masoned0ceb8c2011-06-02 10:05:39 -070075
Darin Petkov9cb02682012-01-28 00:17:38 +010076void ServiceDBusAdaptor::EmitStringmapChanged(const string &name,
77 const Stringmap &value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070078 SLOG(DBus, 2) << __func__ << ": " << name;
Darin Petkov9cb02682012-01-28 00:17:38 +010079 PropertyChanged(name, DBusAdaptor::StringmapToVariant(value));
Chris Masoned0ceb8c2011-06-02 10:05:39 -070080}
81
Chris Masoned7732e42011-05-20 11:08:56 -070082map<string, ::DBus::Variant> ServiceDBusAdaptor::GetProperties(
83 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070084 SLOG(DBus, 2) << __func__;
Chris Masonea8a2c252011-06-27 22:16:30 -070085 map<string, ::DBus::Variant> properties;
Chris Masone27c4aa52011-07-02 13:10:14 -070086 DBusAdaptor::GetProperties(service_->store(), &properties, &error);
Chris Masonea8a2c252011-06-27 22:16:30 -070087 return properties;
Chris Masoned7732e42011-05-20 11:08:56 -070088}
89
mukesh agrawal4d0401c2012-01-06 16:05:31 -080090void ServiceDBusAdaptor::SetProperty(const string &name,
91 const ::DBus::Variant &value,
Chris Masoned7732e42011-05-20 11:08:56 -070092 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070093 SLOG(DBus, 2) << __func__ << ": " << name;
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -080094 DBusAdaptor::SetProperty(service_->mutable_store(), name, value, &error);
Chris Masoned7732e42011-05-20 11:08:56 -070095}
96
mukesh agrawal4d0401c2012-01-06 16:05:31 -080097void ServiceDBusAdaptor::ClearProperty(const string &name,
mukesh agrawal8abd2f62012-01-30 14:56:14 -080098 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070099 SLOG(DBus, 2) << __func__ << ": " << name;
mukesh agrawal8abd2f62012-01-30 14:56:14 -0800100 DBusAdaptor::ClearProperty(service_->mutable_store(), name, &error);
Paul Stewartd215af62012-04-24 23:25:50 -0700101 if (!error.is_set()) {
102 service_->OnPropertyChanged(name);
103 }
Chris Masoned7732e42011-05-20 11:08:56 -0700104}
105
Paul Stewartbcb2c962012-10-31 10:52:10 -0700106vector<bool> ServiceDBusAdaptor::ClearProperties(const vector<string> &names,
107 ::DBus::Error &/*error*/) {
108 SLOG(DBus, 2) << __func__;
109 vector<bool> results;
110 vector<string>::const_iterator it;
111 for (it = names.begin(); it != names.end(); ++it) {
112 ::DBus::Error error;
113 ClearProperty(*it, error);
114 results.push_back(!error.is_set());
115 }
116 return results;
117}
118
Chris Masoned7732e42011-05-20 11:08:56 -0700119void ServiceDBusAdaptor::Connect(::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700120 SLOG(DBus, 2) << __func__;
Darin Petkov4d6d9412011-08-24 13:19:54 -0700121 Error e;
mukesh agrawaldc7b8442012-09-27 13:48:14 -0700122 service_->Connect(&e, "D-Bus RPC");
Darin Petkov4d6d9412011-08-24 13:19:54 -0700123 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700124}
125
mukesh agrawal0ed0f2e2011-12-05 20:36:17 +0000126void ServiceDBusAdaptor::Disconnect(::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700127 SLOG(DBus, 2) << __func__;
mukesh agrawal0ed0f2e2011-12-05 20:36:17 +0000128 Error e;
Christopher Wileyabd3b502012-09-26 13:08:52 -0700129 service_->UserInitiatedDisconnect(&e);
mukesh agrawal0ed0f2e2011-12-05 20:36:17 +0000130 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700131}
132
Albert Chaulk0e1cdea2013-02-27 15:32:55 -0800133void ServiceDBusAdaptor::Remove(::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700134 SLOG(DBus, 2) << __func__;
Albert Chaulk0e1cdea2013-02-27 15:32:55 -0800135 Error e;
136 service_->Remove(&e);
137 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700138}
139
140void ServiceDBusAdaptor::MoveBefore(const ::DBus::Path& ,
mukesh agrawal1830fa12011-09-26 14:31:40 -0700141 ::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700142 SLOG(DBus, 2) << __func__;
Chris Masoned7732e42011-05-20 11:08:56 -0700143}
144
145void ServiceDBusAdaptor::MoveAfter(const ::DBus::Path& ,
mukesh agrawal1830fa12011-09-26 14:31:40 -0700146 ::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700147 SLOG(DBus, 2) << __func__;
Chris Masoned7732e42011-05-20 11:08:56 -0700148}
149
Darin Petkovc408e692011-08-17 13:47:15 -0700150void ServiceDBusAdaptor::ActivateCellularModem(const string &carrier,
Chris Masoned7732e42011-05-20 11:08:56 -0700151 ::DBus::Error &error) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700152 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500153 Error e(Error::kOperationInitiated);
154 DBus::Tag *tag = new DBus::Tag();
155 service_->ActivateCellularModem(carrier, &e, GetMethodReplyCallback(tag));
156 ReturnResultOrDefer(tag, e, &error);
Chris Masoned7732e42011-05-20 11:08:56 -0700157}
158
Ben Chan5d924542013-02-14 17:49:08 -0800159void ServiceDBusAdaptor::CompleteCellularActivation(::DBus::Error &error) {
160 SLOG(DBus, 2) << __func__;
161 Error e;
162 service_->CompleteCellularActivation(&e);
163 e.ToDBusError(&error);
164}
165
Paul Stewart967eaeb2013-04-25 19:53:07 -0700166map<::DBus::Path, string> ServiceDBusAdaptor::GetLoadableProfileEntries(
167 ::DBus::Error &error) {
168 SLOG(DBus, 2) << __func__;
169 map<string, string> profile_entry_strings =
170 service_->GetLoadableProfileEntries();
171 map<::DBus::Path, string> profile_entries;
172 for (const auto &entry : profile_entry_strings) {
173 profile_entries[::DBus::Path(entry.first)] = entry.second;
174 }
175 return profile_entries;
176}
177
Chris Masoned7732e42011-05-20 11:08:56 -0700178} // namespace shill