diff options
author | Peter Qiu <zqiu@google.com> | 2015-11-21 17:47:49 -0800 |
---|---|---|
committer | Peter Qiu <zqiu@google.com> | 2015-11-21 21:30:54 -0800 |
commit | 685dd4acea083dc74105edbdf8a06e539c291a45 (patch) | |
tree | b13567f9dc82e9396b3be615fe8d62984ae67ee7 | |
parent | 2ea547f45d2a143e1b25b275c46d1f317186b07a (diff) | |
download | apmanager-685dd4acea083dc74105edbdf8a06e539c291a45.tar.gz |
Provide abstraction for ManagerAdaptorInterface
D-Bus implementation of the interface is also included.
Bug: 24194427
TEST=Build apmanager for both Brillo and Chrome OS
Change-Id: Id2478673cbca36279fb9e5e87a203a4eb021d1db
-rw-r--r-- | Android.mk | 1 | ||||
-rw-r--r-- | apmanager.gyp | 1 | ||||
-rw-r--r-- | control_interface.h | 4 | ||||
-rw-r--r-- | dbus/dbus_control.cc | 7 | ||||
-rw-r--r-- | dbus/dbus_control.h | 2 | ||||
-rw-r--r-- | dbus/manager_dbus_adaptor.cc | 63 | ||||
-rw-r--r-- | dbus/manager_dbus_adaptor.h | 59 | ||||
-rw-r--r-- | manager_adaptor_interface.h | 34 | ||||
-rw-r--r-- | mock_control.cc | 5 | ||||
-rw-r--r-- | mock_control.h | 3 |
10 files changed, 179 insertions, 0 deletions
@@ -71,6 +71,7 @@ LOCAL_SRC_FILES := \ dbus/dbus_control.cc \ dbus/device_dbus_adaptor.cc \ dbus/firewalld_dbus_proxy.cc \ + dbus/manager_dbus_adaptor.cc \ dbus/service_dbus_adaptor.cc \ dbus/shill_dbus_proxy.cc \ device.cc \ diff --git a/apmanager.gyp b/apmanager.gyp index a261984..b492133 100644 --- a/apmanager.gyp +++ b/apmanager.gyp @@ -78,6 +78,7 @@ 'dbus/config_dbus_adaptor.cc', 'dbus/dbus_control.cc', 'dbus/device_dbus_adaptor.cc', + 'dbus/manager_dbus_adaptor.cc', 'dbus/permission_broker_dbus_proxy.cc', 'dbus/service_dbus_adaptor.cc', 'dbus/shill_dbus_proxy.cc', diff --git a/control_interface.h b/control_interface.h index 15f547c..e1f6f1b 100644 --- a/control_interface.h +++ b/control_interface.h @@ -23,6 +23,7 @@ #include "apmanager/config_adaptor_interface.h" #include "apmanager/device_adaptor_interface.h" #include "apmanager/firewall_proxy_interface.h" +#include "apmanager/manager_adaptor_interface.h" #include "apmanager/service_adaptor_interface.h" #include "apmanager/shill_proxy_interface.h" @@ -30,6 +31,7 @@ namespace apmanager { class Config; class Device; +class Manager; class Service; // This is the Interface for an object factory that creates adaptor/proxy @@ -46,6 +48,8 @@ class ControlInterface { Config* config, int service_identifier) = 0; virtual std::unique_ptr<DeviceAdaptorInterface> CreateDeviceAdaptor( Device* device) = 0; + virtual std::unique_ptr<ManagerAdaptorInterface> CreateManagerAdaptor( + Manager* manager) = 0; virtual std::unique_ptr<ServiceAdaptorInterface> CreateServiceAdaptor( Service* service) = 0; diff --git a/dbus/dbus_control.cc b/dbus/dbus_control.cc index 54722e7..d682fb8 100644 --- a/dbus/dbus_control.cc +++ b/dbus/dbus_control.cc @@ -18,6 +18,7 @@ #include "apmanager/dbus/config_dbus_adaptor.h" #include "apmanager/dbus/device_dbus_adaptor.h" +#include "apmanager/dbus/manager_dbus_adaptor.h" #include "apmanager/dbus/service_dbus_adaptor.h" #include "apmanager/dbus/shill_dbus_proxy.h" #include "apmanager/manager.h" @@ -102,6 +103,12 @@ std::unique_ptr<DeviceAdaptorInterface> DBusControl::CreateDeviceAdaptor( new DeviceDBusAdaptor(bus_, object_manager_.get(), device)); } +std::unique_ptr<ManagerAdaptorInterface> DBusControl::CreateManagerAdaptor( + Manager* manager) { + return std::unique_ptr<ManagerAdaptorInterface>( + new ManagerDBusAdaptor(bus_, object_manager_.get(), manager)); +} + std::unique_ptr<ServiceAdaptorInterface> DBusControl::CreateServiceAdaptor( Service* service) { return std::unique_ptr<ServiceAdaptorInterface>( diff --git a/dbus/dbus_control.h b/dbus/dbus_control.h index 565ed11..c12dbfa 100644 --- a/dbus/dbus_control.h +++ b/dbus/dbus_control.h @@ -39,6 +39,8 @@ class DBusControl : public ControlInterface { Config* config, int service_identifier) override; std::unique_ptr<DeviceAdaptorInterface> CreateDeviceAdaptor( Device* device) override; + std::unique_ptr<ManagerAdaptorInterface> CreateManagerAdaptor( + Manager* manager) override; std::unique_ptr<ServiceAdaptorInterface> CreateServiceAdaptor( Service* device) override; std::unique_ptr<FirewallProxyInterface> CreateFirewallProxy( diff --git a/dbus/manager_dbus_adaptor.cc b/dbus/manager_dbus_adaptor.cc new file mode 100644 index 0000000..a205cea --- /dev/null +++ b/dbus/manager_dbus_adaptor.cc @@ -0,0 +1,63 @@ +// +// 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/manager_dbus_adaptor.h" + +#if !defined(__ANDROID__) +#include <chromeos/dbus/service_constants.h> +#else +#include <dbus/apmanager/dbus-constants.h> +#endif // __ANDROID__ + +#include "apmanager/manager.h" + +using brillo::dbus_utils::ExportedObjectManager; +using org::chromium::apmanager::ManagerAdaptor; +using std::string; + +namespace apmanager { + +ManagerDBusAdaptor::ManagerDBusAdaptor( + const scoped_refptr<dbus::Bus>& bus, + ExportedObjectManager* object_manager, + Manager* manager) + : adaptor_(this), + dbus_object_(object_manager, bus, ManagerAdaptor::GetObjectPath()), + manager_(manager) {} + +ManagerDBusAdaptor::~ManagerDBusAdaptor() {} + +void ManagerDBusAdaptor::RegisterAsync( + const base::Callback<void(bool)>& completion_callback) { + adaptor_.RegisterWithDBusObject(&dbus_object_); + dbus_object_.RegisterAsync(completion_callback); +} + +bool ManagerDBusAdaptor::CreateService(brillo::ErrorPtr* error, + dbus::Message* message, + dbus::ObjectPath* out_service) { + // TODO(zqiu): to be implemented. + return true; +} + +bool ManagerDBusAdaptor::RemoveService(brillo::ErrorPtr* error, + dbus::Message* message, + const dbus::ObjectPath& in_service) { + // TODO(zqiu): to be implemented. + return true; +} + +} // namespace apmanager diff --git a/dbus/manager_dbus_adaptor.h b/dbus/manager_dbus_adaptor.h new file mode 100644 index 0000000..1a2f4cd --- /dev/null +++ b/dbus/manager_dbus_adaptor.h @@ -0,0 +1,59 @@ +// +// 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_MANAGER_DBUS_ADAPTOR_H_ +#define APMANAGER_DBUS_MANAGER_DBUS_ADAPTOR_H_ + +#include <base/macros.h> +#include <dbus_bindings/org.chromium.apmanager.Manager.h> + +#include "apmanager/manager_adaptor_interface.h" + +namespace apmanager { + +class Manager; + +class ManagerDBusAdaptor : public org::chromium::apmanager::ManagerInterface, + public ManagerAdaptorInterface { + public: + ManagerDBusAdaptor(const scoped_refptr<dbus::Bus>& bus, + brillo::dbus_utils::ExportedObjectManager* object_manager, + Manager* manager); + ~ManagerDBusAdaptor() override; + + // Implementation of org::chromium::apmanager::ManagerInterface. + bool CreateService(brillo::ErrorPtr* error, + dbus::Message* message, + dbus::ObjectPath* out_service) override; + bool RemoveService(brillo::ErrorPtr* error, + dbus::Message* message, + const dbus::ObjectPath& in_service) override; + + // Implementation of ManagerAdaptorInterface. + void RegisterAsync( + const base::Callback<void(bool)>& completion_callback) override; + + private: + org::chromium::apmanager::ManagerAdaptor adaptor_; + brillo::dbus_utils::DBusObject dbus_object_; + Manager* manager_; + + DISALLOW_COPY_AND_ASSIGN(ManagerDBusAdaptor); +}; + +} // namespace apmanager + +#endif // APMANAGER_DBUS_MANAGER_DBUS_ADAPTOR_H_ diff --git a/manager_adaptor_interface.h b/manager_adaptor_interface.h new file mode 100644 index 0000000..00826e0 --- /dev/null +++ b/manager_adaptor_interface.h @@ -0,0 +1,34 @@ +// +// Copyright 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_MANAGER_ADAPTOR_INTERFACE_H_ +#define APMANAGER_MANAGER_ADAPTOR_INTERFACE_H_ + +#include <base/callback.h> + +namespace apmanager { + +class ManagerAdaptorInterface { + public: + virtual ~ManagerAdaptorInterface() {} + + virtual void RegisterAsync( + const base::Callback<void(bool)>& completion_callback) = 0; +}; + +} // namespace apmanager + +#endif // APMANAGER_MANAGER_ADAPTOR_INTERFACE_H_ diff --git a/mock_control.cc b/mock_control.cc index 2ce18f8..6b9f32e 100644 --- a/mock_control.cc +++ b/mock_control.cc @@ -32,6 +32,11 @@ std::unique_ptr<DeviceAdaptorInterface> MockControl::CreateDeviceAdaptor( return std::unique_ptr<DeviceAdaptorInterface>(CreateDeviceAdaptorRaw()); } +std::unique_ptr<ManagerAdaptorInterface> MockControl::CreateManagerAdaptor( + Manager* /* manager */) { + return std::unique_ptr<ManagerAdaptorInterface>(CreateManagerAdaptorRaw()); +} + std::unique_ptr<ServiceAdaptorInterface> MockControl::CreateServiceAdaptor( Service* /* service */) { return std::unique_ptr<ServiceAdaptorInterface>(CreateServiceAdaptorRaw()); diff --git a/mock_control.h b/mock_control.h index 4009c78..d428064 100644 --- a/mock_control.h +++ b/mock_control.h @@ -39,6 +39,7 @@ class MockControl : public ControlInterface { MOCK_METHOD0(CreateConfigAdaptorRaw, ConfigAdaptorInterface*()); MOCK_METHOD0(CreateDeviceAdaptorRaw, DeviceAdaptorInterface*()); MOCK_METHOD0(CreateFirewallProxyRaw, FirewallProxyInterface*()); + MOCK_METHOD0(CreateManagerAdaptorRaw, ManagerAdaptorInterface*()); MOCK_METHOD0(CreateServiceAdaptorRaw, ServiceAdaptorInterface*()); MOCK_METHOD0(CreateShillProxyRaw, ShillProxyInterface*()); @@ -48,6 +49,8 @@ class MockControl : public ControlInterface { Config* config, int service_identifier) override; std::unique_ptr<DeviceAdaptorInterface> CreateDeviceAdaptor( Device* device) override; + std::unique_ptr<ManagerAdaptorInterface> CreateManagerAdaptor( + Manager* manager) override; std::unique_ptr<ServiceAdaptorInterface> CreateServiceAdaptor( Service* service) override; std::unique_ptr<FirewallProxyInterface> CreateFirewallProxy( |