diff options
author | Peter Qiu <zqiu@google.com> | 2015-10-13 13:21:58 -0700 |
---|---|---|
committer | Peter Qiu <zqiu@google.com> | 2015-10-13 16:42:48 -0700 |
commit | a522e0006b344c6438a18e0a4848e7cdfbf5dd0a (patch) | |
tree | 2389a42fe4637bff95321d1c016357f4211e4d08 | |
parent | 8d0c31bb481b712a3b2e6612390679e29053c620 (diff) | |
download | apmanager-a522e0006b344c6438a18e0a4848e7cdfbf5dd0a.tar.gz |
Provide an abstraction for control interface
Only define/implement APIs for creating proxies for now.
Bug: 24194427
TEST=Compile for both Android and Chrome OS
Change-Id: I55d387abd0104ab808343f244be5acaa8a4c8549
-rw-r--r-- | Android.mk | 1 | ||||
-rw-r--r-- | apmanager.gyp | 1 | ||||
-rw-r--r-- | control_interface.h | 45 | ||||
-rw-r--r-- | dbus_control.cc | 56 | ||||
-rw-r--r-- | dbus_control.h | 52 |
5 files changed, 155 insertions, 0 deletions
@@ -67,6 +67,7 @@ LOCAL_SRC_FILES := \ dbus_bindings/org.chromium.apmanager.Service.dbus-xml \ config.cc \ daemon.cc \ + dbus_control.cc \ device.cc \ device_info.cc \ dhcp_server.cc \ diff --git a/apmanager.gyp b/apmanager.gyp index 4367d17..23f4b24 100644 --- a/apmanager.gyp +++ b/apmanager.gyp @@ -75,6 +75,7 @@ 'sources': [ 'config.cc', 'daemon.cc', + 'dbus_control.cc', 'device.cc', 'device_info.cc', 'dhcp_server.cc', diff --git a/control_interface.h b/control_interface.h new file mode 100644 index 0000000..e5bbfd0 --- /dev/null +++ b/control_interface.h @@ -0,0 +1,45 @@ +// +// Copyright (C) 2015 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef APMANAGER_CONTROL_INTERFACE_H_ +#define APMANAGER_CONTROL_INTERFACE_H_ + +#include <base/callback.h> +#include <base/macros.h> + +#include "apmanager/firewall_proxy_interface.h" +#include "apmanager/shill_proxy_interface.h" + +namespace apmanager { + +// This is the Interface for an object factory that creates adaptor/proxy +// objects +class ControlInterface { + public: + virtual ~ControlInterface() {} + + // Proxy creation APIs. + virtual std::unique_ptr<FirewallProxyInterface> CreateFirewallProxy( + const base::Closure& service_appeared_callback, + const base::Closure& service_vanished_callback) = 0; + virtual std::unique_ptr<ShillProxyInterface> CreateShillProxy( + const base::Closure& service_appeared_callback, + const base::Closure& service_vanished_callback) = 0; +}; + +} // namespace apmanager + +#endif // APMANAGER_CONTROL_INTERFACE_H_ diff --git a/dbus_control.cc b/dbus_control.cc new file mode 100644 index 0000000..9cc227f --- /dev/null +++ b/dbus_control.cc @@ -0,0 +1,56 @@ +// +// Copyright (C) 2015 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include "apmanager/dbus_control.h" + +#include "apmanager/shill_dbus_proxy.h" + +#if !defined(__ANDROID__) +#include "apmanager/permission_broker_dbus_proxy.h" +#else +#include "apmanager/firewalld_dbus_proxy.h" +#endif //__ANDROID__ + +namespace apmanager { + +DBusControl::DBusControl(const scoped_refptr<dbus::Bus>& bus) + : bus_(bus) {} + +DBusControl::~DBusControl() {} + +std::unique_ptr<FirewallProxyInterface> DBusControl::CreateFirewallProxy( + const base::Closure& service_appeared_callback, + const base::Closure& service_vanished_callback) { +#if !defined(__ANDROID__) + return std::unique_ptr<FirewallProxyInterface>( + new PermissionBrokerDBusProxy( + bus_, service_appeared_callback, service_vanished_callback)); +#else + return std::unique_ptr<FirewallProxyInterface>( + new FirewalldDBusProxy( + bus_, service_appeared_callback, service_vanished_callback)); +#endif // __ANDROID__ +} + +std::unique_ptr<ShillProxyInterface> DBusControl::CreateShillProxy( + const base::Closure& service_appeared_callback, + const base::Closure& service_vanished_callback) { + return std::unique_ptr<ShillProxyInterface>( + new ShillDBusProxy( + bus_, service_appeared_callback, service_vanished_callback)); +} + +} // namespace apmanager diff --git a/dbus_control.h b/dbus_control.h new file mode 100644 index 0000000..6d59e42 --- /dev/null +++ b/dbus_control.h @@ -0,0 +1,52 @@ +// +// Copyright (C) 2015 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef APMANAGER_DBUS_CONTROL_H_ +#define APMANAGER_DBUS_CONTROL_H_ + +#include <base/macros.h> +#include <dbus/bus.h> + +#include "apmanager/control_interface.h" + +namespace apmanager { + +// D-Bus control interface for IPC through D-Bus. +class DBusControl : public ControlInterface { + public: + DBusControl(const scoped_refptr<dbus::Bus>& bus); + ~DBusControl() override; + + // Inheritted from ControlInterface. + std::unique_ptr<FirewallProxyInterface> CreateFirewallProxy( + const base::Closure& service_appeared_callback, + const base::Closure& service_vanished_callback) override; + std::unique_ptr<ShillProxyInterface> CreateShillProxy( + const base::Closure& service_appeared_callback, + const base::Closure& service_vanished_callback) override; + + private: + // NOTE: No dedicated bus is needed for the proxies, since the proxies + // being created here doesn't listen for any broadcast signals. + // Use a dedicated bus for the proxies if this condition is not true + // anymore. + scoped_refptr<dbus::Bus> bus_; + DISALLOW_COPY_AND_ASSIGN(DBusControl); +}; + +} // namespace apmanager + +#endif // APMANAGER_DBUS_CONTROL_H_ |