blob: 7e1026f5cad1fc2518011ade247745ea9c632cc5 [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"
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) {
38 PropertyChanged(name, DBusAdaptor::BoolToVariant(value));
39}
40
41void ProfileDBusAdaptor::EmitUintChanged(const string &name,
42 uint32 value) {
43 PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value));
44}
45
46void ProfileDBusAdaptor::EmitIntChanged(const string &name, int value) {
47 PropertyChanged(name, DBusAdaptor::Int32ToVariant(value));
48}
49
50void ProfileDBusAdaptor::EmitStringChanged(const string &name,
51 const string &value) {
52 PropertyChanged(name, DBusAdaptor::StringToVariant(value));
53}
54
55map<string, ::DBus::Variant> ProfileDBusAdaptor::GetProperties(
56 ::DBus::Error &error) {
57 map<string, ::DBus::Variant> properties;
Chris Masone27c4aa52011-07-02 13:10:14 -070058 DBusAdaptor::GetProperties(profile_->store(), &properties, &error);
Chris Masone52cd19b2011-06-29 17:23:04 -070059 return properties;
60}
61
62void ProfileDBusAdaptor::SetProperty(const string &name,
63 const ::DBus::Variant &value,
64 ::DBus::Error &error) {
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -080065 if (DBusAdaptor::SetProperty(profile_->mutable_store(),
66 name,
67 value,
68 &error)) {
Chris Masone52cd19b2011-06-29 17:23:04 -070069 PropertyChanged(name, value);
70 }
71}
72
73map<string, ::DBus::Variant> ProfileDBusAdaptor::GetEntry(
Paul Stewart0756db92012-01-27 08:34:47 -080074 const std::string &name,
75 ::DBus::Error &error) {
76 Error e;
77 ServiceRefPtr service = profile_->GetServiceFromEntry(name, &e);
78 map<string, ::DBus::Variant> properties;
79 if (e.IsSuccess()) {
80 DBusAdaptor::GetProperties(service->store(), &properties, &error);
81 return properties;
82 }
83
84 ProfileDBusPropertyExporter loader(profile_->GetConstStorage(), name);
85 if (!loader.LoadServiceProperties(&properties, &e)) {
86 e.ToDBusError(&error);
87 }
88 return properties;
Chris Masone52cd19b2011-06-29 17:23:04 -070089}
90
Paul Stewart75225512012-01-26 22:51:33 -080091void ProfileDBusAdaptor::DeleteEntry(const std::string &name,
92 ::DBus::Error &error) {
93 Error e;
94 profile_->DeleteEntry(name, &e);
95 e.ToDBusError(&error);
Chris Masone52cd19b2011-06-29 17:23:04 -070096}
97
98} // namespace shill