blob: 578a1db0a9c17f448285725519f12b694cbe3f70 [file] [log] [blame]
Peter Qiu326b6cf2015-09-02 11:11:42 -07001//
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 Qiu5dd242d2014-10-14 12:23:21 -070016
17#ifndef APMANAGER_MANAGER_H_
18#define APMANAGER_MANAGER_H_
19
Peter Qiufb39ba42014-11-21 09:09:59 -080020#include <string>
Peter Qiu376e4042014-11-13 09:40:28 -080021#include <vector>
22
Peter Qiu5dd242d2014-10-14 12:23:21 -070023#include <base/macros.h>
Peter Qiu5dd242d2014-10-14 12:23:21 -070024
Peter Qiufb39ba42014-11-21 09:09:59 -080025#include "apmanager/device_info.h"
Peter Qiu1810c012015-02-05 14:35:41 -080026#include "apmanager/firewall_manager.h"
Peter Qiu7758d8d2015-11-23 14:27:33 -080027#include "apmanager/manager_adaptor_interface.h"
Peter Qiu376e4042014-11-13 09:40:28 -080028#include "apmanager/service.h"
Peter Qiu2a6fb332015-09-17 22:19:17 -070029#include "apmanager/shill_manager.h"
Peter Qiu5dd242d2014-10-14 12:23:21 -070030
31namespace apmanager {
32
Peter Qiube128822015-10-13 13:55:03 -070033class ControlInterface;
34
Peter Qiu7758d8d2015-11-23 14:27:33 -080035class Manager {
Peter Qiu5dd242d2014-10-14 12:23:21 -070036 public:
Peter Qiuf9335402015-11-16 12:09:16 -080037 explicit Manager(ControlInterface* control_interface);
Peter Qiu5dd242d2014-10-14 12:23:21 -070038 virtual ~Manager();
39
Peter Qiu7758d8d2015-11-23 14:27:33 -080040 // Register this object to the RPC interface asynchronously.
41 void RegisterAsync(const base::Callback<void(bool)>& completion_callback);
Peter Qiu5dd242d2014-10-14 12:23:21 -070042
Peter Qiu7758d8d2015-11-23 14:27:33 -080043 // 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 Qiufb39ba42014-11-21 09:09:59 -080052
53 virtual void Start();
54 virtual void Stop();
55
Peter Qiu7758d8d2015-11-23 14:27:33 -080056 virtual void RegisterDevice(const scoped_refptr<Device>& device);
Peter Qiufb39ba42014-11-21 09:09:59 -080057
Peter Qiu8e785b92014-11-24 10:01:08 -080058 // Return an unuse device with AP interface mode support.
Peter Qiufb39ba42014-11-21 09:09:59 -080059 virtual scoped_refptr<Device> GetAvailableDevice();
Peter Qiu8e785b92014-11-24 10:01:08 -080060
61 // Return the device that's associated with the given interface
62 // |interface_name|.
Peter Qiufb39ba42014-11-21 09:09:59 -080063 virtual scoped_refptr<Device> GetDeviceFromInterfaceName(
64 const std::string& interface_name);
65
Peter Qiu7e0ffcf2014-12-02 12:53:27 -080066 // 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 Qiucbbefa22015-10-27 12:05:34 -070070#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 Qiu7e0ffcf2014-12-02 12:53:27 -080078
Peter Qiu943cf3a2015-02-24 10:59:17 -080079 // 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 Qiuf9335402015-11-16 12:09:16 -080083 ControlInterface* control_interface() const { return control_interface_; }
84
Peter Qiu5dd242d2014-10-14 12:23:21 -070085 private:
86 friend class ManagerTest;
87
Peter Qiuf9335402015-11-16 12:09:16 -080088 ControlInterface* control_interface_;
Peter Qiu376e4042014-11-13 09:40:28 -080089 int service_identifier_;
Peter Qiufb39ba42014-11-21 09:09:59 -080090 std::vector<scoped_refptr<Device>> devices_;
91 DeviceInfo device_info_;
92
Peter Qiu2a6fb332015-09-17 22:19:17 -070093 // Manager for communicating with shill (connection manager).
94 ShillManager shill_manager_;
95 // Manager for communicating with remote firewall service.
Peter Qiu1810c012015-02-05 14:35:41 -080096 FirewallManager firewall_manager_;
Peter Qiu7e0ffcf2014-12-02 12:53:27 -080097
Peter Qiu7758d8d2015-11-23 14:27:33 -080098 // 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 Qiu5dd242d2014-10-14 12:23:21 -0700104 DISALLOW_COPY_AND_ASSIGN(Manager);
105};
106
107} // namespace apmanager
108
109#endif // APMANAGER_MANAGER_H_