blob: c248065592553b43c1983365947699773a755044 [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
mukesh agrawal7aed61c2013-04-22 16:01:24 -070064void IPConfigDBusAdaptor::EmitStringsChanged(const string &name,
65 const vector<string> &value) {
66 SLOG(DBus, 2) << __func__ << ": " << name;
67 PropertyChanged(name, DBusAdaptor::StringsToVariant(value));
68}
69
Chris Masonec6c6c132011-06-30 11:29:52 -070070map<string, ::DBus::Variant> IPConfigDBusAdaptor::GetProperties(
71 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070072 SLOG(DBus, 2) << __func__;
Chris Masonec6c6c132011-06-30 11:29:52 -070073 map<string, ::DBus::Variant> properties;
Chris Masone27c4aa52011-07-02 13:10:14 -070074 DBusAdaptor::GetProperties(ipconfig_->store(), &properties, &error);
Chris Masonec6c6c132011-06-30 11:29:52 -070075 return properties;
76}
77
78void IPConfigDBusAdaptor::SetProperty(const string &name,
79 const ::DBus::Variant &value,
80 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070081 SLOG(DBus, 2) << __func__ << ": " << name;
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -080082 if (DBusAdaptor::SetProperty(ipconfig_->mutable_store(),
83 name,
84 value,
85 &error)) {
Chris Masonec6c6c132011-06-30 11:29:52 -070086 PropertyChanged(name, value);
87 }
88}
89
mukesh agrawal4d0401c2012-01-06 16:05:31 -080090void IPConfigDBusAdaptor::ClearProperty(const std::string &name,
mukesh agrawal8abd2f62012-01-30 14:56:14 -080091 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070092 SLOG(DBus, 2) << __func__ << ": " << name;
mukesh agrawal8abd2f62012-01-30 14:56:14 -080093 DBusAdaptor::ClearProperty(ipconfig_->mutable_store(), name, &error);
Chris Masonec6c6c132011-06-30 11:29:52 -070094}
95
mukesh agrawal1830fa12011-09-26 14:31:40 -070096void IPConfigDBusAdaptor::Remove(::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -070097 SLOG(DBus, 2) << __func__;
Chris Masonec6c6c132011-06-30 11:29:52 -070098}
99
Paul Stewart4558bda2012-08-03 10:44:10 -0700100void IPConfigDBusAdaptor::Refresh(::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700101 SLOG(DBus, 2) << __func__;
Paul Stewart4558bda2012-08-03 10:44:10 -0700102 Error e;
103 ipconfig_->Refresh(&e);
104 e.ToDBusError(&error);
Chris Masonec6c6c132011-06-30 11:29:52 -0700105}
106
107} // namespace shill