shill_property_util.h revision 68043e1e95eeb07d5cae7aca370b26518b0867d6
1// Copyright 2013 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_SHILL_PROPERTY_UTIL_H_
6#define CHROMEOS_NETWORK_SHILL_PROPERTY_UTIL_H_
7
8#include <string>
9
10#include "base/memory/scoped_ptr.h"
11#include "chromeos/chromeos_export.h"
12
13namespace base {
14class DictionaryValue;
15class Value;
16}
17
18namespace chromeos {
19
20class NetworkUIData;
21
22namespace shill_property_util {
23
24// Generates a name from properties."Wifi.HexSSID" if present, otherwise
25// validates properties.Name and returns a valid utf8 version.
26CHROMEOS_EXPORT std::string GetNameFromProperties(
27    const std::string& service_path,
28    const base::DictionaryValue& properties);
29
30// Returns the UIData specified by |value|. Returns NULL if the value cannot be
31// parsed.
32scoped_ptr<NetworkUIData> GetUIDataFromValue(const base::Value& value);
33
34// Returns the NetworkUIData parsed from the UIData property of
35// |shill_dictionary|. If parsing fails or the field doesn't exist, returns
36// NULL.
37scoped_ptr<NetworkUIData> GetUIDataFromProperties(
38    const base::DictionaryValue& shill_dictionary);
39
40// Sets the UIData property in |shill_dictionary| to the serialization of
41// |ui_data|.
42void SetUIData(const NetworkUIData& ui_data,
43               base::DictionaryValue* shill_dictionary);
44
45// Copy configuration properties required by Shill to identify a network.
46// Only WiFi, VPN, Ethernet and EthernetEAP are supported. WiMax and Cellular
47// are not supported. Returns true only if all required properties could be
48// copied.
49bool CopyIdentifyingProperties(const base::DictionaryValue& service_properties,
50                               base::DictionaryValue* dest);
51
52}  // namespace shill_property_util
53
54class CHROMEOS_EXPORT NetworkTypePattern {
55 public:
56  // Matches any network.
57  static NetworkTypePattern Default();
58
59  // Matches wireless networks
60  static NetworkTypePattern Wireless();
61
62  // Matches cellular or wimax networks.
63  static NetworkTypePattern Mobile();
64
65  // Matches non virtual networks.
66  static NetworkTypePattern NonVirtual();
67
68  // Matches ethernet networks (with or without EAP).
69  static NetworkTypePattern Ethernet();
70
71  static NetworkTypePattern WiFi();
72  static NetworkTypePattern Cellular();
73  static NetworkTypePattern VPN();
74  static NetworkTypePattern Wimax();
75
76  // Matches only networks of exactly the type |shill_network_type|, which must
77  // be one of the types defined in service_constants.h (e.g.
78  // shill::kTypeWifi).
79  // Note: Shill distinguishes Ethernet without EAP from Ethernet with EAP. If
80  // unsure, better use one of the matchers above.
81  static NetworkTypePattern Primitive(const std::string& shill_network_type);
82
83  bool Equals(const NetworkTypePattern& other) const;
84  bool MatchesType(const std::string& shill_network_type) const;
85
86  // Returns true if this pattern matches at least one network type that
87  // |other_pattern| matches (according to MatchesType). Thus MatchesPattern is
88  // symmetric and reflexive but not transitive.
89  // See the unit test for examples.
90  bool MatchesPattern(const NetworkTypePattern& other_pattern) const;
91
92  std::string ToDebugString() const;
93
94 private:
95  explicit NetworkTypePattern(int pattern);
96
97  // The bit array of the matching network types.
98  int pattern_;
99
100  DISALLOW_ASSIGN(NetworkTypePattern);
101};
102
103}  // namespace chromeos
104
105#endif  // CHROMEOS_NETWORK_SHILL_PROPERTY_UTIL_H_
106