Home | History | Annotate | Download | only in apmanager
      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 //
     16 
     17 #ifndef APMANAGER_MANAGER_H_
     18 #define APMANAGER_MANAGER_H_
     19 
     20 #include <string>
     21 #include <vector>
     22 
     23 #include <base/macros.h>
     24 
     25 #include "apmanager/device_info.h"
     26 #include "apmanager/firewall_manager.h"
     27 #include "apmanager/manager_adaptor_interface.h"
     28 #include "apmanager/service.h"
     29 #include "apmanager/shill_manager.h"
     30 
     31 namespace apmanager {
     32 
     33 class ControlInterface;
     34 
     35 class Manager {
     36  public:
     37   explicit Manager(ControlInterface* control_interface);
     38   virtual ~Manager();
     39 
     40   // Register this object to the RPC interface asynchronously.
     41   void RegisterAsync(const base::Callback<void(bool)>& completion_callback);
     42 
     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);
     52 
     53   virtual void Start();
     54   virtual void Stop();
     55 
     56   virtual void RegisterDevice(const scoped_refptr<Device>& device);
     57 
     58   // Return an unuse device with AP interface mode support.
     59   virtual scoped_refptr<Device> GetAvailableDevice();
     60 
     61   // Return the device that's associated with the given interface
     62   // |interface_name|.
     63   virtual scoped_refptr<Device> GetDeviceFromInterfaceName(
     64       const std::string& interface_name);
     65 
     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);
     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__
     78 
     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 
     83   ControlInterface* control_interface() const { return control_interface_; }
     84 
     85  private:
     86   friend class ManagerTest;
     87 
     88   ControlInterface* control_interface_;
     89   int service_identifier_;
     90   std::vector<scoped_refptr<Device>> devices_;
     91   DeviceInfo device_info_;
     92 
     93   // Manager for communicating with shill (connection manager).
     94   ShillManager shill_manager_;
     95   // Manager for communicating with remote firewall service.
     96   FirewallManager firewall_manager_;
     97 
     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 
    104   DISALLOW_COPY_AND_ASSIGN(Manager);
    105 };
    106 
    107 }  // namespace apmanager
    108 
    109 #endif  // APMANAGER_MANAGER_H_
    110