Darin Petkov | e4b2702 | 2012-05-16 13:28:50 +0200 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Darin Petkov | 25665aa | 2012-05-21 14:08:12 +0200 | [diff] [blame] | 5 | #ifndef SHILL_DBUS_PROPERTIES_H_ |
| 6 | #define SHILL_DBUS_PROPERTIES_H_ |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 7 | |
| 8 | #include <map> |
| 9 | #include <string> |
Jason Glasgow | 9c09e36 | 2012-04-18 15:16:29 -0400 | [diff] [blame] | 10 | #include <vector> |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 11 | |
| 12 | #include <base/basictypes.h> |
| 13 | #include <dbus-c++/types.h> |
| 14 | |
Darin Petkov | e4b2702 | 2012-05-16 13:28:50 +0200 | [diff] [blame] | 15 | #include "shill/accessor_interface.h" |
Gaurav Shah | 3df47b7 | 2013-03-22 15:40:41 -0700 | [diff] [blame] | 16 | #include "shill/dbus_variant_gmock_printer.h" |
Darin Petkov | e4b2702 | 2012-05-16 13:28:50 +0200 | [diff] [blame] | 17 | |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 18 | namespace shill { |
| 19 | |
| 20 | typedef std::map<std::string, DBus::Variant> DBusPropertiesMap; |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 21 | typedef std::map<uint32_t, DBus::Variant> DBusEnumValueMap; |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 22 | |
| 23 | class DBusProperties { |
| 24 | public: |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 25 | static bool GetBool(const DBusPropertiesMap &properties, |
| 26 | const std::string &key, |
| 27 | bool *value); |
| 28 | |
Ben Chan | 0a3a3a5 | 2013-07-10 11:34:07 -0700 | [diff] [blame] | 29 | static bool GetDBusPropertiesMap(const DBusPropertiesMap &properties, |
| 30 | const std::string &key, |
| 31 | DBusPropertiesMap *value); |
| 32 | |
| 33 | static bool GetDouble(const DBusPropertiesMap &properties, |
| 34 | const std::string &key, |
| 35 | double *value); |
| 36 | |
| 37 | static bool GetInt16(const DBusPropertiesMap &properties, |
| 38 | const std::string &key, |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 39 | int16_t *value); |
Ben Chan | 0a3a3a5 | 2013-07-10 11:34:07 -0700 | [diff] [blame] | 40 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 41 | static bool GetInt32(const DBusPropertiesMap &properties, |
| 42 | const std::string &key, |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 43 | int32_t *value); |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 44 | |
Ben Chan | 0a3a3a5 | 2013-07-10 11:34:07 -0700 | [diff] [blame] | 45 | static bool GetInt64(const DBusPropertiesMap &properties, |
| 46 | const std::string &key, |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 47 | int64_t *value); |
Ben Chan | 0a3a3a5 | 2013-07-10 11:34:07 -0700 | [diff] [blame] | 48 | |
Nathan Williams | e984080 | 2012-04-18 18:47:40 -0400 | [diff] [blame] | 49 | static bool GetObjectPath(const DBusPropertiesMap &properties, |
| 50 | const std::string &key, |
Ben Chan | 0a3a3a5 | 2013-07-10 11:34:07 -0700 | [diff] [blame] | 51 | DBus::Path *value); |
Nathan Williams | e984080 | 2012-04-18 18:47:40 -0400 | [diff] [blame] | 52 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 53 | static bool GetString(const DBusPropertiesMap &properties, |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 54 | const std::string &key, |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 55 | std::string *value); |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 56 | |
Arman Uguray | 631c7e4 | 2013-07-30 16:41:12 -0700 | [diff] [blame] | 57 | static bool GetStringmap(const DBusPropertiesMap &properties, |
| 58 | const std::string &key, |
| 59 | std::map<std::string, std::string> *value); |
| 60 | |
Jason Glasgow | 9c09e36 | 2012-04-18 15:16:29 -0400 | [diff] [blame] | 61 | static bool GetStrings(const DBusPropertiesMap &properties, |
| 62 | const std::string &key, |
| 63 | std::vector<std::string> *value); |
| 64 | |
Ben Chan | 0a3a3a5 | 2013-07-10 11:34:07 -0700 | [diff] [blame] | 65 | static bool GetUint8(const DBusPropertiesMap &properties, |
| 66 | const std::string &key, |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 67 | uint8_t *value); |
Ben Chan | 0a3a3a5 | 2013-07-10 11:34:07 -0700 | [diff] [blame] | 68 | |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 69 | static bool GetUint16(const DBusPropertiesMap &properties, |
| 70 | const std::string &key, |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 71 | uint16_t *value); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 72 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 73 | static bool GetUint32(const DBusPropertiesMap &properties, |
| 74 | const std::string &key, |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 75 | uint32_t *value); |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 76 | |
Ben Chan | 0a3a3a5 | 2013-07-10 11:34:07 -0700 | [diff] [blame] | 77 | static bool GetUint64(const DBusPropertiesMap &properties, |
| 78 | const std::string &key, |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 79 | uint64_t *value); |
Ben Chan | 0a3a3a5 | 2013-07-10 11:34:07 -0700 | [diff] [blame] | 80 | |
Darin Petkov | e4b2702 | 2012-05-16 13:28:50 +0200 | [diff] [blame] | 81 | static bool GetRpcIdentifiers(const DBusPropertiesMap &properties, |
| 82 | const std::string &key, |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 83 | RpcIdentifiers *value); |
| 84 | |
| 85 | static void ConvertPathsToRpcIdentifiers( |
| 86 | const std::vector<DBus::Path> &dbus_paths, |
| 87 | RpcIdentifiers *rpc_identifiers); |
Darin Petkov | e4b2702 | 2012-05-16 13:28:50 +0200 | [diff] [blame] | 88 | |
Darin Petkov | 25665aa | 2012-05-21 14:08:12 +0200 | [diff] [blame] | 89 | static void ConvertKeyValueStoreToMap( |
| 90 | const KeyValueStore &store, DBusPropertiesMap *properties); |
| 91 | |
Ben Chan | 0a3a3a5 | 2013-07-10 11:34:07 -0700 | [diff] [blame] | 92 | static std::string KeysToString(const DBusPropertiesMap &properties); |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 93 | |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 94 | private: |
| 95 | DISALLOW_COPY_AND_ASSIGN(DBusProperties); |
| 96 | }; |
| 97 | |
| 98 | } // namespace shill |
| 99 | |
Darin Petkov | 25665aa | 2012-05-21 14:08:12 +0200 | [diff] [blame] | 100 | #endif // SHILL_DBUS_PROPERTIES_H_ |