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