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