blob: a9ecab7ba9b7596aedb5f1efe652e5da56f4830f [file] [log] [blame]
mukesh agrawal4d0401c2012-01-06 16:05:31 -08001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Chris Masonec6c6c132011-06-30 11:29:52 -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/ipconfig_dbus_adaptor.h"
6
7#include <map>
8#include <string>
9#include <vector>
10
Ben Chana0ddf462014-02-06 11:32:42 -080011#include <base/strings/stringprintf.h>
Chris Masonec6c6c132011-06-30 11:29:52 -070012#include <dbus-c++/dbus.h>
13
14#include "shill/error.h"
15#include "shill/ipconfig.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -070016#include "shill/logging.h"
Chris Masonec6c6c132011-06-30 11:29:52 -070017
Chris Masone0756f232011-07-21 17:24:00 -070018using base::StringPrintf;
Chris Masonec6c6c132011-06-30 11:29:52 -070019using std::map;
20using std::string;
21using std::vector;
22
23namespace shill {
24
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070025namespace Logging {
26static auto kModuleLogScope = ScopeLogger::kDBus;
Paul Stewart8ae18742015-06-16 13:13:10 -070027static string ObjectID(IPConfigDBusAdaptor* i) { return i->GetRpcIdentifier(); }
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070028}
29
Chris Masonec6c6c132011-06-30 11:29:52 -070030// static
Chris Masone0756f232011-07-21 17:24:00 -070031const char IPConfigDBusAdaptor::kPath[] = "/ipconfig/";
Chris Masonec6c6c132011-06-30 11:29:52 -070032
Paul Stewart8ae18742015-06-16 13:13:10 -070033IPConfigDBusAdaptor::IPConfigDBusAdaptor(DBus::Connection* conn,
34 IPConfig* config)
Chris Masone0756f232011-07-21 17:24:00 -070035 : DBusAdaptor(conn, StringPrintf("%s%s_%u_%s",
36 kPath,
Paul Stewartf3b38402015-01-16 12:59:03 -080037 SanitizePathElement(
38 config->device_name()).c_str(),
Chris Masone0756f232011-07-21 17:24:00 -070039 config->serial(),
40 config->type().c_str())),
Chris Masonec6c6c132011-06-30 11:29:52 -070041 ipconfig_(config) {
42}
43
44IPConfigDBusAdaptor::~IPConfigDBusAdaptor() {
Ben Chancc225ef2014-09-30 13:26:51 -070045 ipconfig_ = nullptr;
Chris Masonec6c6c132011-06-30 11:29:52 -070046}
47
Paul Stewart8ae18742015-06-16 13:13:10 -070048void IPConfigDBusAdaptor::EmitBoolChanged(const string& name, bool value) {
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070049 SLOG(this, 2) << __func__ << ": " << name;
Chris Masonec6c6c132011-06-30 11:29:52 -070050 PropertyChanged(name, DBusAdaptor::BoolToVariant(value));
51}
52
Paul Stewart8ae18742015-06-16 13:13:10 -070053void IPConfigDBusAdaptor::EmitUintChanged(const string& name,
Ben Chan7fab8972014-08-10 17:14:46 -070054 uint32_t value) {
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070055 SLOG(this, 2) << __func__ << ": " << name;
Chris Masonec6c6c132011-06-30 11:29:52 -070056 PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value));
57}
58
Paul Stewart8ae18742015-06-16 13:13:10 -070059void IPConfigDBusAdaptor::EmitIntChanged(const string& name, int value) {
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070060 SLOG(this, 2) << __func__ << ": " << name;
Chris Masonec6c6c132011-06-30 11:29:52 -070061 PropertyChanged(name, DBusAdaptor::Int32ToVariant(value));
62}
63
Paul Stewart8ae18742015-06-16 13:13:10 -070064void IPConfigDBusAdaptor::EmitStringChanged(const string& name,
65 const string& value) {
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070066 SLOG(this, 2) << __func__ << ": " << name;
Chris Masonec6c6c132011-06-30 11:29:52 -070067 PropertyChanged(name, DBusAdaptor::StringToVariant(value));
68}
69
Paul Stewart8ae18742015-06-16 13:13:10 -070070void IPConfigDBusAdaptor::EmitStringsChanged(const string& name,
71 const vector<string>& value) {
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070072 SLOG(this, 2) << __func__ << ": " << name;
mukesh agrawal7aed61c2013-04-22 16:01:24 -070073 PropertyChanged(name, DBusAdaptor::StringsToVariant(value));
74}
75
Ben Chan3f4d4ee2014-09-09 07:41:33 -070076map<string, DBus::Variant> IPConfigDBusAdaptor::GetProperties(
Paul Stewart8ae18742015-06-16 13:13:10 -070077 DBus::Error& error) { // NOLINT
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070078 SLOG(this, 2) << __func__;
Ben Chan3f4d4ee2014-09-09 07:41:33 -070079 map<string, DBus::Variant> properties;
Chris Masone27c4aa52011-07-02 13:10:14 -070080 DBusAdaptor::GetProperties(ipconfig_->store(), &properties, &error);
Chris Masonec6c6c132011-06-30 11:29:52 -070081 return properties;
82}
83
Paul Stewart8ae18742015-06-16 13:13:10 -070084void IPConfigDBusAdaptor::SetProperty(const string& name,
85 const DBus::Variant& value,
86 DBus::Error& error) { // NOLINT
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070087 SLOG(this, 2) << __func__ << ": " << name;
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -080088 if (DBusAdaptor::SetProperty(ipconfig_->mutable_store(),
89 name,
90 value,
91 &error)) {
Chris Masonec6c6c132011-06-30 11:29:52 -070092 PropertyChanged(name, value);
93 }
94}
95
Paul Stewart8ae18742015-06-16 13:13:10 -070096void IPConfigDBusAdaptor::ClearProperty(const string& name,
97 DBus::Error& error) { // NOLINT
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070098 SLOG(this, 2) << __func__ << ": " << name;
mukesh agrawal8abd2f62012-01-30 14:56:14 -080099 DBusAdaptor::ClearProperty(ipconfig_->mutable_store(), name, &error);
Chris Masonec6c6c132011-06-30 11:29:52 -0700100}
101
Paul Stewart8ae18742015-06-16 13:13:10 -0700102void IPConfigDBusAdaptor::Remove(DBus::Error& /*error*/) { // NOLINT
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -0700103 SLOG(this, 2) << __func__;
Chris Masonec6c6c132011-06-30 11:29:52 -0700104}
105
Paul Stewart8ae18742015-06-16 13:13:10 -0700106void IPConfigDBusAdaptor::Refresh(DBus::Error& error) { // NOLINT
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -0700107 SLOG(this, 2) << __func__;
Paul Stewart4558bda2012-08-03 10:44:10 -0700108 Error e;
109 ipconfig_->Refresh(&e);
110 e.ToDBusError(&error);
Chris Masonec6c6c132011-06-30 11:29:52 -0700111}
112
113} // namespace shill