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