OLD | NEW |
(Empty) | |
| 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_DEVICE_HANDLER_H_ |
| 6 #define CHROMEOS_NETWORK_NETWORK_DEVICE_HANDLER_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <set> |
| 10 #include <string> |
| 11 |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/observer_list.h" |
| 14 #include "chromeos/chromeos_export.h" |
| 15 #include "chromeos/dbus/dbus_method_call_status.h" |
| 16 #include "chromeos/dbus/shill_property_changed_observer.h" |
| 17 #include "chromeos/network/network_util.h" // WifiAccessPoint |
| 18 |
| 19 namespace base { |
| 20 class DictionaryValue; |
| 21 class ListValue; |
| 22 class Value; |
| 23 } |
| 24 |
| 25 namespace chromeos { |
| 26 |
| 27 class CHROMEOS_EXPORT NetworkDeviceHandler |
| 28 : public ShillPropertyChangedObserver { |
| 29 public: |
| 30 struct Device { |
| 31 Device(); |
| 32 ~Device(); |
| 33 std::string type; |
| 34 bool powered; |
| 35 bool scanning; |
| 36 int scan_interval; |
| 37 std::map<std::string, WifiAccessPoint> wifi_access_points; |
| 38 }; |
| 39 typedef std::map<std::string, Device> DeviceMap; |
| 40 |
| 41 class Observer { |
| 42 public: |
| 43 typedef NetworkDeviceHandler::DeviceMap DeviceMap; |
| 44 |
| 45 // Called when devices are updated. Passes the updated map of devices. |
| 46 virtual void NetworkDevicesUpdated(const DeviceMap& devices) = 0; |
| 47 |
| 48 protected: |
| 49 virtual ~Observer() {} |
| 50 }; |
| 51 |
| 52 NetworkDeviceHandler(); |
| 53 virtual ~NetworkDeviceHandler(); |
| 54 void Init(); |
| 55 |
| 56 // Add/remove observers. |
| 57 void AddObserver(Observer* observer); |
| 58 void RemoveObserver(Observer* observer); |
| 59 |
| 60 bool devices_ready() const { return devices_ready_; } |
| 61 const DeviceMap& devices() const { return devices_; } |
| 62 |
| 63 // ShillPropertyChangedObserver overrides |
| 64 virtual void OnPropertyChanged(const std::string& key, |
| 65 const base::Value& value) OVERRIDE; |
| 66 |
| 67 private: |
| 68 void ManagerPropertiesCallback(DBusMethodCallStatus call_status, |
| 69 const base::DictionaryValue& properties); |
| 70 void DevicePropertyChanged(const base::ListValue* devices); |
| 71 void DevicePropertiesCallback(const std::string& device_path, |
| 72 DBusMethodCallStatus call_status, |
| 73 const base::DictionaryValue& properties); |
| 74 void NetworkPropertiesCallback(const std::string& device_path, |
| 75 const std::string& network_path, |
| 76 DBusMethodCallStatus call_status, |
| 77 const base::DictionaryValue& properties); |
| 78 void DeviceNetworkReady(const std::string& device_path, |
| 79 const std::string& network_path); |
| 80 void DeviceReady(const std::string& device_path); |
| 81 |
| 82 // True when the device list is up to date. |
| 83 bool devices_ready_; |
| 84 |
| 85 // Map of Device structs, valid when |devices_ready_| is true. |
| 86 DeviceMap devices_; |
| 87 |
| 88 // Map of pending devices. |
| 89 std::set<std::string> pending_device_paths_; |
| 90 |
| 91 // Map of pending networks per device path. |
| 92 std::map<std::string, std::set<std::string> > pending_network_paths_; |
| 93 |
| 94 // Observer list |
| 95 ObserverList<Observer> observers_; |
| 96 |
| 97 // For Shill client callbacks |
| 98 base::WeakPtrFactory<NetworkDeviceHandler> weak_ptr_factory_; |
| 99 }; |
| 100 |
| 101 } // namespace chromeos |
| 102 |
| 103 #endif // CHROMEOS_NETWORK_NETWORK_DEVICE_HANDLER_H_ |
OLD | NEW |