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