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 // Utilities for plugins for the cromo modem manager. | 5 // Utilities for plugins for the cromo modem manager. |
6 | 6 |
7 #ifndef CROMO_UTILITIES_H_ | 7 #ifndef CROMO_UTILITIES_H_ |
8 #define CROMO_UTILITIES_H_ | 8 #define CROMO_UTILITIES_H_ |
9 | 9 |
10 #include <base/basictypes.h> | 10 #include <base/basictypes.h> |
11 #include <map> | 11 #include <map> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include <dbus/dbus.h> | 14 #include <dbus/dbus.h> |
15 #include <dbus-c++/dbus.h> | 15 #include <dbus-c++/dbus.h> |
16 | 16 |
17 namespace utilities { | 17 namespace utilities { |
18 | 18 |
19 typedef std::map<std::string, DBus::Variant> DBusPropertyMap; | 19 typedef std::map<std::string, DBus::Variant> DBusPropertyMap; |
20 | 20 |
21 // Extracts the key from proprties, returning not_found_response if | 21 // Extracts the key from properties, returning not_found_response if |
22 // the key is not found. If key is found, but is not a string, sets | 22 // the key is not found. If key is found, but is not a string, sets |
23 // error and returns not_found_response. If error.is_set() is true, | 23 // error and returns not_found_response. If error.is_set() is true, |
24 // ExtractString will not report further errors. You can make | 24 // ExtractString will not report further errors. You can make |
25 // multiple ExtractString calls and check error at the end. | 25 // multiple ExtractString calls and check error at the end. |
26 const char *ExtractString(const DBusPropertyMap properties, | 26 const char* ExtractString(const DBusPropertyMap properties, |
27 const char *key, | 27 const char* key, |
28 const char *not_found_response, | 28 const char* not_found_response, |
29 DBus::Error &error); | 29 DBus::Error& error); |
30 | 30 |
31 // Extracts the key from proprties, returning not_found_response if | 31 // Extracts the key from properties, returning not_found_response if |
32 // the key is not found. If key is found, but is not a Uint32, sets | 32 // the key is not found. If key is found, but is not a Uint32, sets |
33 // error and returns not_found_response. If error.is_set() is true, | 33 // error and returns not_found_response. If error.is_set() is true, |
34 // ExtractUint32 will not report further errors. You can make | 34 // ExtractUint32 will not report further errors. You can make |
35 // multiple ExtractUint32 calls and check error at the end. | 35 // multiple ExtractUint32 calls and check error at the end. |
36 uint32_t ExtractUint32(const DBusPropertyMap properties, | 36 uint32_t ExtractUint32(const DBusPropertyMap properties, |
37 const char *key, | 37 const char* key, |
38 uint32_t not_found_response, | 38 uint32_t not_found_response, |
39 DBus::Error &error); | 39 DBus::Error& error); |
40 | 40 |
41 | 41 |
42 // Convert a string representing a hex ESN to one representing a | 42 // Convert a string representing a hex ESN to one representing a |
43 // decimal ESN. Returns success. | 43 // decimal ESN. Returns success. |
44 bool HexEsnToDecimal(const std::string &esn_hex, std::string *out); | 44 bool HexEsnToDecimal(const std::string& esn_hex, std::string* out); |
| 45 |
| 46 // Converts an array of bytes containing text encoded in the GSM 03.38 |
| 47 // character set (also know as GSM-7) into a UTF-8 encoded string. |
| 48 // GSM-7 is a 7-bit character set, and in SMS messages, the 7-bit |
| 49 // septets are packed into an array of 8-bit octets. |
| 50 // |
| 51 // The first byte of the input array the length of the converted |
| 52 // data in septets, i.e., it is the number of GSM-7 septets that |
| 53 // will result after the array is unpacked. |
| 54 std::string Gsm7ToUtf8String(const uint8_t* gsm7); |
| 55 |
| 56 // Converts a string of characters encoded using UTF-8 into an |
| 57 // array of bytes which is result of converting the string into |
| 58 // septets in the GSM-7 alphabet and then packing the septets into |
| 59 // octets. |
| 60 std::vector<uint8_t> Utf8StringToGsm7(const std::string& input); |
| 61 |
| 62 // Debugging utility for printing an array of bytes in a nicely |
| 63 // formatted manner รก la the UNIX hd command. |
| 64 void DumpHex(const uint8_t* buf, size_t size); |
45 | 65 |
46 } // namespace utilities | 66 } // namespace utilities |
47 | 67 |
48 #endif /* CROMO_UTILITIES_H_ */ | 68 #endif /* CROMO_UTILITIES_H_ */ |
OLD | NEW |