Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 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 |
| 21 | const char ServiceDBusAdaptor::kInterfaceName[] = SHILL_INTERFACE; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 22 | // static |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 23 | const char ServiceDBusAdaptor::kPath[] = "/service/"; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 24 | |
Chris Masone | ec6b18b | 2011-06-08 14:09:10 -0700 | [diff] [blame] | 25 | ServiceDBusAdaptor::ServiceDBusAdaptor(DBus::Connection* conn, Service *service) |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 26 | : DBusAdaptor(conn, kPath + service->UniqueName()), |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 27 | service_(service) {} |
Chris Masone | ec6b18b | 2011-06-08 14:09:10 -0700 | [diff] [blame] | 28 | |
| 29 | ServiceDBusAdaptor::~ServiceDBusAdaptor() { |
| 30 | service_ = NULL; |
| 31 | } |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 32 | |
| 33 | void ServiceDBusAdaptor::UpdateConnected() {} |
| 34 | |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 35 | void ServiceDBusAdaptor::EmitBoolChanged(const std::string& name, bool value) { |
| 36 | PropertyChanged(name, DBusAdaptor::BoolToVariant(value)); |
| 37 | } |
| 38 | |
| 39 | void ServiceDBusAdaptor::EmitUintChanged(const std::string& name, |
| 40 | uint32 value) { |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 41 | PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value)); |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | void ServiceDBusAdaptor::EmitIntChanged(const std::string& name, int value) { |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 45 | PropertyChanged(name, DBusAdaptor::Int32ToVariant(value)); |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | void ServiceDBusAdaptor::EmitStringChanged(const std::string& name, |
| 49 | const std::string& value) { |
| 50 | PropertyChanged(name, DBusAdaptor::StringToVariant(value)); |
| 51 | |
| 52 | } |
| 53 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 54 | map<string, ::DBus::Variant> ServiceDBusAdaptor::GetProperties( |
| 55 | ::DBus::Error &error) { |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 56 | map<string, ::DBus::Variant> properties; |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 57 | DBusAdaptor::GetProperties(service_->store(), &properties, &error); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 58 | return properties; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 61 | void ServiceDBusAdaptor::SetProperty(const string& name, |
| 62 | const ::DBus::Variant& value, |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 63 | ::DBus::Error &error) { |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 64 | DBusAdaptor::DispatchOnType(service_->store(), name, value, &error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void ServiceDBusAdaptor::ClearProperty(const string& , ::DBus::Error &error) { |
| 68 | } |
| 69 | |
| 70 | void ServiceDBusAdaptor::Connect(::DBus::Error &error) { |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 71 | Error e; |
| 72 | service_->Connect(&e); |
| 73 | e.ToDBusError(&error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void ServiceDBusAdaptor::Disconnect(::DBus::Error &error) { |
| 77 | } |
| 78 | |
| 79 | void ServiceDBusAdaptor::Remove(::DBus::Error &error) { |
| 80 | } |
| 81 | |
| 82 | void ServiceDBusAdaptor::MoveBefore(const ::DBus::Path& , |
| 83 | ::DBus::Error &error) { |
| 84 | } |
| 85 | |
| 86 | void ServiceDBusAdaptor::MoveAfter(const ::DBus::Path& , |
| 87 | ::DBus::Error &error) { |
| 88 | } |
| 89 | |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 90 | void ServiceDBusAdaptor::ActivateCellularModem(const string &carrier, |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 91 | ::DBus::Error &error) { |
Darin Petkov | b100ae7 | 2011-08-24 16:19:45 -0700 | [diff] [blame] | 92 | Error e; |
| 93 | service_->ActivateCellularModem(carrier, &e); |
| 94 | e.ToDBusError(&error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | } // namespace shill |