blob: 172dd2ecaf01c6c702922c44c9346783a2017076 [file] [log] [blame]
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -08001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Chris Masone52cd19b2011-06-29 17:23:04 -07002// 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 Masone52cd19b2011-06-29 17:23:04 -070011#include <dbus-c++/dbus.h>
12
13#include "shill/error.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -070014#include "shill/logging.h"
Chris Masone52cd19b2011-06-29 17:23:04 -070015#include "shill/profile.h"
Paul Stewart0756db92012-01-27 08:34:47 -080016#include "shill/service.h"
Chris Masone52cd19b2011-06-29 17:23:04 -070017
18using std::map;
19using std::string;
20using std::vector;
21
22namespace shill {
23
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070024namespace Logging {
25static auto kModuleLogScope = ScopeLogger::kDBus;
Paul Stewart1a212a62015-06-16 13:13:10 -070026static string ObjectID(ProfileDBusAdaptor* p) { return p->GetRpcIdentifier(); }
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070027}
28
29
Chris Masone52cd19b2011-06-29 17:23:04 -070030// static
Chris Masone52cd19b2011-06-29 17:23:04 -070031const char ProfileDBusAdaptor::kPath[] = "/profile/";
32
Paul Stewart1a212a62015-06-16 13:13:10 -070033ProfileDBusAdaptor::ProfileDBusAdaptor(DBus::Connection* conn, Profile* profile)
Chris Masone7df0c672011-07-15 10:24:54 -070034 : DBusAdaptor(conn, kPath + profile->GetFriendlyName()),
Chris Masone52cd19b2011-06-29 17:23:04 -070035 profile_(profile) {
36}
37
38ProfileDBusAdaptor::~ProfileDBusAdaptor() {
Ben Chancc225ef2014-09-30 13:26:51 -070039 profile_ = nullptr;
Chris Masone52cd19b2011-06-29 17:23:04 -070040}
41
Paul Stewart1a212a62015-06-16 13:13:10 -070042void ProfileDBusAdaptor::EmitBoolChanged(const string& name, bool value) {
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070043 SLOG(this, 2) << __func__ << ": " << name;
Chris Masone52cd19b2011-06-29 17:23:04 -070044 PropertyChanged(name, DBusAdaptor::BoolToVariant(value));
45}
46
Paul Stewart1a212a62015-06-16 13:13:10 -070047void ProfileDBusAdaptor::EmitUintChanged(const string& name,
Ben Chan7fab8972014-08-10 17:14:46 -070048 uint32_t value) {
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070049 SLOG(this, 2) << __func__ << ": " << name;
Chris Masone52cd19b2011-06-29 17:23:04 -070050 PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value));
51}
52
Paul Stewart1a212a62015-06-16 13:13:10 -070053void ProfileDBusAdaptor::EmitIntChanged(const string& name, int value) {
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070054 SLOG(this, 2) << __func__ << ": " << name;
Chris Masone52cd19b2011-06-29 17:23:04 -070055 PropertyChanged(name, DBusAdaptor::Int32ToVariant(value));
56}
57
Paul Stewart1a212a62015-06-16 13:13:10 -070058void ProfileDBusAdaptor::EmitStringChanged(const string& name,
59 const string& value) {
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070060 SLOG(this, 2) << __func__ << ": " << name;
Chris Masone52cd19b2011-06-29 17:23:04 -070061 PropertyChanged(name, DBusAdaptor::StringToVariant(value));
62}
63
Ben Chan3f4d4ee2014-09-09 07:41:33 -070064map<string, DBus::Variant> ProfileDBusAdaptor::GetProperties(
Paul Stewart1a212a62015-06-16 13:13:10 -070065 DBus::Error& error) { // NOLINT
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070066 SLOG(this, 2) << __func__;
Ben Chan3f4d4ee2014-09-09 07:41:33 -070067 map<string, DBus::Variant> properties;
Chris Masone27c4aa52011-07-02 13:10:14 -070068 DBusAdaptor::GetProperties(profile_->store(), &properties, &error);
Chris Masone52cd19b2011-06-29 17:23:04 -070069 return properties;
70}
71
Paul Stewart1a212a62015-06-16 13:13:10 -070072void ProfileDBusAdaptor::SetProperty(const string& name,
73 const DBus::Variant& value,
74 DBus::Error& error) { // NOLINT
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070075 SLOG(this, 2) << __func__ << ": " << name;
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -080076 if (DBusAdaptor::SetProperty(profile_->mutable_store(),
77 name,
78 value,
79 &error)) {
Chris Masone52cd19b2011-06-29 17:23:04 -070080 PropertyChanged(name, value);
81 }
82}
83
Ben Chan3f4d4ee2014-09-09 07:41:33 -070084map<string, DBus::Variant> ProfileDBusAdaptor::GetEntry(
Paul Stewart1a212a62015-06-16 13:13:10 -070085 const std::string& name,
86 DBus::Error& error) { // NOLINT
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070087 SLOG(this, 2) << __func__ << ": " << name;
Paul Stewart0756db92012-01-27 08:34:47 -080088 Error e;
89 ServiceRefPtr service = profile_->GetServiceFromEntry(name, &e);
Ben Chan3f4d4ee2014-09-09 07:41:33 -070090 map<string, DBus::Variant> properties;
Paul Stewart0756db92012-01-27 08:34:47 -080091 if (e.IsSuccess()) {
92 DBusAdaptor::GetProperties(service->store(), &properties, &error);
Peter Qiu18213652015-04-21 16:01:51 -070093 } else {
Paul Stewart0756db92012-01-27 08:34:47 -080094 e.ToDBusError(&error);
95 }
96 return properties;
Chris Masone52cd19b2011-06-29 17:23:04 -070097}
98
Paul Stewart1a212a62015-06-16 13:13:10 -070099void ProfileDBusAdaptor::DeleteEntry(const std::string& name,
100 DBus::Error& error) { // NOLINT
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -0700101 SLOG(this, 2) << __func__ << ": " << name;
Paul Stewart75225512012-01-26 22:51:33 -0800102 Error e;
103 profile_->DeleteEntry(name, &e);
104 e.ToDBusError(&error);
Chris Masone52cd19b2011-06-29 17:23:04 -0700105}
106
107} // namespace shill