blob: 2372f76f3abc41c084c64b3a52e144a050af9ce5 [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/profile_dbus_property_exporter.h"
17#include "shill/service.h"
Chris Masone52cd19b2011-06-29 17:23:04 -070018
19using std::map;
20using std::string;
21using std::vector;
22
23namespace shill {
24
25// static
Chris Masone52cd19b2011-06-29 17:23:04 -070026const char ProfileDBusAdaptor::kPath[] = "/profile/";
27
28ProfileDBusAdaptor::ProfileDBusAdaptor(DBus::Connection* conn, Profile *profile)
Chris Masone7df0c672011-07-15 10:24:54 -070029 : DBusAdaptor(conn, kPath + profile->GetFriendlyName()),
Chris Masone52cd19b2011-06-29 17:23:04 -070030 profile_(profile) {
31}
32
33ProfileDBusAdaptor::~ProfileDBusAdaptor() {
34 profile_ = NULL;
35}
36
37void ProfileDBusAdaptor::EmitBoolChanged(const string &name, bool value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070038 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masone52cd19b2011-06-29 17:23:04 -070039 PropertyChanged(name, DBusAdaptor::BoolToVariant(value));
40}
41
42void ProfileDBusAdaptor::EmitUintChanged(const string &name,
Ben Chan7fab8972014-08-10 17:14:46 -070043 uint32_t value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070044 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masone52cd19b2011-06-29 17:23:04 -070045 PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value));
46}
47
48void ProfileDBusAdaptor::EmitIntChanged(const string &name, int value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070049 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masone52cd19b2011-06-29 17:23:04 -070050 PropertyChanged(name, DBusAdaptor::Int32ToVariant(value));
51}
52
53void ProfileDBusAdaptor::EmitStringChanged(const string &name,
54 const string &value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070055 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masone52cd19b2011-06-29 17:23:04 -070056 PropertyChanged(name, DBusAdaptor::StringToVariant(value));
57}
58
59map<string, ::DBus::Variant> ProfileDBusAdaptor::GetProperties(
60 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070061 SLOG(DBus, 2) << __func__;
Chris Masone52cd19b2011-06-29 17:23:04 -070062 map<string, ::DBus::Variant> properties;
Chris Masone27c4aa52011-07-02 13:10:14 -070063 DBusAdaptor::GetProperties(profile_->store(), &properties, &error);
Chris Masone52cd19b2011-06-29 17:23:04 -070064 return properties;
65}
66
67void ProfileDBusAdaptor::SetProperty(const string &name,
68 const ::DBus::Variant &value,
69 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070070 SLOG(DBus, 2) << __func__ << ": " << name;
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -080071 if (DBusAdaptor::SetProperty(profile_->mutable_store(),
72 name,
73 value,
74 &error)) {
Chris Masone52cd19b2011-06-29 17:23:04 -070075 PropertyChanged(name, value);
76 }
77}
78
79map<string, ::DBus::Variant> ProfileDBusAdaptor::GetEntry(
Paul Stewart0756db92012-01-27 08:34:47 -080080 const std::string &name,
81 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070082 SLOG(DBus, 2) << __func__ << ": " << name;
Paul Stewart0756db92012-01-27 08:34:47 -080083 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 Masone52cd19b2011-06-29 17:23:04 -070096}
97
Paul Stewart75225512012-01-26 22:51:33 -080098void ProfileDBusAdaptor::DeleteEntry(const std::string &name,
99 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700100 SLOG(DBus, 2) << __func__ << ": " << name;
Paul Stewart75225512012-01-26 22:51:33 -0800101 Error e;
102 profile_->DeleteEntry(name, &e);
103 e.ToDBusError(&error);
Chris Masone52cd19b2011-06-29 17:23:04 -0700104}
105
106} // namespace shill