OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium 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 #ifndef CHROMEOS_NETWORK_NETWORK_UTIL_H_ | 5 #ifndef CHROMEOS_NETWORK_NETWORK_UTIL_H_ |
6 #define CHROMEOS_NETWORK_NETWORK_UTIL_H_ | 6 #define CHROMEOS_NETWORK_NETWORK_UTIL_H_ |
7 | 7 |
8 // This header is introduced to make it easy to switch from chromeos_network.cc | 8 // This header is introduced to make it easy to switch from chromeos_network.cc |
9 // to Chrome's own DBus code. crosbug.com/16557 | 9 // to Chrome's own DBus code. crosbug.com/16557 |
10 // All calls to functions in chromeos_network.h should be made through | 10 // All calls to functions in chromeos_network.h should be made through |
11 // functions provided by this header. | 11 // functions provided by this header. |
12 | 12 |
13 #include <string> | 13 #include <string> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
17 #include "base/callback.h" | 17 #include "base/callback.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "base/values.h" |
19 #include "chromeos/chromeos_export.h" | 20 #include "chromeos/chromeos_export.h" |
20 | 21 |
21 namespace chromeos { | 22 namespace chromeos { |
22 | 23 |
23 // Struct to represent a SMS. | 24 // Struct to represent a SMS. |
24 struct CHROMEOS_EXPORT SMS { | 25 struct CHROMEOS_EXPORT SMS { |
25 SMS(); | 26 SMS(); |
26 ~SMS(); | 27 ~SMS(); |
27 base::Time timestamp; | 28 base::Time timestamp; |
28 std::string number; | 29 std::string number; |
29 std::string text; | 30 std::string text; |
30 std::string smsc; // optional; empty if not present in message. | 31 std::string smsc; // optional; empty if not present in message. |
31 int32 validity; // optional; -1 if not present in message. | 32 int32 validity; // optional; -1 if not present in message. |
32 int32 msgclass; // optional; -1 if not present in message. | 33 int32 msgclass; // optional; -1 if not present in message. |
33 }; | 34 }; |
34 | 35 |
35 // Struct for passing wifi access point data. | 36 // Struct for passing wifi access point data. |
36 struct CHROMEOS_EXPORT WifiAccessPoint { | 37 struct CHROMEOS_EXPORT WifiAccessPoint { |
37 WifiAccessPoint(); | 38 WifiAccessPoint(); |
38 ~WifiAccessPoint(); | 39 ~WifiAccessPoint(); |
39 std::string ssid; // The ssid of the WiFi node if available. | 40 std::string ssid; // The ssid of the WiFi node if available. |
40 std::string mac_address; // The mac address of the WiFi node. | 41 std::string mac_address; // The mac address of the WiFi node. |
41 base::Time timestamp; // Timestamp when this AP was detected. | 42 base::Time timestamp; // Timestamp when this AP was detected. |
42 int signal_strength; // Radio signal strength measured in dBm. | 43 int signal_strength; // Radio signal strength measured in dBm. |
43 int signal_to_noise; // Current signal to noise ratio measured in dB. | 44 int signal_to_noise; // Current signal to noise ratio measured in dB. |
44 int channel; // Wifi channel number. | 45 int channel; // Wifi channel number. |
45 }; | 46 }; |
46 | 47 |
| 48 // Struct for passing network scan result data. |
| 49 struct CHROMEOS_EXPORT CellularScanResult { |
| 50 CellularScanResult(); |
| 51 ~CellularScanResult(); |
| 52 std::string status; // The network's availability status. (One of "unknown", |
| 53 // "available", "current", or "forbidden") |
| 54 std::string network_id; // 3GPP operator code ("MCCMNC"). |
| 55 std::string short_name; // Short-format name of the operator. |
| 56 std::string long_name; // Long-format name of the operator. |
| 57 std::string technology; // Access technology. |
| 58 }; |
| 59 |
47 typedef std::vector<WifiAccessPoint> WifiAccessPointVector; | 60 typedef std::vector<WifiAccessPoint> WifiAccessPointVector; |
48 | 61 |
49 // Describes whether there is an error and whether the error came from | 62 // Describes whether there is an error and whether the error came from |
50 // the local system or from the server implementing the connect | 63 // the local system or from the server implementing the connect |
51 // method. | 64 // method. |
52 enum NetworkMethodErrorType { | 65 enum NetworkMethodErrorType { |
53 NETWORK_METHOD_ERROR_NONE = 0, | 66 NETWORK_METHOD_ERROR_NONE = 0, |
54 NETWORK_METHOD_ERROR_LOCAL = 1, | 67 NETWORK_METHOD_ERROR_LOCAL = 1, |
55 NETWORK_METHOD_ERROR_REMOTE = 2, | 68 NETWORK_METHOD_ERROR_REMOTE = 2, |
56 }; | 69 }; |
57 | 70 |
58 // Callback for methods that initiate an operation and return no data. | 71 // Callback for methods that initiate an operation and return no data. |
59 typedef base::Callback<void( | 72 typedef base::Callback<void( |
60 const std::string& path, | 73 const std::string& path, |
61 NetworkMethodErrorType error, | 74 NetworkMethodErrorType error, |
62 const std::string& error_message)> NetworkOperationCallback; | 75 const std::string& error_message)> NetworkOperationCallback; |
63 | 76 |
64 namespace network_util { | 77 namespace network_util { |
65 | 78 |
66 // Converts a |prefix_length| to a netmask. (for IPv4 only) | 79 // Converts a |prefix_length| to a netmask. (for IPv4 only) |
67 // e.g. a |prefix_length| of 24 is converted to a netmask of "255.255.255.0". | 80 // e.g. a |prefix_length| of 24 is converted to a netmask of "255.255.255.0". |
68 // Invalid prefix lengths will return the empty string. | 81 // Invalid prefix lengths will return the empty string. |
69 CHROMEOS_EXPORT std::string PrefixLengthToNetmask(int32 prefix_length); | 82 CHROMEOS_EXPORT std::string PrefixLengthToNetmask(int32 prefix_length); |
70 | 83 |
71 // Converts a |netmask| to a prefixlen. (for IPv4 only) | 84 // Converts a |netmask| to a prefixlen. (for IPv4 only) |
72 // e.g. a |netmask| of 255.255.255.0 is converted to a prefixlen of 24 | 85 // e.g. a |netmask| of 255.255.255.0 is converted to a prefixlen of 24 |
73 CHROMEOS_EXPORT int32 NetmaskToPrefixLength(const std::string& netmask); | 86 CHROMEOS_EXPORT int32 NetmaskToPrefixLength(const std::string& netmask); |
74 | 87 |
| 88 // Parses |list|, which contains DictionaryValues and returns a vector of |
| 89 // CellularScanResult in |scan_results|. Returns false if parsing fails, |
| 90 // in which case the contents of |scan_results| will be undefined. |
| 91 CHROMEOS_EXPORT bool ParseCellularScanResults( |
| 92 const ListValue& list, std::vector<CellularScanResult>* scan_results); |
| 93 |
75 } // namespace network_util | 94 } // namespace network_util |
76 } // namespace chromeos | 95 } // namespace chromeos |
77 | 96 |
78 #endif // CHROMEOS_NETWORK_NETWORK_UTIL_H_ | 97 #endif // CHROMEOS_NETWORK_NETWORK_UTIL_H_ |
OLD | NEW |