blob: fbb22dbd5d89fc5d3676501bd8ae3a7e466da512 [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
Chris Masone0756f232011-07-21 17:24:00 -070011#include <base/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
25// static
Chris Masone0756f232011-07-21 17:24:00 -070026const char IPConfigDBusAdaptor::kPath[] = "/ipconfig/";
Chris Masonec6c6c132011-06-30 11:29:52 -070027
28IPConfigDBusAdaptor::IPConfigDBusAdaptor(DBus::Connection* conn,
29 IPConfig *config)
Chris Masone0756f232011-07-21 17:24:00 -070030 : DBusAdaptor(conn, StringPrintf("%s%s_%u_%s",
31 kPath,
32 config->device_name().c_str(),
33 config->serial(),
34 config->type().c_str())),
Chris Masonec6c6c132011-06-30 11:29:52 -070035 ipconfig_(config) {
36}
37
38IPConfigDBusAdaptor::~IPConfigDBusAdaptor() {
39 ipconfig_ = NULL;
40}
41
42void IPConfigDBusAdaptor::EmitBoolChanged(const string &name, bool value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070043 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masonec6c6c132011-06-30 11:29:52 -070044 PropertyChanged(name, DBusAdaptor::BoolToVariant(value));
45}
46
47void IPConfigDBusAdaptor::EmitUintChanged(const string &name,
48 uint32 value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070049 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masonec6c6c132011-06-30 11:29:52 -070050 PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value));
51}
52
53void IPConfigDBusAdaptor::EmitIntChanged(const string &name, int value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070054 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masonec6c6c132011-06-30 11:29:52 -070055 PropertyChanged(name, DBusAdaptor::Int32ToVariant(value));
56}
57
58void IPConfigDBusAdaptor::EmitStringChanged(const string &name,
59 const string &value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070060 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masonec6c6c132011-06-30 11:29:52 -070061 PropertyChanged(name, DBusAdaptor::StringToVariant(value));
62}
63
64map<string, ::DBus::Variant> IPConfigDBusAdaptor::GetProperties(
65 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070066 SLOG(DBus, 2) << __func__;
Chris Masonec6c6c132011-06-30 11:29:52 -070067 map<string, ::DBus::Variant> properties;
Chris Masone27c4aa52011-07-02 13:10:14 -070068 DBusAdaptor::GetProperties(ipconfig_->store(), &properties, &error);
Chris Masonec6c6c132011-06-30 11:29:52 -070069 return properties;
70}
71
72void IPConfigDBusAdaptor::SetProperty(const string &name,
73 const ::DBus::Variant &value,
74 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070075 SLOG(DBus, 2) << __func__ << ": " << name;
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -080076 if (DBusAdaptor::SetProperty(ipconfig_->mutable_store(),
77 name,
78 value,
79 &error)) {
Chris Masonec6c6c132011-06-30 11:29:52 -070080 PropertyChanged(name, value);
81 }
82}
83
mukesh agrawal4d0401c2012-01-06 16:05:31 -080084void IPConfigDBusAdaptor::ClearProperty(const std::string &name,
mukesh agrawal8abd2f62012-01-30 14:56:14 -080085 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070086 SLOG(DBus, 2) << __func__ << ": " << name;
mukesh agrawal8abd2f62012-01-30 14:56:14 -080087 DBusAdaptor::ClearProperty(ipconfig_->mutable_store(), name, &error);
Chris Masonec6c6c132011-06-30 11:29:52 -070088}
89
mukesh agrawal1830fa12011-09-26 14:31:40 -070090void IPConfigDBusAdaptor::Remove(::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -070091 SLOG(DBus, 2) << __func__;
Chris Masonec6c6c132011-06-30 11:29:52 -070092}
93
Paul Stewart4558bda2012-08-03 10:44:10 -070094void IPConfigDBusAdaptor::Refresh(::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070095 SLOG(DBus, 2) << __func__;
Paul Stewart4558bda2012-08-03 10:44:10 -070096 Error e;
97 ipconfig_->Refresh(&e);
98 e.ToDBusError(&error);
Chris Masonec6c6c132011-06-30 11:29:52 -070099}
100
101} // namespace shill