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 | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 20 | #include <string> |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame] | 21 | #include <vector> |
| 22 | |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 23 | #include <base/macros.h> |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 24 | |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 25 | #include "apmanager/device_info.h" |
Peter Qiu | 1810c01 | 2015-02-05 14:35:41 -0800 | [diff] [blame] | 26 | #include "apmanager/firewall_manager.h" |
Peter Qiu | 7758d8d | 2015-11-23 14:27:33 -0800 | [diff] [blame] | 27 | #include "apmanager/manager_adaptor_interface.h" |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame] | 28 | #include "apmanager/service.h" |
Peter Qiu | 2a6fb33 | 2015-09-17 22:19:17 -0700 | [diff] [blame] | 29 | #include "apmanager/shill_manager.h" |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 30 | |
| 31 | namespace apmanager { |
| 32 | |
Peter Qiu | be12882 | 2015-10-13 13:55:03 -0700 | [diff] [blame] | 33 | class ControlInterface; |
| 34 | |
Peter Qiu | 7758d8d | 2015-11-23 14:27:33 -0800 | [diff] [blame] | 35 | class Manager { |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 36 | public: |
Peter Qiu | f933540 | 2015-11-16 12:09:16 -0800 | [diff] [blame] | 37 | explicit Manager(ControlInterface* control_interface); |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 38 | virtual ~Manager(); |
| 39 | |
Peter Qiu | 7758d8d | 2015-11-23 14:27:33 -0800 | [diff] [blame] | 40 | // Register this object to the RPC interface asynchronously. |
| 41 | void RegisterAsync(const base::Callback<void(bool)>& completion_callback); |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 42 | |
Peter Qiu | 7758d8d | 2015-11-23 14:27:33 -0800 | [diff] [blame] | 43 | // Create and return a new Service instance. The newly created instance |
| 44 | // will be added to the service list, it will only get deleted via |
| 45 | // RemoveService. |
| 46 | scoped_refptr<Service> CreateService(); |
| 47 | |
| 48 | // Remove |service| from the service list. Return true if service is found |
| 49 | // and deleted from the list, false otherwise. |error| will be populated |
| 50 | // on failure. |
| 51 | bool RemoveService(const scoped_refptr<Service>& service, Error* error); |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 52 | |
| 53 | virtual void Start(); |
| 54 | virtual void Stop(); |
| 55 | |
Peter Qiu | 7758d8d | 2015-11-23 14:27:33 -0800 | [diff] [blame] | 56 | virtual void RegisterDevice(const scoped_refptr<Device>& device); |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 57 | |
Peter Qiu | 8e785b9 | 2014-11-24 10:01:08 -0800 | [diff] [blame] | 58 | // Return an unuse device with AP interface mode support. |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 59 | virtual scoped_refptr<Device> GetAvailableDevice(); |
Peter Qiu | 8e785b9 | 2014-11-24 10:01:08 -0800 | [diff] [blame] | 60 | |
| 61 | // Return the device that's associated with the given interface |
| 62 | // |interface_name|. |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 63 | virtual scoped_refptr<Device> GetDeviceFromInterfaceName( |
| 64 | const std::string& interface_name); |
| 65 | |
Peter Qiu | 7e0ffcf | 2014-12-02 12:53:27 -0800 | [diff] [blame] | 66 | // Claim the given interface |interface_name| from shill. |
| 67 | virtual void ClaimInterface(const std::string& interface_name); |
| 68 | // Release the given interface |interface_name| to shill. |
| 69 | virtual void ReleaseInterface(const std::string& interface_name); |
Peter Qiu | cbbefa2 | 2015-10-27 12:05:34 -0700 | [diff] [blame] | 70 | #if defined(__BRILLO__) |
| 71 | // Setup an AP mode interface. Returns true and sets |interface_name| |
| 72 | // on success, false otherwise. |
| 73 | virtual bool SetupApModeInterface(std::string* interface_name); |
| 74 | // Setup a station mode interface. Returns true and sets |interface_name| |
| 75 | // on success, false otherwise. |
| 76 | virtual bool SetupStationModeInterface(std::string* interface_name); |
| 77 | #endif // __BRILLO__ |
Peter Qiu | 7e0ffcf | 2014-12-02 12:53:27 -0800 | [diff] [blame] | 78 | |
Peter Qiu | 943cf3a | 2015-02-24 10:59:17 -0800 | [diff] [blame] | 79 | // Request/release access to DHCP port for the specified interface. |
| 80 | virtual void RequestDHCPPortAccess(const std::string& interface); |
| 81 | virtual void ReleaseDHCPPortAccess(const std::string& interface); |
| 82 | |
Peter Qiu | f933540 | 2015-11-16 12:09:16 -0800 | [diff] [blame] | 83 | ControlInterface* control_interface() const { return control_interface_; } |
| 84 | |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 85 | private: |
| 86 | friend class ManagerTest; |
| 87 | |
Peter Qiu | f933540 | 2015-11-16 12:09:16 -0800 | [diff] [blame] | 88 | ControlInterface* control_interface_; |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame] | 89 | int service_identifier_; |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 90 | std::vector<scoped_refptr<Device>> devices_; |
| 91 | DeviceInfo device_info_; |
| 92 | |
Peter Qiu | 2a6fb33 | 2015-09-17 22:19:17 -0700 | [diff] [blame] | 93 | // Manager for communicating with shill (connection manager). |
| 94 | ShillManager shill_manager_; |
| 95 | // Manager for communicating with remote firewall service. |
Peter Qiu | 1810c01 | 2015-02-05 14:35:41 -0800 | [diff] [blame] | 96 | FirewallManager firewall_manager_; |
Peter Qiu | 7e0ffcf | 2014-12-02 12:53:27 -0800 | [diff] [blame] | 97 | |
Peter Qiu | 7758d8d | 2015-11-23 14:27:33 -0800 | [diff] [blame] | 98 | // Put the service list after ShillManager and FirewallManager, since both |
| 99 | // are needed for tearing down an active/running Service. |
| 100 | std::vector<scoped_refptr<Service>> services_; |
| 101 | |
| 102 | std::unique_ptr<ManagerAdaptorInterface> adaptor_; |
| 103 | |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 104 | DISALLOW_COPY_AND_ASSIGN(Manager); |
| 105 | }; |
| 106 | |
| 107 | } // namespace apmanager |
| 108 | |
| 109 | #endif // APMANAGER_MANAGER_H_ |