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 | |
| 11 | #include <base/logging.h> |
| 12 | #include <dbus-c++/dbus.h> |
| 13 | |
| 14 | #include "shill/error.h" |
| 15 | #include "shill/profile.h" |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 16 | #include "shill/profile_dbus_property_exporter.h" |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 17 | #include "shill/scope_logger.h" |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 18 | #include "shill/service.h" |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 19 | |
| 20 | using std::map; |
| 21 | using std::string; |
| 22 | using std::vector; |
| 23 | |
| 24 | namespace shill { |
| 25 | |
| 26 | // static |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 27 | const char ProfileDBusAdaptor::kPath[] = "/profile/"; |
| 28 | |
| 29 | ProfileDBusAdaptor::ProfileDBusAdaptor(DBus::Connection* conn, Profile *profile) |
Chris Masone | 7df0c67 | 2011-07-15 10:24:54 -0700 | [diff] [blame] | 30 | : DBusAdaptor(conn, kPath + profile->GetFriendlyName()), |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 31 | profile_(profile) { |
| 32 | } |
| 33 | |
| 34 | ProfileDBusAdaptor::~ProfileDBusAdaptor() { |
| 35 | profile_ = NULL; |
| 36 | } |
| 37 | |
| 38 | void ProfileDBusAdaptor::EmitBoolChanged(const string &name, bool value) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 39 | SLOG(DBus, 2) << __func__ << ": " << name; |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 40 | PropertyChanged(name, DBusAdaptor::BoolToVariant(value)); |
| 41 | } |
| 42 | |
| 43 | void ProfileDBusAdaptor::EmitUintChanged(const string &name, |
| 44 | uint32 value) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 45 | SLOG(DBus, 2) << __func__ << ": " << name; |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 46 | PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value)); |
| 47 | } |
| 48 | |
| 49 | void ProfileDBusAdaptor::EmitIntChanged(const string &name, int value) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 50 | SLOG(DBus, 2) << __func__ << ": " << name; |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 51 | PropertyChanged(name, DBusAdaptor::Int32ToVariant(value)); |
| 52 | } |
| 53 | |
| 54 | void ProfileDBusAdaptor::EmitStringChanged(const string &name, |
| 55 | const string &value) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 56 | SLOG(DBus, 2) << __func__ << ": " << name; |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 57 | PropertyChanged(name, DBusAdaptor::StringToVariant(value)); |
| 58 | } |
| 59 | |
| 60 | map<string, ::DBus::Variant> ProfileDBusAdaptor::GetProperties( |
| 61 | ::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 62 | SLOG(DBus, 2) << __func__; |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 63 | map<string, ::DBus::Variant> properties; |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 64 | DBusAdaptor::GetProperties(profile_->store(), &properties, &error); |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 65 | return properties; |
| 66 | } |
| 67 | |
| 68 | void ProfileDBusAdaptor::SetProperty(const string &name, |
| 69 | const ::DBus::Variant &value, |
| 70 | ::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 71 | SLOG(DBus, 2) << __func__ << ": " << name; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 72 | if (DBusAdaptor::SetProperty(profile_->mutable_store(), |
| 73 | name, |
| 74 | value, |
| 75 | &error)) { |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 76 | PropertyChanged(name, value); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | map<string, ::DBus::Variant> ProfileDBusAdaptor::GetEntry( |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 81 | const std::string &name, |
| 82 | ::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 83 | SLOG(DBus, 2) << __func__ << ": " << name; |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 84 | Error e; |
| 85 | ServiceRefPtr service = profile_->GetServiceFromEntry(name, &e); |
| 86 | map<string, ::DBus::Variant> properties; |
| 87 | if (e.IsSuccess()) { |
| 88 | DBusAdaptor::GetProperties(service->store(), &properties, &error); |
| 89 | return properties; |
| 90 | } |
| 91 | |
| 92 | ProfileDBusPropertyExporter loader(profile_->GetConstStorage(), name); |
| 93 | if (!loader.LoadServiceProperties(&properties, &e)) { |
| 94 | e.ToDBusError(&error); |
| 95 | } |
| 96 | return properties; |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Paul Stewart | 7522551 | 2012-01-26 22:51:33 -0800 | [diff] [blame] | 99 | void ProfileDBusAdaptor::DeleteEntry(const std::string &name, |
| 100 | ::DBus::Error &error) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 101 | SLOG(DBus, 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 |