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 | |
| 11 | #include <base/logging.h> |
Chris Masone | 0756f23 | 2011-07-21 17:24:00 -0700 | [diff] [blame] | 12 | #include <base/stringprintf.h> |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 13 | #include <dbus-c++/dbus.h> |
| 14 | |
| 15 | #include "shill/error.h" |
| 16 | #include "shill/ipconfig.h" |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 17 | #include "shill/scope_logger.h" |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 18 | |
Chris Masone | 0756f23 | 2011-07-21 17:24:00 -0700 | [diff] [blame] | 19 | using base::StringPrintf; |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 20 | using std::map; |
| 21 | using std::string; |
| 22 | using std::vector; |
| 23 | |
| 24 | namespace shill { |
| 25 | |
| 26 | // static |
Chris Masone | 0756f23 | 2011-07-21 17:24:00 -0700 | [diff] [blame] | 27 | const char IPConfigDBusAdaptor::kPath[] = "/ipconfig/"; |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 28 | |
| 29 | IPConfigDBusAdaptor::IPConfigDBusAdaptor(DBus::Connection* conn, |
| 30 | IPConfig *config) |
Chris Masone | 0756f23 | 2011-07-21 17:24:00 -0700 | [diff] [blame] | 31 | : DBusAdaptor(conn, StringPrintf("%s%s_%u_%s", |
| 32 | kPath, |
| 33 | config->device_name().c_str(), |
| 34 | config->serial(), |
| 35 | config->type().c_str())), |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 36 | ipconfig_(config) { |
| 37 | } |
| 38 | |
| 39 | IPConfigDBusAdaptor::~IPConfigDBusAdaptor() { |
| 40 | ipconfig_ = NULL; |
| 41 | } |
| 42 | |
| 43 | void IPConfigDBusAdaptor::EmitBoolChanged(const string &name, bool value) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 44 | SLOG(DBus, 2) << __func__ << ": " << name; |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 45 | PropertyChanged(name, DBusAdaptor::BoolToVariant(value)); |
| 46 | } |
| 47 | |
| 48 | void IPConfigDBusAdaptor::EmitUintChanged(const string &name, |
| 49 | uint32 value) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 50 | SLOG(DBus, 2) << __func__ << ": " << name; |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 51 | PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value)); |
| 52 | } |
| 53 | |
| 54 | void IPConfigDBusAdaptor::EmitIntChanged(const string &name, int value) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 55 | SLOG(DBus, 2) << __func__ << ": " << name; |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 56 | PropertyChanged(name, DBusAdaptor::Int32ToVariant(value)); |
| 57 | } |
| 58 | |
| 59 | void IPConfigDBusAdaptor::EmitStringChanged(const string &name, |
| 60 | const string &value) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 61 | SLOG(DBus, 2) << __func__ << ": " << name; |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 62 | PropertyChanged(name, DBusAdaptor::StringToVariant(value)); |
| 63 | } |
| 64 | |
| 65 | map<string, ::DBus::Variant> IPConfigDBusAdaptor::GetProperties( |
| 66 | ::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 67 | SLOG(DBus, 2) << __func__; |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 68 | map<string, ::DBus::Variant> properties; |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 69 | DBusAdaptor::GetProperties(ipconfig_->store(), &properties, &error); |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 70 | return properties; |
| 71 | } |
| 72 | |
| 73 | void IPConfigDBusAdaptor::SetProperty(const string &name, |
| 74 | const ::DBus::Variant &value, |
| 75 | ::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 76 | SLOG(DBus, 2) << __func__ << ": " << name; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 77 | if (DBusAdaptor::SetProperty(ipconfig_->mutable_store(), |
| 78 | name, |
| 79 | value, |
| 80 | &error)) { |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 81 | PropertyChanged(name, value); |
| 82 | } |
| 83 | } |
| 84 | |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 85 | void IPConfigDBusAdaptor::ClearProperty(const std::string &name, |
mukesh agrawal | 8abd2f6 | 2012-01-30 14:56:14 -0800 | [diff] [blame] | 86 | ::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 87 | SLOG(DBus, 2) << __func__ << ": " << name; |
mukesh agrawal | 8abd2f6 | 2012-01-30 14:56:14 -0800 | [diff] [blame] | 88 | DBusAdaptor::ClearProperty(ipconfig_->mutable_store(), name, &error); |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 89 | } |
| 90 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 91 | void IPConfigDBusAdaptor::Remove(::DBus::Error &/*error*/) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 92 | SLOG(DBus, 2) << __func__; |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 93 | } |
| 94 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 95 | void IPConfigDBusAdaptor::MoveBefore(const ::DBus::Path& /*path*/, |
| 96 | ::DBus::Error &/*error*/) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 97 | SLOG(DBus, 2) << __func__; |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 98 | } |
| 99 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 100 | void IPConfigDBusAdaptor::MoveAfter(const ::DBus::Path& /*path*/, |
| 101 | ::DBus::Error &/*error*/) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 102 | SLOG(DBus, 2) << __func__; |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | } // namespace shill |