blob: c30e60b92603bc64a7f9114333fe480a6ee983fa [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 Qiufd02b6f2015-02-27 09:55:11 -080020#include <map>
Peter Qiufb39ba42014-11-21 09:09:59 -080021#include <string>
Peter Qiu376e4042014-11-13 09:40:28 -080022#include <vector>
23
Peter Qiu5dd242d2014-10-14 12:23:21 -070024#include <base/macros.h>
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -070025#include <brillo/dbus/dbus_service_watcher.h>
Peter Qiu5dd242d2014-10-14 12:23:21 -070026
Peter Qiufb39ba42014-11-21 09:09:59 -080027#include "apmanager/device_info.h"
Peter Qiu1810c012015-02-05 14:35:41 -080028#include "apmanager/firewall_manager.h"
Peter Qiu376e4042014-11-13 09:40:28 -080029#include "apmanager/service.h"
Peter Qiu2a6fb332015-09-17 22:19:17 -070030#include "apmanager/shill_manager.h"
Peter Qiu1ec4e7e2015-09-17 21:49:00 -070031#include "dbus_bindings/org.chromium.apmanager.Manager.h"
Peter Qiu5dd242d2014-10-14 12:23:21 -070032
33namespace apmanager {
34
Peter Qiube128822015-10-13 13:55:03 -070035class ControlInterface;
36
Peter Qiuf0731732014-11-11 09:46:41 -080037class Manager : public org::chromium::apmanager::ManagerAdaptor,
38 public org::chromium::apmanager::ManagerInterface {
Peter Qiu5dd242d2014-10-14 12:23:21 -070039 public:
Alex Vakulenkob56e3cd2015-04-24 18:09:32 -070040 template<typename T>
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -070041 using DBusMethodResponse = brillo::dbus_utils::DBusMethodResponse<T>;
Alex Vakulenkob56e3cd2015-04-24 18:09:32 -070042
Peter Qiu5dd242d2014-10-14 12:23:21 -070043 Manager();
44 virtual ~Manager();
45
Peter Qiuf0731732014-11-11 09:46:41 -080046 // Implementation of ManagerInterface.
Peter Qiu376e4042014-11-13 09:40:28 -080047 // 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 Vakulenkob56e3cd2015-04-24 18:09:32 -070051 std::unique_ptr<DBusMethodResponse<dbus::ObjectPath>> response,
Peter Qiufd02b6f2015-02-27 09:55:11 -080052 dbus::Message* message);
Peter Qiu376e4042014-11-13 09:40:28 -080053 // Handles calls to org.chromium.apmanager.Manager.RemoveService().
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -070054 virtual bool RemoveService(brillo::ErrorPtr* error,
Peter Qiufd02b6f2015-02-27 09:55:11 -080055 dbus::Message* message,
Peter Qiuf0731732014-11-11 09:46:41 -080056 const dbus::ObjectPath& in_service);
Peter Qiu5dd242d2014-10-14 12:23:21 -070057
Peter Qiufb39ba42014-11-21 09:09:59 -080058 // Register DBus object.
59 void RegisterAsync(
Peter Qiube128822015-10-13 13:55:03 -070060 ControlInterface* control_interface,
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -070061 brillo::dbus_utils::ExportedObjectManager* object_manager,
Peter Qiuc9ce1f12014-12-05 11:14:29 -080062 const scoped_refptr<dbus::Bus>& bus,
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -070063 brillo::dbus_utils::AsyncEventSequencer* sequencer);
Peter Qiufb39ba42014-11-21 09:09:59 -080064
65 virtual void Start();
66 virtual void Stop();
67
68 virtual void RegisterDevice(scoped_refptr<Device> device);
69
Peter Qiu8e785b92014-11-24 10:01:08 -080070 // Return an unuse device with AP interface mode support.
Peter Qiufb39ba42014-11-21 09:09:59 -080071 virtual scoped_refptr<Device> GetAvailableDevice();
Peter Qiu8e785b92014-11-24 10:01:08 -080072
73 // Return the device that's associated with the given interface
74 // |interface_name|.
Peter Qiufb39ba42014-11-21 09:09:59 -080075 virtual scoped_refptr<Device> GetDeviceFromInterfaceName(
76 const std::string& interface_name);
77
Peter Qiu7e0ffcf2014-12-02 12:53:27 -080078 // 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 Qiucbbefa22015-10-27 12:05:34 -070082#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 Qiu7e0ffcf2014-12-02 12:53:27 -080090
Peter Qiu943cf3a2015-02-24 10:59:17 -080091 // 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 Qiu5dd242d2014-10-14 12:23:21 -070095 private:
96 friend class ManagerTest;
97
Peter Qiu376e4042014-11-13 09:40:28 -080098 // A callback that will be called when the Service/Config D-Bus
99 // objects/interfaces are exported successfully and ready to be used.
Peter Qiu1ff67a72014-11-22 07:06:10 -0800100 void OnServiceRegistered(
Alex Vakulenkob56e3cd2015-04-24 18:09:32 -0700101 std::unique_ptr<DBusMethodResponse<dbus::ObjectPath>> response,
102 std::unique_ptr<Service> service,
Peter Qiu376e4042014-11-13 09:40:28 -0800103 bool success);
Peter Qiu5dd242d2014-10-14 12:23:21 -0700104
Peter Qiufb39ba42014-11-21 09:09:59 -0800105 // A callback that will be called when a Device D-Bus object/interface is
106 // exported successfully and ready to be used.
Peter Qiu1ff67a72014-11-22 07:06:10 -0800107 void OnDeviceRegistered(scoped_refptr<Device> device, bool success);
Peter Qiufb39ba42014-11-21 09:09:59 -0800108
Peter Qiufd02b6f2015-02-27 09:55:11 -0800109 // This is invoked when the owner of an AP service disappeared.
110 void OnAPServiceOwnerDisappeared(int service_identifier);
111
Peter Qiu376e4042014-11-13 09:40:28 -0800112 int service_identifier_;
Peter Qiufb39ba42014-11-21 09:09:59 -0800113 int device_identifier_;
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700114 std::unique_ptr<brillo::dbus_utils::DBusObject> dbus_object_;
Peter Qiuc9ce1f12014-12-05 11:14:29 -0800115 scoped_refptr<dbus::Bus> bus_;
Peter Qiu376e4042014-11-13 09:40:28 -0800116 std::vector<std::unique_ptr<Service>> services_;
Peter Qiufb39ba42014-11-21 09:09:59 -0800117 std::vector<scoped_refptr<Device>> devices_;
Peter Qiufd02b6f2015-02-27 09:55:11 -0800118 // DBus service watchers for the owner of AP services.
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700119 using DBusServiceWatcher = brillo::dbus_utils::DBusServiceWatcher;
Peter Qiufd02b6f2015-02-27 09:55:11 -0800120 std::map<int, std::unique_ptr<DBusServiceWatcher>> service_watchers_;
Peter Qiufb39ba42014-11-21 09:09:59 -0800121 DeviceInfo device_info_;
122
Peter Qiu2a6fb332015-09-17 22:19:17 -0700123 // Manager for communicating with shill (connection manager).
124 ShillManager shill_manager_;
125 // Manager for communicating with remote firewall service.
Peter Qiu1810c012015-02-05 14:35:41 -0800126 FirewallManager firewall_manager_;
Peter Qiu7e0ffcf2014-12-02 12:53:27 -0800127
Peter Qiu5dd242d2014-10-14 12:23:21 -0700128 DISALLOW_COPY_AND_ASSIGN(Manager);
129};
130
131} // namespace apmanager
132
133#endif // APMANAGER_MANAGER_H_