mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -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/profile_dbus_adaptor.h" |
| 6 | |
| 7 | #include <map> |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 11 | #include <dbus-c++/dbus.h> |
| 12 | |
| 13 | #include "shill/error.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 14 | #include "shill/logging.h" |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 15 | #include "shill/profile.h" |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 16 | #include "shill/service.h" |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 17 | |
| 18 | using std::map; |
| 19 | using std::string; |
| 20 | using std::vector; |
| 21 | |
| 22 | namespace shill { |
| 23 | |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 24 | namespace Logging { |
| 25 | static auto kModuleLogScope = ScopeLogger::kDBus; |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 26 | static string ObjectID(ProfileDBusAdaptor* p) { return p->GetRpcIdentifier(); } |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 30 | // static |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 31 | const char ProfileDBusAdaptor::kPath[] = "/profile/"; |
| 32 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 33 | ProfileDBusAdaptor::ProfileDBusAdaptor(DBus::Connection* conn, Profile* profile) |
Chris Masone | 7df0c67 | 2011-07-15 10:24:54 -0700 | [diff] [blame] | 34 | : DBusAdaptor(conn, kPath + profile->GetFriendlyName()), |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 35 | profile_(profile) { |
| 36 | } |
| 37 | |
| 38 | ProfileDBusAdaptor::~ProfileDBusAdaptor() { |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 39 | profile_ = nullptr; |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 42 | void ProfileDBusAdaptor::EmitBoolChanged(const string& name, bool value) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 43 | SLOG(this, 2) << __func__ << ": " << name; |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 44 | PropertyChanged(name, DBusAdaptor::BoolToVariant(value)); |
| 45 | } |
| 46 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 47 | void ProfileDBusAdaptor::EmitUintChanged(const string& name, |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 48 | uint32_t value) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 49 | SLOG(this, 2) << __func__ << ": " << name; |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 50 | PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value)); |
| 51 | } |
| 52 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 53 | void ProfileDBusAdaptor::EmitIntChanged(const string& name, int value) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 54 | SLOG(this, 2) << __func__ << ": " << name; |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 55 | PropertyChanged(name, DBusAdaptor::Int32ToVariant(value)); |
| 56 | } |
| 57 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 58 | void ProfileDBusAdaptor::EmitStringChanged(const string& name, |
| 59 | const string& value) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 60 | SLOG(this, 2) << __func__ << ": " << name; |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 61 | PropertyChanged(name, DBusAdaptor::StringToVariant(value)); |
| 62 | } |
| 63 | |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 64 | map<string, DBus::Variant> ProfileDBusAdaptor::GetProperties( |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 65 | DBus::Error& error) { // NOLINT |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 66 | SLOG(this, 2) << __func__; |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 67 | map<string, DBus::Variant> properties; |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 68 | DBusAdaptor::GetProperties(profile_->store(), &properties, &error); |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 69 | return properties; |
| 70 | } |
| 71 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 72 | void ProfileDBusAdaptor::SetProperty(const string& name, |
| 73 | const DBus::Variant& value, |
| 74 | DBus::Error& error) { // NOLINT |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 75 | SLOG(this, 2) << __func__ << ": " << name; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 76 | if (DBusAdaptor::SetProperty(profile_->mutable_store(), |
| 77 | name, |
| 78 | value, |
| 79 | &error)) { |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 80 | PropertyChanged(name, value); |
| 81 | } |
| 82 | } |
| 83 | |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 84 | map<string, DBus::Variant> ProfileDBusAdaptor::GetEntry( |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 85 | const std::string& name, |
| 86 | DBus::Error& error) { // NOLINT |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 87 | SLOG(this, 2) << __func__ << ": " << name; |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 88 | Error e; |
| 89 | ServiceRefPtr service = profile_->GetServiceFromEntry(name, &e); |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 90 | map<string, DBus::Variant> properties; |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 91 | if (e.IsSuccess()) { |
| 92 | DBusAdaptor::GetProperties(service->store(), &properties, &error); |
Peter Qiu | 1821365 | 2015-04-21 16:01:51 -0700 | [diff] [blame] | 93 | } else { |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 94 | e.ToDBusError(&error); |
| 95 | } |
| 96 | return properties; |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 99 | void ProfileDBusAdaptor::DeleteEntry(const std::string& name, |
| 100 | DBus::Error& error) { // NOLINT |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 101 | SLOG(this, 2) << __func__ << ": " << name; |
Paul Stewart | 7522551 | 2012-01-26 22:51:33 -0800 | [diff] [blame] | 102 | Error e; |
| 103 | profile_->DeleteEntry(name, &e); |
| 104 | e.ToDBusError(&error); |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | } // namespace shill |