blob: a12b5c5110f8c030fb5b002b77cdeb6cfb88b2ac [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
11#include <base/logging.h>
Chris Masone0756f232011-07-21 17:24:00 -070012#include <base/stringprintf.h>
Chris Masonec6c6c132011-06-30 11:29:52 -070013#include <dbus-c++/dbus.h>
14
15#include "shill/error.h"
16#include "shill/ipconfig.h"
mukesh agrawal06175d72012-04-23 16:46:01 -070017#include "shill/scope_logger.h"
Chris Masonec6c6c132011-06-30 11:29:52 -070018
Chris Masone0756f232011-07-21 17:24:00 -070019using base::StringPrintf;
Chris Masonec6c6c132011-06-30 11:29:52 -070020using std::map;
21using std::string;
22using std::vector;
23
24namespace shill {
25
26// static
Chris Masone0756f232011-07-21 17:24:00 -070027const char IPConfigDBusAdaptor::kPath[] = "/ipconfig/";
Chris Masonec6c6c132011-06-30 11:29:52 -070028
29IPConfigDBusAdaptor::IPConfigDBusAdaptor(DBus::Connection* conn,
30 IPConfig *config)
Chris Masone0756f232011-07-21 17:24:00 -070031 : DBusAdaptor(conn, StringPrintf("%s%s_%u_%s",
32 kPath,
33 config->device_name().c_str(),
34 config->serial(),
35 config->type().c_str())),
Chris Masonec6c6c132011-06-30 11:29:52 -070036 ipconfig_(config) {
37}
38
39IPConfigDBusAdaptor::~IPConfigDBusAdaptor() {
40 ipconfig_ = NULL;
41}
42
43void IPConfigDBusAdaptor::EmitBoolChanged(const string &name, bool value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070044 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masonec6c6c132011-06-30 11:29:52 -070045 PropertyChanged(name, DBusAdaptor::BoolToVariant(value));
46}
47
48void IPConfigDBusAdaptor::EmitUintChanged(const string &name,
49 uint32 value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070050 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masonec6c6c132011-06-30 11:29:52 -070051 PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value));
52}
53
54void IPConfigDBusAdaptor::EmitIntChanged(const string &name, int value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070055 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masonec6c6c132011-06-30 11:29:52 -070056 PropertyChanged(name, DBusAdaptor::Int32ToVariant(value));
57}
58
59void IPConfigDBusAdaptor::EmitStringChanged(const string &name,
60 const string &value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070061 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masonec6c6c132011-06-30 11:29:52 -070062 PropertyChanged(name, DBusAdaptor::StringToVariant(value));
63}
64
65map<string, ::DBus::Variant> IPConfigDBusAdaptor::GetProperties(
66 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070067 SLOG(DBus, 2) << __func__;
Chris Masonec6c6c132011-06-30 11:29:52 -070068 map<string, ::DBus::Variant> properties;
Chris Masone27c4aa52011-07-02 13:10:14 -070069 DBusAdaptor::GetProperties(ipconfig_->store(), &properties, &error);
Chris Masonec6c6c132011-06-30 11:29:52 -070070 return properties;
71}
72
73void IPConfigDBusAdaptor::SetProperty(const string &name,
74 const ::DBus::Variant &value,
75 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070076 SLOG(DBus, 2) << __func__ << ": " << name;
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -080077 if (DBusAdaptor::SetProperty(ipconfig_->mutable_store(),
78 name,
79 value,
80 &error)) {
Chris Masonec6c6c132011-06-30 11:29:52 -070081 PropertyChanged(name, value);
82 }
83}
84
mukesh agrawal4d0401c2012-01-06 16:05:31 -080085void IPConfigDBusAdaptor::ClearProperty(const std::string &name,
mukesh agrawal8abd2f62012-01-30 14:56:14 -080086 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070087 SLOG(DBus, 2) << __func__ << ": " << name;
mukesh agrawal8abd2f62012-01-30 14:56:14 -080088 DBusAdaptor::ClearProperty(ipconfig_->mutable_store(), name, &error);
Chris Masonec6c6c132011-06-30 11:29:52 -070089}
90
mukesh agrawal1830fa12011-09-26 14:31:40 -070091void IPConfigDBusAdaptor::Remove(::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -070092 SLOG(DBus, 2) << __func__;
Chris Masonec6c6c132011-06-30 11:29:52 -070093}
94
mukesh agrawal1830fa12011-09-26 14:31:40 -070095void IPConfigDBusAdaptor::MoveBefore(const ::DBus::Path& /*path*/,
96 ::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -070097 SLOG(DBus, 2) << __func__;
Chris Masonec6c6c132011-06-30 11:29:52 -070098}
99
mukesh agrawal1830fa12011-09-26 14:31:40 -0700100void IPConfigDBusAdaptor::MoveAfter(const ::DBus::Path& /*path*/,
101 ::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700102 SLOG(DBus, 2) << __func__;
Chris Masonec6c6c132011-06-30 11:29:52 -0700103}
104
105} // namespace shill