mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 2 | // 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 Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 10 | #include <base/logging.h> |
| 11 | |
| 12 | #include "shill/error.h" |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 13 | #include "shill/service.h" |
| 14 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 15 | using std::map; |
| 16 | using std::string; |
| 17 | |
| 18 | namespace shill { |
| 19 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 20 | // static |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 21 | const char ServiceDBusAdaptor::kPath[] = "/service/"; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 22 | |
Chris Masone | ec6b18b | 2011-06-08 14:09:10 -0700 | [diff] [blame] | 23 | ServiceDBusAdaptor::ServiceDBusAdaptor(DBus::Connection* conn, Service *service) |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 24 | : DBusAdaptor(conn, kPath + service->UniqueName()), |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 25 | service_(service) {} |
Chris Masone | ec6b18b | 2011-06-08 14:09:10 -0700 | [diff] [blame] | 26 | |
| 27 | ServiceDBusAdaptor::~ServiceDBusAdaptor() { |
| 28 | service_ = NULL; |
| 29 | } |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 30 | |
| 31 | void ServiceDBusAdaptor::UpdateConnected() {} |
| 32 | |
Darin Petkov | d78ee7e | 2012-01-12 11:21:10 +0100 | [diff] [blame] | 33 | void ServiceDBusAdaptor::EmitBoolChanged(const string &name, bool value) { |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 34 | PropertyChanged(name, DBusAdaptor::BoolToVariant(value)); |
| 35 | } |
| 36 | |
Darin Petkov | d78ee7e | 2012-01-12 11:21:10 +0100 | [diff] [blame] | 37 | void ServiceDBusAdaptor::EmitUint8Changed(const string &name, uint8 value) { |
| 38 | PropertyChanged(name, DBusAdaptor::ByteToVariant(value)); |
| 39 | } |
| 40 | |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 41 | void ServiceDBusAdaptor::EmitUint16Changed(const string &name, uint16 value) { |
| 42 | PropertyChanged(name, DBusAdaptor::Uint16ToVariant(value)); |
| 43 | } |
| 44 | |
Darin Petkov | d78ee7e | 2012-01-12 11:21:10 +0100 | [diff] [blame] | 45 | void ServiceDBusAdaptor::EmitUintChanged(const string &name, uint32 value) { |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 46 | PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value)); |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Darin Petkov | d78ee7e | 2012-01-12 11:21:10 +0100 | [diff] [blame] | 49 | void ServiceDBusAdaptor::EmitIntChanged(const string &name, int value) { |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 50 | PropertyChanged(name, DBusAdaptor::Int32ToVariant(value)); |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Darin Petkov | d78ee7e | 2012-01-12 11:21:10 +0100 | [diff] [blame] | 53 | void ServiceDBusAdaptor::EmitStringChanged(const string &name, |
| 54 | const string &value) { |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 55 | PropertyChanged(name, DBusAdaptor::StringToVariant(value)); |
Darin Petkov | 9cb0268 | 2012-01-28 00:17:38 +0100 | [diff] [blame] | 56 | } |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 57 | |
Darin Petkov | 9cb0268 | 2012-01-28 00:17:38 +0100 | [diff] [blame] | 58 | void ServiceDBusAdaptor::EmitStringmapChanged(const string &name, |
| 59 | const Stringmap &value) { |
| 60 | PropertyChanged(name, DBusAdaptor::StringmapToVariant(value)); |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 63 | map<string, ::DBus::Variant> ServiceDBusAdaptor::GetProperties( |
| 64 | ::DBus::Error &error) { |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 65 | map<string, ::DBus::Variant> properties; |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 66 | DBusAdaptor::GetProperties(service_->store(), &properties, &error); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 67 | return properties; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 68 | } |
| 69 | |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 70 | void ServiceDBusAdaptor::SetProperty(const string &name, |
| 71 | const ::DBus::Variant &value, |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 72 | ::DBus::Error &error) { |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 73 | DBusAdaptor::SetProperty(service_->mutable_store(), name, value, &error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 74 | } |
| 75 | |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 76 | void ServiceDBusAdaptor::ClearProperty(const string &name, |
mukesh agrawal | 8abd2f6 | 2012-01-30 14:56:14 -0800 | [diff] [blame] | 77 | ::DBus::Error &error) { |
| 78 | DBusAdaptor::ClearProperty(service_->mutable_store(), name, &error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | void ServiceDBusAdaptor::Connect(::DBus::Error &error) { |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 82 | Error e; |
| 83 | service_->Connect(&e); |
| 84 | e.ToDBusError(&error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 85 | } |
| 86 | |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 87 | void ServiceDBusAdaptor::Disconnect(::DBus::Error &error) { |
| 88 | Error e; |
| 89 | service_->Disconnect(&e); |
| 90 | e.ToDBusError(&error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 91 | } |
| 92 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 93 | void ServiceDBusAdaptor::Remove(::DBus::Error &/*error*/) { |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | void ServiceDBusAdaptor::MoveBefore(const ::DBus::Path& , |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 97 | ::DBus::Error &/*error*/) { |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | void ServiceDBusAdaptor::MoveAfter(const ::DBus::Path& , |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 101 | ::DBus::Error &/*error*/) { |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 104 | void ServiceDBusAdaptor::ActivateCellularModem(const string &carrier, |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 105 | ::DBus::Error &error) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 106 | VLOG(2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 107 | Error e(Error::kOperationInitiated); |
| 108 | DBus::Tag *tag = new DBus::Tag(); |
| 109 | service_->ActivateCellularModem(carrier, &e, GetMethodReplyCallback(tag)); |
| 110 | ReturnResultOrDefer(tag, e, &error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | } // namespace shill |