1 //
2 // Copyright (C) 2016 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 SHILL_BINDER_BINDER_CONTROL_H_
18 #define SHILL_BINDER_BINDER_CONTROL_H_
19 
20 #include <map>
21 #include <string>
22 
23 #include <binder/IBinder.h>
24 #include <utils/StrongPointer.h>
25 
26 #include "shill/control_interface.h"
27 
28 namespace shill {
29 
30 class EventDispatcher;
31 class Manager;
32 
33 class BinderControl : public ControlInterface {
34  public:
35   BinderControl(EventDispatcher* dispatcher);
36   ~BinderControl() override;
37 
38   void RegisterManagerObject(
39       Manager* manager,
40       const base::Closure& registration_done_callback) override;
41   DeviceAdaptorInterface* CreateDeviceAdaptor(Device* device) override;
42   IPConfigAdaptorInterface* CreateIPConfigAdaptor(IPConfig* ipconfig) override;
43   ManagerAdaptorInterface* CreateManagerAdaptor(Manager* manager) override;
44   ProfileAdaptorInterface* CreateProfileAdaptor(Profile* profile) override;
45   RPCTaskAdaptorInterface* CreateRPCTaskAdaptor(RPCTask* task) override;
46   ServiceAdaptorInterface* CreateServiceAdaptor(Service* service) override;
47 
48   const std::string& NullRPCIdentifier() override;
49 
50   // The caller retains ownership of 'delegate'.  It must not be deleted before
51   // the proxy.
52   PowerManagerProxyInterface* CreatePowerManagerProxy(
53       PowerManagerProxyDelegate* delegate,
54       const base::Closure& service_appeared_callback,
55       const base::Closure& service_vanished_callback) override;
56 
57 #if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X)
58   SupplicantProcessProxyInterface* CreateSupplicantProcessProxy(
59       const base::Closure& service_appeared_callback,
60       const base::Closure& service_vanished_callback) override;
61 
62   SupplicantInterfaceProxyInterface* CreateSupplicantInterfaceProxy(
63       SupplicantEventDelegateInterface* delegate,
64       const std::string& object_path) override;
65 
66   SupplicantNetworkProxyInterface* CreateSupplicantNetworkProxy(
67       const std::string& object_path) override;
68 #endif  // DISABLE_WIFI || DISABLE_WIRED_8021X
69 
70 #if !defined(DISABLE_WIFI)
71   // See comment in supplicant_bss_proxy.h, about bare pointer.
72   SupplicantBSSProxyInterface* CreateSupplicantBSSProxy(
73       WiFiEndpoint* wifi_endpoint, const std::string& object_path) override;
74 #endif  // DISABLE_WIFI
75 
76   UpstartProxyInterface* CreateUpstartProxy() override;
77 
78   DHCPCDListenerInterface* CreateDHCPCDListener(
79       DHCPProvider* provider) override;
80 
81   DHCPProxyInterface* CreateDHCPProxy(const std::string& service) override;
82 
83   FirewallProxyInterface* CreateFirewallProxy() override;
84 
85  private:
86   static const char kNullRpcIdentifier[];
87 
88   template <typename Object, typename AdaptorInterface, typename Adaptor>
89   AdaptorInterface* CreateAdaptor(Object* object);
90 
91   // This counter is used to assign unique IDs to binder adaptors. The string
92   // representation of this integer will assigned to as a unique ID to the next
93   // binder adaptor created. This unique ID will then be used as the Binder
94   // adaptor's RPC identifier.
95   uint32_t next_unique_binder_adaptor_id_;
96   std::map<std::string, android::sp<android::IBinder>> rpc_id_to_binder_map_;
97   EventDispatcher* dispatcher_;
98   std::string null_identifier_;
99 
100   // TODO(samueltan): remove when shill is no longer dependent on DBus proxies.
101   scoped_refptr<dbus::Bus> proxy_bus_;
102 };
103 
104 }  // namespace shill
105 
106 #endif  // SHILL_BINDER_BINDER_CONTROL_H_
107