blob: 92f19aace3e08201e655df1b8c68771143a5e0bb [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
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)
Chris Masonea82b7112011-05-25 15:16:29 -070024 : DBusAdaptor(conn, kPath + service->UniqueName()),
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) {
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) {
38 PropertyChanged(name, DBusAdaptor::ByteToVariant(value));
39}
40
mukesh agrawale1d90e92012-02-15 17:36:08 -080041void ServiceDBusAdaptor::EmitUint16Changed(const string &name, uint16 value) {
42 PropertyChanged(name, DBusAdaptor::Uint16ToVariant(value));
43}
44
Darin Petkovd78ee7e2012-01-12 11:21:10 +010045void ServiceDBusAdaptor::EmitUintChanged(const string &name, uint32 value) {
Chris Masone8fe2c7e2011-06-09 15:51:19 -070046 PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value));
Chris Masoned0ceb8c2011-06-02 10:05:39 -070047}
48
Darin Petkovd78ee7e2012-01-12 11:21:10 +010049void ServiceDBusAdaptor::EmitIntChanged(const string &name, int value) {
Chris Masone8fe2c7e2011-06-09 15:51:19 -070050 PropertyChanged(name, DBusAdaptor::Int32ToVariant(value));
Chris Masoned0ceb8c2011-06-02 10:05:39 -070051}
52
Darin Petkovd78ee7e2012-01-12 11:21:10 +010053void ServiceDBusAdaptor::EmitStringChanged(const string &name,
54 const string &value) {
Chris Masoned0ceb8c2011-06-02 10:05:39 -070055 PropertyChanged(name, DBusAdaptor::StringToVariant(value));
Darin Petkov9cb02682012-01-28 00:17:38 +010056}
Chris Masoned0ceb8c2011-06-02 10:05:39 -070057
Darin Petkov9cb02682012-01-28 00:17:38 +010058void ServiceDBusAdaptor::EmitStringmapChanged(const string &name,
59 const Stringmap &value) {
60 PropertyChanged(name, DBusAdaptor::StringmapToVariant(value));
Chris Masoned0ceb8c2011-06-02 10:05:39 -070061}
62
Chris Masoned7732e42011-05-20 11:08:56 -070063map<string, ::DBus::Variant> ServiceDBusAdaptor::GetProperties(
64 ::DBus::Error &error) {
Chris Masonea8a2c252011-06-27 22:16:30 -070065 map<string, ::DBus::Variant> properties;
Chris Masone27c4aa52011-07-02 13:10:14 -070066 DBusAdaptor::GetProperties(service_->store(), &properties, &error);
Chris Masonea8a2c252011-06-27 22:16:30 -070067 return properties;
Chris Masoned7732e42011-05-20 11:08:56 -070068}
69
mukesh agrawal4d0401c2012-01-06 16:05:31 -080070void ServiceDBusAdaptor::SetProperty(const string &name,
71 const ::DBus::Variant &value,
Chris Masoned7732e42011-05-20 11:08:56 -070072 ::DBus::Error &error) {
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -080073 DBusAdaptor::SetProperty(service_->mutable_store(), name, value, &error);
Chris Masoned7732e42011-05-20 11:08:56 -070074}
75
mukesh agrawal4d0401c2012-01-06 16:05:31 -080076void ServiceDBusAdaptor::ClearProperty(const string &name,
mukesh agrawal8abd2f62012-01-30 14:56:14 -080077 ::DBus::Error &error) {
78 DBusAdaptor::ClearProperty(service_->mutable_store(), name, &error);
Chris Masoned7732e42011-05-20 11:08:56 -070079}
80
81void ServiceDBusAdaptor::Connect(::DBus::Error &error) {
Darin Petkov4d6d9412011-08-24 13:19:54 -070082 Error e;
83 service_->Connect(&e);
84 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -070085}
86
mukesh agrawal0ed0f2e2011-12-05 20:36:17 +000087void ServiceDBusAdaptor::Disconnect(::DBus::Error &error) {
88 Error e;
89 service_->Disconnect(&e);
90 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -070091}
92
mukesh agrawal1830fa12011-09-26 14:31:40 -070093void ServiceDBusAdaptor::Remove(::DBus::Error &/*error*/) {
Chris Masoned7732e42011-05-20 11:08:56 -070094}
95
96void ServiceDBusAdaptor::MoveBefore(const ::DBus::Path& ,
mukesh agrawal1830fa12011-09-26 14:31:40 -070097 ::DBus::Error &/*error*/) {
Chris Masoned7732e42011-05-20 11:08:56 -070098}
99
100void ServiceDBusAdaptor::MoveAfter(const ::DBus::Path& ,
mukesh agrawal1830fa12011-09-26 14:31:40 -0700101 ::DBus::Error &/*error*/) {
Chris Masoned7732e42011-05-20 11:08:56 -0700102}
103
Darin Petkovc408e692011-08-17 13:47:15 -0700104void ServiceDBusAdaptor::ActivateCellularModem(const string &carrier,
Chris Masoned7732e42011-05-20 11:08:56 -0700105 ::DBus::Error &error) {
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500106 VLOG(2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500107 Error e(Error::kOperationInitiated);
108 DBus::Tag *tag = new DBus::Tag();
109 service_->ActivateCellularModem(carrier, &e, GetMethodReplyCallback(tag));
110 ReturnResultOrDefer(tag, e, &error);
Chris Masoned7732e42011-05-20 11:08:56 -0700111}
112
113} // namespace shill