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