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 | c6c6c13 | 2011-06-30 11:29:52 -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/ipconfig_dbus_adaptor.h" |
| 6 | |
| 7 | #include <map> |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 11 | #include <base/strings/stringprintf.h> |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 12 | #include <dbus-c++/dbus.h> |
| 13 | |
| 14 | #include "shill/error.h" |
| 15 | #include "shill/ipconfig.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 16 | #include "shill/logging.h" |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 17 | |
Chris Masone | 0756f23 | 2011-07-21 17:24:00 -0700 | [diff] [blame] | 18 | using base::StringPrintf; |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 19 | using std::map; |
| 20 | using std::string; |
| 21 | using std::vector; |
| 22 | |
| 23 | namespace shill { |
| 24 | |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 25 | namespace Logging { |
| 26 | static auto kModuleLogScope = ScopeLogger::kDBus; |
Paul Stewart | 8ae1874 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 27 | static string ObjectID(IPConfigDBusAdaptor* i) { return i->GetRpcIdentifier(); } |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 28 | } |
| 29 | |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 30 | // static |
Chris Masone | 0756f23 | 2011-07-21 17:24:00 -0700 | [diff] [blame] | 31 | const char IPConfigDBusAdaptor::kPath[] = "/ipconfig/"; |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 32 | |
Paul Stewart | 8ae1874 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 33 | IPConfigDBusAdaptor::IPConfigDBusAdaptor(DBus::Connection* conn, |
| 34 | IPConfig* config) |
Chris Masone | 0756f23 | 2011-07-21 17:24:00 -0700 | [diff] [blame] | 35 | : DBusAdaptor(conn, StringPrintf("%s%s_%u_%s", |
| 36 | kPath, |
Paul Stewart | f3b3840 | 2015-01-16 12:59:03 -0800 | [diff] [blame] | 37 | SanitizePathElement( |
| 38 | config->device_name()).c_str(), |
Chris Masone | 0756f23 | 2011-07-21 17:24:00 -0700 | [diff] [blame] | 39 | config->serial(), |
| 40 | config->type().c_str())), |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 41 | ipconfig_(config) { |
| 42 | } |
| 43 | |
| 44 | IPConfigDBusAdaptor::~IPConfigDBusAdaptor() { |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 45 | ipconfig_ = nullptr; |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Paul Stewart | 8ae1874 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 48 | void IPConfigDBusAdaptor::EmitBoolChanged(const string& name, bool value) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 49 | SLOG(this, 2) << __func__ << ": " << name; |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 50 | PropertyChanged(name, DBusAdaptor::BoolToVariant(value)); |
| 51 | } |
| 52 | |
Paul Stewart | 8ae1874 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 53 | void IPConfigDBusAdaptor::EmitUintChanged(const string& name, |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 54 | uint32_t value) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 55 | SLOG(this, 2) << __func__ << ": " << name; |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 56 | PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value)); |
| 57 | } |
| 58 | |
Paul Stewart | 8ae1874 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 59 | void IPConfigDBusAdaptor::EmitIntChanged(const string& name, int value) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 60 | SLOG(this, 2) << __func__ << ": " << name; |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 61 | PropertyChanged(name, DBusAdaptor::Int32ToVariant(value)); |
| 62 | } |
| 63 | |
Paul Stewart | 8ae1874 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 64 | void IPConfigDBusAdaptor::EmitStringChanged(const string& name, |
| 65 | const string& value) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 66 | SLOG(this, 2) << __func__ << ": " << name; |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 67 | PropertyChanged(name, DBusAdaptor::StringToVariant(value)); |
| 68 | } |
| 69 | |
Paul Stewart | 8ae1874 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 70 | void IPConfigDBusAdaptor::EmitStringsChanged(const string& name, |
| 71 | const vector<string>& value) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 72 | SLOG(this, 2) << __func__ << ": " << name; |
mukesh agrawal | 7aed61c | 2013-04-22 16:01:24 -0700 | [diff] [blame] | 73 | PropertyChanged(name, DBusAdaptor::StringsToVariant(value)); |
| 74 | } |
| 75 | |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 76 | map<string, DBus::Variant> IPConfigDBusAdaptor::GetProperties( |
Paul Stewart | 8ae1874 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 77 | DBus::Error& error) { // NOLINT |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 78 | SLOG(this, 2) << __func__; |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 79 | map<string, DBus::Variant> properties; |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 80 | DBusAdaptor::GetProperties(ipconfig_->store(), &properties, &error); |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 81 | return properties; |
| 82 | } |
| 83 | |
Paul Stewart | 8ae1874 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 84 | void IPConfigDBusAdaptor::SetProperty(const string& name, |
| 85 | const DBus::Variant& value, |
| 86 | DBus::Error& error) { // NOLINT |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 87 | SLOG(this, 2) << __func__ << ": " << name; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 88 | if (DBusAdaptor::SetProperty(ipconfig_->mutable_store(), |
| 89 | name, |
| 90 | value, |
| 91 | &error)) { |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 92 | PropertyChanged(name, value); |
| 93 | } |
| 94 | } |
| 95 | |
Paul Stewart | 8ae1874 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 96 | void IPConfigDBusAdaptor::ClearProperty(const string& name, |
| 97 | DBus::Error& error) { // NOLINT |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 98 | SLOG(this, 2) << __func__ << ": " << name; |
mukesh agrawal | 8abd2f6 | 2012-01-30 14:56:14 -0800 | [diff] [blame] | 99 | DBusAdaptor::ClearProperty(ipconfig_->mutable_store(), name, &error); |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Paul Stewart | 8ae1874 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 102 | void IPConfigDBusAdaptor::Remove(DBus::Error& /*error*/) { // NOLINT |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 103 | SLOG(this, 2) << __func__; |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Paul Stewart | 8ae1874 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 106 | void IPConfigDBusAdaptor::Refresh(DBus::Error& error) { // NOLINT |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 107 | SLOG(this, 2) << __func__; |
Paul Stewart | 4558bda | 2012-08-03 10:44:10 -0700 | [diff] [blame] | 108 | Error e; |
| 109 | ipconfig_->Refresh(&e); |
| 110 | e.ToDBusError(&error); |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | } // namespace shill |