blob: 3597beb0cb7be4ce57e490366eec18a62fef08ea [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 <base/logging.h>
11
12#include "shill/error.h"
Chris Masonea82b7112011-05-25 15:16:29 -070013#include "shill/service.h"
14
Chris Masoned7732e42011-05-20 11:08:56 -070015using std::map;
16using std::string;
17
18namespace shill {
19
Chris Masoned7732e42011-05-20 11:08:56 -070020// static
21const char ServiceDBusAdaptor::kInterfaceName[] = SHILL_INTERFACE;
Chris Masoned7732e42011-05-20 11:08:56 -070022// static
Chris Masonea82b7112011-05-25 15:16:29 -070023const char ServiceDBusAdaptor::kPath[] = "/service/";
Chris Masoned7732e42011-05-20 11:08:56 -070024
Chris Masoneec6b18b2011-06-08 14:09:10 -070025ServiceDBusAdaptor::ServiceDBusAdaptor(DBus::Connection* conn, Service *service)
Chris Masonea82b7112011-05-25 15:16:29 -070026 : DBusAdaptor(conn, kPath + service->UniqueName()),
Chris Masoned7732e42011-05-20 11:08:56 -070027 service_(service) {}
Chris Masoneec6b18b2011-06-08 14:09:10 -070028
29ServiceDBusAdaptor::~ServiceDBusAdaptor() {
30 service_ = NULL;
31}
Chris Masoned7732e42011-05-20 11:08:56 -070032
33void ServiceDBusAdaptor::UpdateConnected() {}
34
Darin Petkovd78ee7e2012-01-12 11:21:10 +010035void ServiceDBusAdaptor::EmitBoolChanged(const string &name, bool value) {
Chris Masoned0ceb8c2011-06-02 10:05:39 -070036 PropertyChanged(name, DBusAdaptor::BoolToVariant(value));
37}
38
Darin Petkovd78ee7e2012-01-12 11:21:10 +010039void ServiceDBusAdaptor::EmitUint8Changed(const string &name, uint8 value) {
40 PropertyChanged(name, DBusAdaptor::ByteToVariant(value));
41}
42
mukesh agrawale1d90e92012-02-15 17:36:08 -080043void ServiceDBusAdaptor::EmitUint16Changed(const string &name, uint16 value) {
44 PropertyChanged(name, DBusAdaptor::Uint16ToVariant(value));
45}
46
Darin Petkovd78ee7e2012-01-12 11:21:10 +010047void ServiceDBusAdaptor::EmitUintChanged(const 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
Darin Petkovd78ee7e2012-01-12 11:21:10 +010051void ServiceDBusAdaptor::EmitIntChanged(const 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
Darin Petkovd78ee7e2012-01-12 11:21:10 +010055void ServiceDBusAdaptor::EmitStringChanged(const string &name,
56 const string &value) {
Chris Masoned0ceb8c2011-06-02 10:05:39 -070057 PropertyChanged(name, DBusAdaptor::StringToVariant(value));
Darin Petkov9cb02682012-01-28 00:17:38 +010058}
Chris Masoned0ceb8c2011-06-02 10:05:39 -070059
Darin Petkov9cb02682012-01-28 00:17:38 +010060void ServiceDBusAdaptor::EmitStringmapChanged(const string &name,
61 const Stringmap &value) {
62 PropertyChanged(name, DBusAdaptor::StringmapToVariant(value));
Chris Masoned0ceb8c2011-06-02 10:05:39 -070063}
64
Chris Masoned7732e42011-05-20 11:08:56 -070065map<string, ::DBus::Variant> ServiceDBusAdaptor::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(service_->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 ServiceDBusAdaptor::SetProperty(const string &name,
73 const ::DBus::Variant &value,
Chris Masoned7732e42011-05-20 11:08:56 -070074 ::DBus::Error &error) {
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -080075 DBusAdaptor::SetProperty(service_->mutable_store(), name, value, &error);
Chris Masoned7732e42011-05-20 11:08:56 -070076}
77
mukesh agrawal4d0401c2012-01-06 16:05:31 -080078void ServiceDBusAdaptor::ClearProperty(const string &name,
mukesh agrawal8abd2f62012-01-30 14:56:14 -080079 ::DBus::Error &error) {
80 DBusAdaptor::ClearProperty(service_->mutable_store(), name, &error);
Chris Masoned7732e42011-05-20 11:08:56 -070081}
82
83void ServiceDBusAdaptor::Connect(::DBus::Error &error) {
Darin Petkov4d6d9412011-08-24 13:19:54 -070084 Error e;
85 service_->Connect(&e);
86 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -070087}
88
mukesh agrawal0ed0f2e2011-12-05 20:36:17 +000089void ServiceDBusAdaptor::Disconnect(::DBus::Error &error) {
90 Error e;
91 service_->Disconnect(&e);
92 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -070093}
94
mukesh agrawal1830fa12011-09-26 14:31:40 -070095void ServiceDBusAdaptor::Remove(::DBus::Error &/*error*/) {
Chris Masoned7732e42011-05-20 11:08:56 -070096}
97
98void ServiceDBusAdaptor::MoveBefore(const ::DBus::Path& ,
mukesh agrawal1830fa12011-09-26 14:31:40 -070099 ::DBus::Error &/*error*/) {
Chris Masoned7732e42011-05-20 11:08:56 -0700100}
101
102void ServiceDBusAdaptor::MoveAfter(const ::DBus::Path& ,
mukesh agrawal1830fa12011-09-26 14:31:40 -0700103 ::DBus::Error &/*error*/) {
Chris Masoned7732e42011-05-20 11:08:56 -0700104}
105
Darin Petkovc408e692011-08-17 13:47:15 -0700106void ServiceDBusAdaptor::ActivateCellularModem(const string &carrier,
Chris Masoned7732e42011-05-20 11:08:56 -0700107 ::DBus::Error &error) {
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500108 VLOG(2) << __func__;
109 Returner *returner = Returner::Create(this);
110 service_->ActivateCellularModem(carrier, returner);
111 returner->DelayOrReturn(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700112}
113
114} // namespace shill