blob: 5c91316e6883f642725bcca43d55cd5624dede34 [file] [log] [blame]
Ben Chanfad4a0b2012-04-18 15:49:59 -07001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Darin Petkove0a312e2011-07-20 13:45:28 -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/dbus_properties.h"
6
Ben Chanfad4a0b2012-04-18 15:49:59 -07007#include "shill/scope_logger.h"
Darin Petkovceb68172011-07-29 14:47:48 -07008
Darin Petkove0a312e2011-07-20 13:45:28 -07009namespace shill {
10
11// static
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040012bool DBusProperties::GetBool(const DBusPropertiesMap &properties,
13 const std::string &key,
14 bool *value) {
Darin Petkove0a312e2011-07-20 13:45:28 -070015 DBusPropertiesMap::const_iterator it = properties.find(key);
16 if (it == properties.end()) {
17 return false;
18 }
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040019 *value = it->second.reader().get_bool();
20 SLOG(DBus, 2) << key << " = " << *value;
21 return true;
22}
23
24// static
25bool DBusProperties::GetInt32(const DBusPropertiesMap &properties,
26 const std::string &key,
27 int32 *value) {
28 DBusPropertiesMap::const_iterator it = properties.find(key);
29 if (it == properties.end()) {
30 return false;
31 }
32 *value = it->second.reader().get_int32();
Ben Chanfad4a0b2012-04-18 15:49:59 -070033 SLOG(DBus, 2) << key << " = " << *value;
Darin Petkove0a312e2011-07-20 13:45:28 -070034 return true;
35}
36
37// static
Nathan Williamse9840802012-04-18 18:47:40 -040038bool DBusProperties::GetObjectPath(const DBusPropertiesMap &properties,
39 const std::string &key,
40 std::string *value) {
41 DBusPropertiesMap::const_iterator it = properties.find(key);
42 if (it == properties.end()) {
43 return false;
44 }
45 *value = it->second.reader().get_path();
Ben Chanfad4a0b2012-04-18 15:49:59 -070046 SLOG(DBus, 2) << key << " = " << *value;
Nathan Williamse9840802012-04-18 18:47:40 -040047 return true;
48}
49
50// static
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040051bool DBusProperties::GetString(const DBusPropertiesMap &properties,
Darin Petkove0a312e2011-07-20 13:45:28 -070052 const std::string &key,
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040053 std::string *value) {
Darin Petkove0a312e2011-07-20 13:45:28 -070054 DBusPropertiesMap::const_iterator it = properties.find(key);
55 if (it == properties.end()) {
56 return false;
57 }
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040058 *value = it->second.reader().get_string();
Ben Chanfad4a0b2012-04-18 15:49:59 -070059 SLOG(DBus, 2) << key << " = " << *value;
Darin Petkovceb68172011-07-29 14:47:48 -070060 return true;
61}
62
63// static
64bool DBusProperties::GetUint16(const DBusPropertiesMap &properties,
65 const std::string &key,
66 uint16 *value) {
67 DBusPropertiesMap::const_iterator it = properties.find(key);
68 if (it == properties.end()) {
69 return false;
70 }
71 *value = it->second.reader().get_uint16();
Ben Chanfad4a0b2012-04-18 15:49:59 -070072 SLOG(DBus, 2) << key << " = " << *value;
Darin Petkove0a312e2011-07-20 13:45:28 -070073 return true;
74}
75
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040076// static
77bool DBusProperties::GetUint32(const DBusPropertiesMap &properties,
78 const std::string &key,
79 uint32 *value) {
80 DBusPropertiesMap::const_iterator it = properties.find(key);
81 if (it == properties.end()) {
82 return false;
83 }
84 *value = it->second.reader().get_uint32();
85 SLOG(DBus, 2) << key << " = " << *value;
86 return true;
87}
88
Darin Petkove0a312e2011-07-20 13:45:28 -070089} // namespace shill