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