blob: 46c4e6d1e302ccbc7addcff8064269c0ed1f6d5b [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
11#include <base/logging.h>
12#include <dbus-c++/dbus.h>
13
14#include "shill/error.h"
15#include "shill/profile.h"
Paul Stewart0756db92012-01-27 08:34:47 -080016#include "shill/profile_dbus_property_exporter.h"
mukesh agrawal06175d72012-04-23 16:46:01 -070017#include "shill/scope_logger.h"
Paul Stewart0756db92012-01-27 08:34:47 -080018#include "shill/service.h"
Chris Masone52cd19b2011-06-29 17:23:04 -070019
20using std::map;
21using std::string;
22using std::vector;
23
24namespace shill {
25
26// static
Chris Masone52cd19b2011-06-29 17:23:04 -070027const char ProfileDBusAdaptor::kPath[] = "/profile/";
28
29ProfileDBusAdaptor::ProfileDBusAdaptor(DBus::Connection* conn, Profile *profile)
Chris Masone7df0c672011-07-15 10:24:54 -070030 : DBusAdaptor(conn, kPath + profile->GetFriendlyName()),
Chris Masone52cd19b2011-06-29 17:23:04 -070031 profile_(profile) {
32}
33
34ProfileDBusAdaptor::~ProfileDBusAdaptor() {
35 profile_ = NULL;
36}
37
38void ProfileDBusAdaptor::EmitBoolChanged(const string &name, bool value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070039 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masone52cd19b2011-06-29 17:23:04 -070040 PropertyChanged(name, DBusAdaptor::BoolToVariant(value));
41}
42
43void ProfileDBusAdaptor::EmitUintChanged(const string &name,
44 uint32 value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070045 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masone52cd19b2011-06-29 17:23:04 -070046 PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value));
47}
48
49void ProfileDBusAdaptor::EmitIntChanged(const string &name, int value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070050 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masone52cd19b2011-06-29 17:23:04 -070051 PropertyChanged(name, DBusAdaptor::Int32ToVariant(value));
52}
53
54void ProfileDBusAdaptor::EmitStringChanged(const string &name,
55 const string &value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070056 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masone52cd19b2011-06-29 17:23:04 -070057 PropertyChanged(name, DBusAdaptor::StringToVariant(value));
58}
59
60map<string, ::DBus::Variant> ProfileDBusAdaptor::GetProperties(
61 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070062 SLOG(DBus, 2) << __func__;
Chris Masone52cd19b2011-06-29 17:23:04 -070063 map<string, ::DBus::Variant> properties;
Chris Masone27c4aa52011-07-02 13:10:14 -070064 DBusAdaptor::GetProperties(profile_->store(), &properties, &error);
Chris Masone52cd19b2011-06-29 17:23:04 -070065 return properties;
66}
67
68void ProfileDBusAdaptor::SetProperty(const string &name,
69 const ::DBus::Variant &value,
70 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070071 SLOG(DBus, 2) << __func__ << ": " << name;
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -080072 if (DBusAdaptor::SetProperty(profile_->mutable_store(),
73 name,
74 value,
75 &error)) {
Chris Masone52cd19b2011-06-29 17:23:04 -070076 PropertyChanged(name, value);
77 }
78}
79
80map<string, ::DBus::Variant> ProfileDBusAdaptor::GetEntry(
Paul Stewart0756db92012-01-27 08:34:47 -080081 const std::string &name,
82 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070083 SLOG(DBus, 2) << __func__ << ": " << name;
Paul Stewart0756db92012-01-27 08:34:47 -080084 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 Masone52cd19b2011-06-29 17:23:04 -070097}
98
Paul Stewart75225512012-01-26 22:51:33 -080099void ProfileDBusAdaptor::DeleteEntry(const std::string &name,
100 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700101 SLOG(DBus, 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