blob: 0c56ba559d7dc1e466490663f49a83e26af568d9 [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;
16
17namespace shill {
18
Chris Masoned7732e42011-05-20 11:08:56 -070019// static
Chris Masonea82b7112011-05-25 15:16:29 -070020const char ServiceDBusAdaptor::kPath[] = "/service/";
Chris Masoned7732e42011-05-20 11:08:56 -070021
Chris Masoneec6b18b2011-06-08 14:09:10 -070022ServiceDBusAdaptor::ServiceDBusAdaptor(DBus::Connection* conn, Service *service)
Chris Masonea82b7112011-05-25 15:16:29 -070023 : DBusAdaptor(conn, kPath + service->UniqueName()),
Chris Masoned7732e42011-05-20 11:08:56 -070024 service_(service) {}
Chris Masoneec6b18b2011-06-08 14:09:10 -070025
26ServiceDBusAdaptor::~ServiceDBusAdaptor() {
27 service_ = NULL;
28}
Chris Masoned7732e42011-05-20 11:08:56 -070029
30void ServiceDBusAdaptor::UpdateConnected() {}
31
Darin Petkovd78ee7e2012-01-12 11:21:10 +010032void ServiceDBusAdaptor::EmitBoolChanged(const string &name, bool value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070033 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masoned0ceb8c2011-06-02 10:05:39 -070034 PropertyChanged(name, DBusAdaptor::BoolToVariant(value));
35}
36
Darin Petkovd78ee7e2012-01-12 11:21:10 +010037void ServiceDBusAdaptor::EmitUint8Changed(const string &name, uint8 value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070038 SLOG(DBus, 2) << __func__ << ": " << name;
Darin Petkovd78ee7e2012-01-12 11:21:10 +010039 PropertyChanged(name, DBusAdaptor::ByteToVariant(value));
40}
41
mukesh agrawale1d90e92012-02-15 17:36:08 -080042void ServiceDBusAdaptor::EmitUint16Changed(const string &name, uint16 value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070043 SLOG(DBus, 2) << __func__ << ": " << name;
mukesh agrawale1d90e92012-02-15 17:36:08 -080044 PropertyChanged(name, DBusAdaptor::Uint16ToVariant(value));
45}
46
Darin Petkovd78ee7e2012-01-12 11:21:10 +010047void ServiceDBusAdaptor::EmitUintChanged(const string &name, uint32 value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070048 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070049 PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value));
Chris Masoned0ceb8c2011-06-02 10:05:39 -070050}
51
Darin Petkovd78ee7e2012-01-12 11:21:10 +010052void ServiceDBusAdaptor::EmitIntChanged(const string &name, int value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070053 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070054 PropertyChanged(name, DBusAdaptor::Int32ToVariant(value));
Chris Masoned0ceb8c2011-06-02 10:05:39 -070055}
56
Darin Petkovd78ee7e2012-01-12 11:21:10 +010057void ServiceDBusAdaptor::EmitStringChanged(const string &name,
58 const string &value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070059 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masoned0ceb8c2011-06-02 10:05:39 -070060 PropertyChanged(name, DBusAdaptor::StringToVariant(value));
Darin Petkov9cb02682012-01-28 00:17:38 +010061}
Chris Masoned0ceb8c2011-06-02 10:05:39 -070062
Darin Petkov9cb02682012-01-28 00:17:38 +010063void ServiceDBusAdaptor::EmitStringmapChanged(const string &name,
64 const Stringmap &value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070065 SLOG(DBus, 2) << __func__ << ": " << name;
Darin Petkov9cb02682012-01-28 00:17:38 +010066 PropertyChanged(name, DBusAdaptor::StringmapToVariant(value));
Chris Masoned0ceb8c2011-06-02 10:05:39 -070067}
68
Chris Masoned7732e42011-05-20 11:08:56 -070069map<string, ::DBus::Variant> ServiceDBusAdaptor::GetProperties(
70 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070071 SLOG(DBus, 2) << __func__;
Chris Masonea8a2c252011-06-27 22:16:30 -070072 map<string, ::DBus::Variant> properties;
Chris Masone27c4aa52011-07-02 13:10:14 -070073 DBusAdaptor::GetProperties(service_->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 ServiceDBusAdaptor::SetProperty(const string &name,
78 const ::DBus::Variant &value,
Chris Masoned7732e42011-05-20 11:08:56 -070079 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070080 SLOG(DBus, 2) << __func__ << ": " << name;
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -080081 DBusAdaptor::SetProperty(service_->mutable_store(), name, value, &error);
Paul Stewartff14b022012-04-24 20:06:23 -070082 if (!error.is_set()) {
83 service_->OnPropertyChanged(name);
84 }
Chris Masoned7732e42011-05-20 11:08:56 -070085}
86
mukesh agrawal4d0401c2012-01-06 16:05:31 -080087void ServiceDBusAdaptor::ClearProperty(const string &name,
mukesh agrawal8abd2f62012-01-30 14:56:14 -080088 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070089 SLOG(DBus, 2) << __func__ << ": " << name;
mukesh agrawal8abd2f62012-01-30 14:56:14 -080090 DBusAdaptor::ClearProperty(service_->mutable_store(), name, &error);
Paul Stewartd215af62012-04-24 23:25:50 -070091 if (!error.is_set()) {
92 service_->OnPropertyChanged(name);
93 }
Chris Masoned7732e42011-05-20 11:08:56 -070094}
95
96void ServiceDBusAdaptor::Connect(::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070097 SLOG(DBus, 2) << __func__;
Darin Petkov4d6d9412011-08-24 13:19:54 -070098 Error e;
99 service_->Connect(&e);
100 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700101}
102
mukesh agrawal0ed0f2e2011-12-05 20:36:17 +0000103void ServiceDBusAdaptor::Disconnect(::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700104 SLOG(DBus, 2) << __func__;
mukesh agrawal0ed0f2e2011-12-05 20:36:17 +0000105 Error e;
106 service_->Disconnect(&e);
107 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700108}
109
mukesh agrawal1830fa12011-09-26 14:31:40 -0700110void ServiceDBusAdaptor::Remove(::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700111 SLOG(DBus, 2) << __func__;
Chris Masoned7732e42011-05-20 11:08:56 -0700112}
113
114void ServiceDBusAdaptor::MoveBefore(const ::DBus::Path& ,
mukesh agrawal1830fa12011-09-26 14:31:40 -0700115 ::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700116 SLOG(DBus, 2) << __func__;
Chris Masoned7732e42011-05-20 11:08:56 -0700117}
118
119void ServiceDBusAdaptor::MoveAfter(const ::DBus::Path& ,
mukesh agrawal1830fa12011-09-26 14:31:40 -0700120 ::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700121 SLOG(DBus, 2) << __func__;
Chris Masoned7732e42011-05-20 11:08:56 -0700122}
123
Darin Petkovc408e692011-08-17 13:47:15 -0700124void ServiceDBusAdaptor::ActivateCellularModem(const string &carrier,
Chris Masoned7732e42011-05-20 11:08:56 -0700125 ::DBus::Error &error) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700126 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500127 Error e(Error::kOperationInitiated);
128 DBus::Tag *tag = new DBus::Tag();
129 service_->ActivateCellularModem(carrier, &e, GetMethodReplyCallback(tag));
130 ReturnResultOrDefer(tag, e, &error);
Chris Masoned7732e42011-05-20 11:08:56 -0700131}
132
133} // namespace shill