blob: 6ebf8bdc148fa3a9035ada1c5d17575e62c3528c [file] [log] [blame]
Chris Masone52cd19b2011-06-29 17:23:04 -07001// 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 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
26const char ProfileDBusAdaptor::kInterfaceName[] = SHILL_INTERFACE;
27// static
28const char ProfileDBusAdaptor::kPath[] = "/profile/";
29
30ProfileDBusAdaptor::ProfileDBusAdaptor(DBus::Connection* conn, Profile *profile)
Chris Masone7df0c672011-07-15 10:24:54 -070031 : DBusAdaptor(conn, kPath + profile->GetFriendlyName()),
Chris Masone52cd19b2011-06-29 17:23:04 -070032 profile_(profile) {
33}
34
35ProfileDBusAdaptor::~ProfileDBusAdaptor() {
36 profile_ = NULL;
37}
38
39void ProfileDBusAdaptor::EmitBoolChanged(const string &name, bool value) {
40 PropertyChanged(name, DBusAdaptor::BoolToVariant(value));
41}
42
43void ProfileDBusAdaptor::EmitUintChanged(const string &name,
44 uint32 value) {
45 PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value));
46}
47
48void ProfileDBusAdaptor::EmitIntChanged(const string &name, int value) {
49 PropertyChanged(name, DBusAdaptor::Int32ToVariant(value));
50}
51
52void ProfileDBusAdaptor::EmitStringChanged(const string &name,
53 const string &value) {
54 PropertyChanged(name, DBusAdaptor::StringToVariant(value));
55}
56
57map<string, ::DBus::Variant> ProfileDBusAdaptor::GetProperties(
58 ::DBus::Error &error) {
59 map<string, ::DBus::Variant> properties;
Chris Masone27c4aa52011-07-02 13:10:14 -070060 DBusAdaptor::GetProperties(profile_->store(), &properties, &error);
Chris Masone52cd19b2011-06-29 17:23:04 -070061 return properties;
62}
63
64void ProfileDBusAdaptor::SetProperty(const string &name,
65 const ::DBus::Variant &value,
66 ::DBus::Error &error) {
mukesh agrawalde29fa82011-09-16 16:16:36 -070067 if (DBusAdaptor::DispatchOnType(profile_->mutable_store(),
68 name,
69 value,
70 &error)) {
Chris Masone52cd19b2011-06-29 17:23:04 -070071 PropertyChanged(name, value);
72 }
73}
74
75map<string, ::DBus::Variant> ProfileDBusAdaptor::GetEntry(
Paul Stewart0756db92012-01-27 08:34:47 -080076 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 Masone52cd19b2011-06-29 17:23:04 -070091}
92
Paul Stewart75225512012-01-26 22:51:33 -080093void ProfileDBusAdaptor::DeleteEntry(const std::string &name,
94 ::DBus::Error &error) {
95 Error e;
96 profile_->DeleteEntry(name, &e);
97 e.ToDBusError(&error);
Chris Masone52cd19b2011-06-29 17:23:04 -070098}
99
100} // namespace shill