| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 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 #ifndef CHROMEOS_DBUS_AP_MANAGER_CLIENT_H_ | |
| 5 #define CHROMEOS_DBUS_AP_MANAGER_CLIENT_H_ | |
| 6 | |
| 7 #include <stdint.h> | |
| 8 | |
| 9 #include <map> | |
| 10 #include <string> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/callback.h" | |
| 14 #include "base/macros.h" | |
| 15 #include "base/values.h" | |
| 16 #include "chromeos/chromeos_export.h" | |
| 17 #include "chromeos/dbus/dbus_client.h" | |
| 18 #include "chromeos/dbus/dbus_method_call_status.h" | |
| 19 #include "dbus/object_path.h" | |
| 20 #include "dbus/property.h" | |
| 21 | |
| 22 namespace chromeos { | |
| 23 | |
| 24 // ApManagerClient is used to communicate with the | |
| 25 // WiFi AP Manager service. All methods should be called from | |
| 26 // the origin thread which initializes the DBusThreadManager instance. | |
| 27 class CHROMEOS_EXPORT ApManagerClient : public DBusClient { | |
| 28 public: | |
| 29 // Structure of properties associated with a WiFi service AP configuration. | |
| 30 // These properties must be set before Start is called. | |
| 31 class ConfigProperties : public dbus::PropertySet { | |
| 32 public: | |
| 33 ConfigProperties(dbus::ObjectProxy* object_proxy, | |
| 34 const std::string& interface_name, | |
| 35 const PropertyChangedCallback& callback); | |
| 36 ~ConfigProperties() override; | |
| 37 | |
| 38 // Name of network [required]. | |
| 39 const std::string& ssid() const { return ssid_.value(); } | |
| 40 void set_ssid(const std::string& ssid, SetCallback callback) { | |
| 41 ssid_.Set(ssid, callback); | |
| 42 } | |
| 43 | |
| 44 // Interface name [optional]. | |
| 45 const std::string& interface_name() const { | |
| 46 return interface_name_.value(); | |
| 47 } | |
| 48 void set_interface_name(const std::string& name, SetCallback callback) { | |
| 49 interface_name_.Set(name, callback); | |
| 50 } | |
| 51 | |
| 52 // Security Mode; "RSN", "None" [optional]. | |
| 53 const std::string& security_mode() const { return security_mode_.value(); } | |
| 54 void set_security_mode(const std::string& mode, SetCallback callback) { | |
| 55 security_mode_.Set(mode, callback); | |
| 56 } | |
| 57 | |
| 58 // Passphrase; [required] when security is not "None". | |
| 59 const std::string& passphrase() const { return passphrase_.value(); } | |
| 60 void set_passphrase(const std::string& passphrase, SetCallback callback) { | |
| 61 passphrase_.Set(passphrase, callback); | |
| 62 } | |
| 63 | |
| 64 // HwMode, "802.11a", "802.11b". Default: "802.11g" [optional]. | |
| 65 const std::string& hw_mode() const { return hw_mode_.value(); } | |
| 66 void set_hw_mode(const std::string& mode, SetCallback callback) { | |
| 67 hw_mode_.Set(mode, callback); | |
| 68 } | |
| 69 | |
| 70 // Operation mode, "Bridge" or "Server". Default "Server". [optional]. | |
| 71 const std::string& operation_mode() const { | |
| 72 return operation_mode_.value(); | |
| 73 } | |
| 74 void set_operation_mode(const std::string& mode, SetCallback callback) { | |
| 75 operation_mode_.Set(mode, callback); | |
| 76 } | |
| 77 | |
| 78 // Operating channel. Default '6' [optional]. | |
| 79 uint16_t channel() const { return channel_.value(); } | |
| 80 void set_channel(uint16_t channel, SetCallback callback) { | |
| 81 channel_.Set(channel, callback); | |
| 82 } | |
| 83 | |
| 84 // Hidden network. Default "false". [optional]. | |
| 85 bool hidden_network() const { return hidden_network_.value(); } | |
| 86 void set_hidden_network(bool hidden, SetCallback callback) { | |
| 87 hidden_network_.Set(hidden, callback); | |
| 88 } | |
| 89 | |
| 90 // Bridge interface. [required] if Bridge operation mode set. | |
| 91 const std::string& bridge_interface() const { | |
| 92 return bridge_interface_.value(); | |
| 93 } | |
| 94 void set_bridge_interface(const std::string& interface, | |
| 95 SetCallback callback) { | |
| 96 bridge_interface_.Set(interface, callback); | |
| 97 } | |
| 98 | |
| 99 // The value of x in the following equation; "192.168.x.254". | |
| 100 // This will be the server's IP address. [required] only if | |
| 101 // operation mode set to "Server". | |
| 102 uint16_t server_address_index() const { | |
| 103 return server_address_index_.value(); | |
| 104 } | |
| 105 void set_server_address_index(uint16_t index, SetCallback callback) { | |
| 106 server_address_index_.Set(index, callback); | |
| 107 } | |
| 108 | |
| 109 private: | |
| 110 dbus::Property<std::string> ssid_; | |
| 111 dbus::Property<std::string> interface_name_; | |
| 112 dbus::Property<std::string> security_mode_; | |
| 113 dbus::Property<std::string> passphrase_; | |
| 114 dbus::Property<std::string> hw_mode_; | |
| 115 dbus::Property<std::string> operation_mode_; | |
| 116 dbus::Property<uint16_t> channel_; | |
| 117 dbus::Property<bool> hidden_network_; | |
| 118 dbus::Property<std::string> bridge_interface_; | |
| 119 dbus::Property<uint16_t> server_address_index_; | |
| 120 | |
| 121 DISALLOW_COPY_AND_ASSIGN(ConfigProperties); | |
| 122 }; | |
| 123 | |
| 124 // Structure of properties associated with a WiFi service AP device. | |
| 125 class DeviceProperties : public dbus::PropertySet { | |
| 126 public: | |
| 127 DeviceProperties(dbus::ObjectProxy* object_proxy, | |
| 128 const std::string& interface_name, | |
| 129 const PropertyChangedCallback& callback); | |
| 130 ~DeviceProperties() override; | |
| 131 | |
| 132 // Name of the WiFi device. | |
| 133 const std::string& device_name() const { return device_name_.value(); } | |
| 134 | |
| 135 // Flag indicating if this device is currently in-use by apmanager. | |
| 136 bool in_use() const { return in_used_.value(); } | |
| 137 | |
| 138 // Name of the WiFi interface on the device that’s preferred for starting an | |
| 139 // AP serivce. | |
| 140 const std::string& preferred_ap_interface() const { | |
| 141 return preferred_ap_interface_.value(); | |
| 142 } | |
| 143 | |
| 144 private: | |
| 145 dbus::Property<std::string> device_name_; | |
| 146 dbus::Property<bool> in_used_; | |
| 147 dbus::Property<std::string> preferred_ap_interface_; | |
| 148 | |
| 149 DISALLOW_COPY_AND_ASSIGN(DeviceProperties); | |
| 150 }; | |
| 151 | |
| 152 // Structure of properties associated with a WiFi service AP service. | |
| 153 class ServiceProperties : public dbus::PropertySet { | |
| 154 public: | |
| 155 ServiceProperties(dbus::ObjectProxy* object_proxy, | |
| 156 const std::string& interface_name, | |
| 157 const PropertyChangedCallback& callback); | |
| 158 ~ServiceProperties() override; | |
| 159 | |
| 160 // DBus path of the config for this service. | |
| 161 const dbus::ObjectPath& config_path() const { return config_.value(); } | |
| 162 | |
| 163 // Current state of service. ["Idle", "Starting", "Started", "Failed"]. | |
| 164 const std::string& state() const { return state_.value(); } | |
| 165 | |
| 166 private: | |
| 167 dbus::Property<dbus::ObjectPath> config_; | |
| 168 dbus::Property<std::string> state_; | |
| 169 | |
| 170 DISALLOW_COPY_AND_ASSIGN(ServiceProperties); | |
| 171 }; | |
| 172 | |
| 173 // Interface for observing changes from a apmanager daemon. | |
| 174 class Observer { | |
| 175 public: | |
| 176 virtual ~Observer(); | |
| 177 | |
| 178 // Called when the manager has been added. | |
| 179 virtual void ManagerAdded(); | |
| 180 | |
| 181 // Called when the manager has been removed. | |
| 182 virtual void ManagerRemoved(); | |
| 183 | |
| 184 // Called when the config with object path |object_path| is added to the | |
| 185 // system. | |
| 186 virtual void ConfigAdded(const dbus::ObjectPath& object_path); | |
| 187 | |
| 188 // Called when the config with object path |object_path| is removed from | |
| 189 // the system. | |
| 190 virtual void ConfigRemoved(const dbus::ObjectPath& object_path); | |
| 191 | |
| 192 // Called when the device with object path |object_path| is added to the | |
| 193 // system. | |
| 194 virtual void DeviceAdded(const dbus::ObjectPath& object_path); | |
| 195 | |
| 196 // Called when the device with object path |object_path| is removed from | |
| 197 // the system. | |
| 198 virtual void DeviceRemoved(const dbus::ObjectPath& object_path); | |
| 199 | |
| 200 // Called when the device with object path |object_path| is added to the | |
| 201 // system. | |
| 202 virtual void ServiceAdded(const dbus::ObjectPath& object_path); | |
| 203 | |
| 204 // Called when the device with object path |object_path| is removed from | |
| 205 // the system. | |
| 206 virtual void ServiceRemoved(const dbus::ObjectPath& object_path); | |
| 207 | |
| 208 // Called when the adapter with object path |object_path| has a | |
| 209 // change in value of the property named |property_name|. | |
| 210 virtual void ConfigPropertyChanged(const dbus::ObjectPath& object_path, | |
| 211 const std::string& property_name); | |
| 212 | |
| 213 // Called when the adapter with object path |object_path| has a | |
| 214 // change in value of the property named |property_name|. | |
| 215 virtual void DevicePropertyChanged(const dbus::ObjectPath& object_path, | |
| 216 const std::string& property_name); | |
| 217 | |
| 218 // Called when the adapter with object path |object_path| has a | |
| 219 // change in value of the property named |property_name|. | |
| 220 virtual void ServicePropertyChanged(const dbus::ObjectPath& object_path, | |
| 221 const std::string& property_name); | |
| 222 }; | |
| 223 | |
| 224 ~ApManagerClient() override; | |
| 225 | |
| 226 // Factory function, creates a new instance which is owned by the caller. | |
| 227 // For normal usage, access the singleton via DBusThreadManager::Get(). | |
| 228 static ApManagerClient* Create(); | |
| 229 | |
| 230 // Adds and removes observers for events on all apmanager | |
| 231 // events. Check the |object_path| parameter of observer methods to | |
| 232 // determine which group is issuing the event. | |
| 233 virtual void AddObserver(Observer* observer) = 0; | |
| 234 virtual void RemoveObserver(Observer* observer) = 0; | |
| 235 | |
| 236 // Calls CreateService method. | |
| 237 // |callback| is called with its |call_status| argument set to | |
| 238 // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise, | |
| 239 // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE. | |
| 240 virtual void CreateService(const ObjectPathDBusMethodCallback& callback) = 0; | |
| 241 | |
| 242 // Calls RemoveService method. | |
| 243 // |callback| is called with its |call_status| argument set to | |
| 244 // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise, | |
| 245 // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE. | |
| 246 virtual void RemoveService(const dbus::ObjectPath& object_path, | |
| 247 const VoidDBusMethodCallback& callback) = 0; | |
| 248 | |
| 249 // Calls Service::Start method. | |
| 250 // |callback| is called with its |call_status| argument set to | |
| 251 // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise, | |
| 252 // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE. | |
| 253 virtual void StartService(const dbus::ObjectPath& object_path, | |
| 254 const VoidDBusMethodCallback& callback) = 0; | |
| 255 | |
| 256 // Calls Service::Stop method. | |
| 257 // |callback| is called with its |call_status| argument set to | |
| 258 // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise, | |
| 259 // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE. | |
| 260 virtual void StopService(const dbus::ObjectPath& object_path, | |
| 261 const VoidDBusMethodCallback& callback) = 0; | |
| 262 | |
| 263 // Obtains the properties for the config with object path |object_path|, | |
| 264 // any values should be copied if needed. | |
| 265 virtual ConfigProperties* GetConfigProperties( | |
| 266 const dbus::ObjectPath& object_path) = 0; | |
| 267 | |
| 268 // Obtains the properties for the device with object path |object_path|, | |
| 269 // any values should be copied if needed. | |
| 270 virtual const DeviceProperties* GetDeviceProperties( | |
| 271 const dbus::ObjectPath& object_path) = 0; | |
| 272 | |
| 273 // Obtains the properties for the device with object path |object_path|, | |
| 274 // any values should be copied if needed. | |
| 275 virtual const ServiceProperties* GetServiceProperties( | |
| 276 const dbus::ObjectPath& object_path) = 0; | |
| 277 | |
| 278 protected: | |
| 279 // Create() should be used instead. | |
| 280 ApManagerClient(); | |
| 281 | |
| 282 private: | |
| 283 DISALLOW_COPY_AND_ASSIGN(ApManagerClient); | |
| 284 }; | |
| 285 | |
| 286 } // namespace chromeos | |
| 287 | |
| 288 #endif // CHROMEOS_DBUS_AP_MANAGER_CLIENT_H_ | |
| OLD | NEW |