OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Plugin tests link against this file, but not against the rest of | 5 // Plugin tests link against this file, but not against the rest of |
6 // cromo. Therefore this file should not have dependencies on the | 6 // cromo. Therefore this file should not have dependencies on the |
7 // rest of cromo. | 7 // rest of cromo. |
8 #include "utilities.h" | 8 #include "utilities.h" |
9 | 9 |
10 #include <glog/logging.h> | 10 #include <glog/logging.h> |
(...skipping 18 matching lines...) Expand all Loading... |
29 // Setting an already-set error causes an assert fail inside dbus-c++. | 29 // Setting an already-set error causes an assert fail inside dbus-c++. |
30 if (!error.is_set()) { | 30 if (!error.is_set()) { |
31 // NB: the copy constructor for DBus::Error causes a template to | 31 // NB: the copy constructor for DBus::Error causes a template to |
32 // be instantiated that kills our -Werror build | 32 // be instantiated that kills our -Werror build |
33 error.set(e.name(), e.message()); | 33 error.set(e.name(), e.message()); |
34 } | 34 } |
35 } | 35 } |
36 return to_return; | 36 return to_return; |
37 } | 37 } |
38 | 38 |
| 39 uint32_t ExtractUint32(const DBusPropertyMap properties, |
| 40 const char *key, |
| 41 uint32_t not_found_response, |
| 42 DBus::Error &error) { |
| 43 DBusPropertyMap::const_iterator p; |
| 44 unsigned int to_return = not_found_response; |
| 45 try { |
| 46 p = properties.find(key); |
| 47 if (p != properties.end()) { |
| 48 to_return = p->second.reader().get_uint32(); |
| 49 } |
| 50 } catch (const DBus::Error &e) { |
| 51 LOG(ERROR)<<"Bad type for: " << key; |
| 52 // Setting an already-set error causes an assert fail inside dbus-c++. |
| 53 if (!error.is_set()) { |
| 54 // NB: the copy constructor for DBus::Error causes a template to |
| 55 // be instantiated that kills our -Werror build |
| 56 error.set(e.name(), e.message()); |
| 57 } |
| 58 } |
| 59 return to_return; |
| 60 } |
| 61 |
39 bool HexEsnToDecimal(const std::string &esn_hex, std::string *out) { | 62 bool HexEsnToDecimal(const std::string &esn_hex, std::string *out) { |
40 size_t length = esn_hex.length(); | 63 size_t length = esn_hex.length(); |
41 if (length > 8) { | 64 if (length > 8) { |
42 LOG(ERROR) << "Long ESN: " << esn_hex; | 65 LOG(ERROR) << "Long ESN: " << esn_hex; |
43 return false; | 66 return false; |
44 } | 67 } |
45 errno = 0; | 68 errno = 0; |
46 const char *start = esn_hex.c_str(); | 69 const char *start = esn_hex.c_str(); |
47 char *end; | 70 char *end; |
48 uint32_t esn = strtoul(start, &end, 16); | 71 uint32_t esn = strtoul(start, &end, 16); |
(...skipping 11 matching lines...) Expand all Loading... |
60 if (rc != 11) { | 83 if (rc != 11) { |
61 LOG(ERROR) << "Format failure"; | 84 LOG(ERROR) << "Format failure"; |
62 return false; | 85 return false; |
63 } | 86 } |
64 if (out) { | 87 if (out) { |
65 *out = decimal; | 88 *out = decimal; |
66 } | 89 } |
67 return true; | 90 return true; |
68 } | 91 } |
69 } // namespace utilities | 92 } // namespace utilities |
OLD | NEW |