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