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" |
| 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) { |
| 43 | PropertyChanged(name, DBusAdaptor::BoolToVariant(value)); |
| 44 | } |
| 45 | |
| 46 | void IPConfigDBusAdaptor::EmitUintChanged(const string &name, |
| 47 | uint32 value) { |
| 48 | PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value)); |
| 49 | } |
| 50 | |
| 51 | void IPConfigDBusAdaptor::EmitIntChanged(const string &name, int value) { |
| 52 | PropertyChanged(name, DBusAdaptor::Int32ToVariant(value)); |
| 53 | } |
| 54 | |
| 55 | void IPConfigDBusAdaptor::EmitStringChanged(const string &name, |
| 56 | const string &value) { |
| 57 | PropertyChanged(name, DBusAdaptor::StringToVariant(value)); |
| 58 | } |
| 59 | |
| 60 | map<string, ::DBus::Variant> IPConfigDBusAdaptor::GetProperties( |
| 61 | ::DBus::Error &error) { |
| 62 | map<string, ::DBus::Variant> properties; |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 63 | DBusAdaptor::GetProperties(ipconfig_->store(), &properties, &error); |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 64 | return properties; |
| 65 | } |
| 66 | |
| 67 | void IPConfigDBusAdaptor::SetProperty(const string &name, |
| 68 | const ::DBus::Variant &value, |
| 69 | ::DBus::Error &error) { |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 70 | if (DBusAdaptor::SetProperty(ipconfig_->mutable_store(), |
| 71 | name, |
| 72 | value, |
| 73 | &error)) { |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 74 | PropertyChanged(name, value); |
| 75 | } |
| 76 | } |
| 77 | |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 78 | void IPConfigDBusAdaptor::ClearProperty(const std::string &name, |
mukesh agrawal | 8abd2f6 | 2012-01-30 14:56:14 -0800 | [diff] [blame] | 79 | ::DBus::Error &error) { |
| 80 | DBusAdaptor::ClearProperty(ipconfig_->mutable_store(), name, &error); |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 81 | } |
| 82 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 83 | void IPConfigDBusAdaptor::Remove(::DBus::Error &/*error*/) { |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 84 | } |
| 85 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 86 | void IPConfigDBusAdaptor::MoveBefore(const ::DBus::Path& /*path*/, |
| 87 | ::DBus::Error &/*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::MoveAfter(const ::DBus::Path& /*path*/, |
| 91 | ::DBus::Error &/*error*/) { |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | } // namespace shill |