Peter Qiu | 326b6cf | 2015-09-02 11:11:42 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2014 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 16 | |
| 17 | #ifndef APMANAGER_MANAGER_H_ |
| 18 | #define APMANAGER_MANAGER_H_ |
| 19 | |
Peter Qiu | fd02b6f | 2015-02-27 09:55:11 -0800 | [diff] [blame] | 20 | #include <map> |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 21 | #include <string> |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame] | 22 | #include <vector> |
| 23 | |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 24 | #include <base/macros.h> |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame] | 25 | #include <brillo/dbus/dbus_service_watcher.h> |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 26 | |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 27 | #include "apmanager/device_info.h" |
Peter Qiu | 1810c01 | 2015-02-05 14:35:41 -0800 | [diff] [blame] | 28 | #include "apmanager/firewall_manager.h" |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame] | 29 | #include "apmanager/service.h" |
Peter Qiu | 2a6fb33 | 2015-09-17 22:19:17 -0700 | [diff] [blame] | 30 | #include "apmanager/shill_manager.h" |
Peter Qiu | 1ec4e7e | 2015-09-17 21:49:00 -0700 | [diff] [blame] | 31 | #include "dbus_bindings/org.chromium.apmanager.Manager.h" |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 32 | |
| 33 | namespace apmanager { |
| 34 | |
Peter Qiu | be12882 | 2015-10-13 13:55:03 -0700 | [diff] [blame] | 35 | class ControlInterface; |
| 36 | |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 37 | class Manager : public org::chromium::apmanager::ManagerAdaptor, |
| 38 | public org::chromium::apmanager::ManagerInterface { |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 39 | public: |
Alex Vakulenko | b56e3cd | 2015-04-24 18:09:32 -0700 | [diff] [blame] | 40 | template<typename T> |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame] | 41 | using DBusMethodResponse = brillo::dbus_utils::DBusMethodResponse<T>; |
Alex Vakulenko | b56e3cd | 2015-04-24 18:09:32 -0700 | [diff] [blame] | 42 | |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 43 | Manager(); |
| 44 | virtual ~Manager(); |
| 45 | |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 46 | // Implementation of ManagerInterface. |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame] | 47 | // Handles calls to org.chromium.apmanager.Manager.CreateService(). |
| 48 | // This is an asynchronous call, response is invoked when Service and Config |
| 49 | // dbus objects complete the DBus service registration. |
| 50 | virtual void CreateService( |
Alex Vakulenko | b56e3cd | 2015-04-24 18:09:32 -0700 | [diff] [blame] | 51 | std::unique_ptr<DBusMethodResponse<dbus::ObjectPath>> response, |
Peter Qiu | fd02b6f | 2015-02-27 09:55:11 -0800 | [diff] [blame] | 52 | dbus::Message* message); |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame] | 53 | // Handles calls to org.chromium.apmanager.Manager.RemoveService(). |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame] | 54 | virtual bool RemoveService(brillo::ErrorPtr* error, |
Peter Qiu | fd02b6f | 2015-02-27 09:55:11 -0800 | [diff] [blame] | 55 | dbus::Message* message, |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 56 | const dbus::ObjectPath& in_service); |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 57 | |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 58 | // Register DBus object. |
| 59 | void RegisterAsync( |
Peter Qiu | be12882 | 2015-10-13 13:55:03 -0700 | [diff] [blame] | 60 | ControlInterface* control_interface, |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame] | 61 | brillo::dbus_utils::ExportedObjectManager* object_manager, |
Peter Qiu | c9ce1f1 | 2014-12-05 11:14:29 -0800 | [diff] [blame] | 62 | const scoped_refptr<dbus::Bus>& bus, |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame] | 63 | brillo::dbus_utils::AsyncEventSequencer* sequencer); |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 64 | |
| 65 | virtual void Start(); |
| 66 | virtual void Stop(); |
| 67 | |
| 68 | virtual void RegisterDevice(scoped_refptr<Device> device); |
| 69 | |
Peter Qiu | 8e785b9 | 2014-11-24 10:01:08 -0800 | [diff] [blame] | 70 | // Return an unuse device with AP interface mode support. |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 71 | virtual scoped_refptr<Device> GetAvailableDevice(); |
Peter Qiu | 8e785b9 | 2014-11-24 10:01:08 -0800 | [diff] [blame] | 72 | |
| 73 | // Return the device that's associated with the given interface |
| 74 | // |interface_name|. |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 75 | virtual scoped_refptr<Device> GetDeviceFromInterfaceName( |
| 76 | const std::string& interface_name); |
| 77 | |
Peter Qiu | 7e0ffcf | 2014-12-02 12:53:27 -0800 | [diff] [blame] | 78 | // Claim the given interface |interface_name| from shill. |
| 79 | virtual void ClaimInterface(const std::string& interface_name); |
| 80 | // Release the given interface |interface_name| to shill. |
| 81 | virtual void ReleaseInterface(const std::string& interface_name); |
Peter Qiu | cbbefa2 | 2015-10-27 12:05:34 -0700 | [diff] [blame^] | 82 | #if defined(__BRILLO__) |
| 83 | // Setup an AP mode interface. Returns true and sets |interface_name| |
| 84 | // on success, false otherwise. |
| 85 | virtual bool SetupApModeInterface(std::string* interface_name); |
| 86 | // Setup a station mode interface. Returns true and sets |interface_name| |
| 87 | // on success, false otherwise. |
| 88 | virtual bool SetupStationModeInterface(std::string* interface_name); |
| 89 | #endif // __BRILLO__ |
Peter Qiu | 7e0ffcf | 2014-12-02 12:53:27 -0800 | [diff] [blame] | 90 | |
Peter Qiu | 943cf3a | 2015-02-24 10:59:17 -0800 | [diff] [blame] | 91 | // Request/release access to DHCP port for the specified interface. |
| 92 | virtual void RequestDHCPPortAccess(const std::string& interface); |
| 93 | virtual void ReleaseDHCPPortAccess(const std::string& interface); |
| 94 | |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 95 | private: |
| 96 | friend class ManagerTest; |
| 97 | |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame] | 98 | // A callback that will be called when the Service/Config D-Bus |
| 99 | // objects/interfaces are exported successfully and ready to be used. |
Peter Qiu | 1ff67a7 | 2014-11-22 07:06:10 -0800 | [diff] [blame] | 100 | void OnServiceRegistered( |
Alex Vakulenko | b56e3cd | 2015-04-24 18:09:32 -0700 | [diff] [blame] | 101 | std::unique_ptr<DBusMethodResponse<dbus::ObjectPath>> response, |
| 102 | std::unique_ptr<Service> service, |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame] | 103 | bool success); |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 104 | |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 105 | // A callback that will be called when a Device D-Bus object/interface is |
| 106 | // exported successfully and ready to be used. |
Peter Qiu | 1ff67a7 | 2014-11-22 07:06:10 -0800 | [diff] [blame] | 107 | void OnDeviceRegistered(scoped_refptr<Device> device, bool success); |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 108 | |
Peter Qiu | fd02b6f | 2015-02-27 09:55:11 -0800 | [diff] [blame] | 109 | // This is invoked when the owner of an AP service disappeared. |
| 110 | void OnAPServiceOwnerDisappeared(int service_identifier); |
| 111 | |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame] | 112 | int service_identifier_; |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 113 | int device_identifier_; |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame] | 114 | std::unique_ptr<brillo::dbus_utils::DBusObject> dbus_object_; |
Peter Qiu | c9ce1f1 | 2014-12-05 11:14:29 -0800 | [diff] [blame] | 115 | scoped_refptr<dbus::Bus> bus_; |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame] | 116 | std::vector<std::unique_ptr<Service>> services_; |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 117 | std::vector<scoped_refptr<Device>> devices_; |
Peter Qiu | fd02b6f | 2015-02-27 09:55:11 -0800 | [diff] [blame] | 118 | // DBus service watchers for the owner of AP services. |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame] | 119 | using DBusServiceWatcher = brillo::dbus_utils::DBusServiceWatcher; |
Peter Qiu | fd02b6f | 2015-02-27 09:55:11 -0800 | [diff] [blame] | 120 | std::map<int, std::unique_ptr<DBusServiceWatcher>> service_watchers_; |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 121 | DeviceInfo device_info_; |
| 122 | |
Peter Qiu | 2a6fb33 | 2015-09-17 22:19:17 -0700 | [diff] [blame] | 123 | // Manager for communicating with shill (connection manager). |
| 124 | ShillManager shill_manager_; |
| 125 | // Manager for communicating with remote firewall service. |
Peter Qiu | 1810c01 | 2015-02-05 14:35:41 -0800 | [diff] [blame] | 126 | FirewallManager firewall_manager_; |
Peter Qiu | 7e0ffcf | 2014-12-02 12:53:27 -0800 | [diff] [blame] | 127 | |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 128 | DISALLOW_COPY_AND_ASSIGN(Manager); |
| 129 | }; |
| 130 | |
| 131 | } // namespace apmanager |
| 132 | |
| 133 | #endif // APMANAGER_MANAGER_H_ |