diff options
author | Peter Qiu <zqiu@google.com> | 2015-11-20 10:11:36 -0800 |
---|---|---|
committer | Peter Qiu <zqiu@google.com> | 2015-11-21 21:30:54 -0800 |
commit | 0e92d1ea02ff4aec2a3c333dd2258d81c1211ace (patch) | |
tree | c4eee04d1751d6e281ff19c48407fbd7a5e923f0 | |
parent | d9c79aa078a5df1882848d26a52d48a02b4057a5 (diff) | |
download | apmanager-0e92d1ea02ff4aec2a3c333dd2258d81c1211ace.tar.gz |
Define and implement an AdaptorInterface for Service
This interface will be used by Service to communicate with
the adaptor that exposes its functionality over IPC.
The D-Bus implementation of this interface is included, and
integrated to the D-Bus control interface.
Bug: 24194427
TEST=Build apmanager for both Brillo and Chrome OS
Change-Id: Ib87e13247cb4fbff53081b2e5cbad61bb499ce31
-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/service_dbus_adaptor.cc | 72 | ||||
-rw-r--r-- | dbus/service_dbus_adaptor.h | 60 | ||||
-rw-r--r-- | mock_control.cc | 5 | ||||
-rw-r--r-- | mock_control.h | 3 | ||||
-rw-r--r-- | service_adaptor_interface.h | 39 |
10 files changed, 194 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/service_dbus_adaptor.cc \ dbus/shill_dbus_proxy.cc \ device.cc \ device_info.cc \ diff --git a/apmanager.gyp b/apmanager.gyp index 05ed279..b5f8de5 100644 --- a/apmanager.gyp +++ b/apmanager.gyp @@ -79,6 +79,7 @@ 'dbus/dbus_control.cc', 'dbus/device_dbus_adaptor.cc', 'dbus/permission_broker_dbus_proxy.cc', + 'dbus/service_dbus_adaptor.cc', 'dbus/shill_dbus_proxy.cc', 'device.cc', 'device_info.cc', diff --git a/control_interface.h b/control_interface.h index 4d4daf5..15f547c 100644 --- a/control_interface.h +++ b/control_interface.h @@ -23,12 +23,14 @@ #include "apmanager/config_adaptor_interface.h" #include "apmanager/device_adaptor_interface.h" #include "apmanager/firewall_proxy_interface.h" +#include "apmanager/service_adaptor_interface.h" #include "apmanager/shill_proxy_interface.h" namespace apmanager { class Config; class Device; +class Service; // This is the Interface for an object factory that creates adaptor/proxy // objects @@ -44,6 +46,8 @@ class ControlInterface { Config* config, int service_identifier) = 0; virtual std::unique_ptr<DeviceAdaptorInterface> CreateDeviceAdaptor( Device* device) = 0; + virtual std::unique_ptr<ServiceAdaptorInterface> CreateServiceAdaptor( + Service* service) = 0; // Proxy creation APIs. virtual std::unique_ptr<FirewallProxyInterface> CreateFirewallProxy( diff --git a/dbus/dbus_control.cc b/dbus/dbus_control.cc index c3da97d..54722e7 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/service_dbus_adaptor.h" #include "apmanager/dbus/shill_dbus_proxy.h" #include "apmanager/manager.h" @@ -101,6 +102,12 @@ std::unique_ptr<DeviceAdaptorInterface> DBusControl::CreateDeviceAdaptor( new DeviceDBusAdaptor(bus_, object_manager_.get(), device)); } +std::unique_ptr<ServiceAdaptorInterface> DBusControl::CreateServiceAdaptor( + Service* service) { + return std::unique_ptr<ServiceAdaptorInterface>( + new ServiceDBusAdaptor(bus_, object_manager_.get(), service)); +} + std::unique_ptr<FirewallProxyInterface> DBusControl::CreateFirewallProxy( const base::Closure& service_appeared_callback, const base::Closure& service_vanished_callback) { diff --git a/dbus/dbus_control.h b/dbus/dbus_control.h index 1a323e7..565ed11 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<ServiceAdaptorInterface> CreateServiceAdaptor( + Service* device) override; std::unique_ptr<FirewallProxyInterface> CreateFirewallProxy( const base::Closure& service_appeared_callback, const base::Closure& service_vanished_callback) override; diff --git a/dbus/service_dbus_adaptor.cc b/dbus/service_dbus_adaptor.cc new file mode 100644 index 0000000..2e90ae7 --- /dev/null +++ b/dbus/service_dbus_adaptor.cc @@ -0,0 +1,72 @@ +// +// Copyright (C) 2014 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/service_dbus_adaptor.h" + +#include <base/strings/stringprintf.h> +#include <dbus_bindings/org.chromium.apmanager.Manager.h> + +#include "apmanager/service.h" + +using brillo::dbus_utils::ExportedObjectManager; +using brillo::dbus_utils::DBusMethodResponse; +using brillo::dbus_utils::DBusObject; +using org::chromium::apmanager::ManagerAdaptor; +using std::string; + +namespace apmanager { + +ServiceDBusAdaptor::ServiceDBusAdaptor( + const scoped_refptr<dbus::Bus>& bus, + ExportedObjectManager* object_manager, + Service* service) + : adaptor_(this), + object_path_( + base::StringPrintf("%s/services/%d", + ManagerAdaptor::GetObjectPath().value().c_str(), + service->identifier())), + dbus_object_(object_manager, bus, object_path_), + service_(service) { + // Register D-Bus object. + adaptor_.RegisterWithDBusObject(&dbus_object_); + dbus_object_.RegisterAndBlock(); +} + +ServiceDBusAdaptor::~ServiceDBusAdaptor() {} + +void ServiceDBusAdaptor::Start( + std::unique_ptr<DBusMethodResponse<>> response) { + // TODO(zqiu): to be implemented. +} + +bool ServiceDBusAdaptor::Stop(brillo::ErrorPtr* error) { + // TODO(zqiu): to be implemented. + return false; +} + +RPCObjectIdentifier ServiceDBusAdaptor::GetRpcObjectIdentifier() { + return object_path_; +} + +void ServiceDBusAdaptor::SetConfig(Config* config) { + adaptor_.SetConfig(config->adaptor()->GetRpcObjectIdentifier()); +} + +void ServiceDBusAdaptor::SetState(const string& state) { + adaptor_.SetState(state); +} + +} // namespace apmanager diff --git a/dbus/service_dbus_adaptor.h b/dbus/service_dbus_adaptor.h new file mode 100644 index 0000000..9ca577d --- /dev/null +++ b/dbus/service_dbus_adaptor.h @@ -0,0 +1,60 @@ +// +// 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_SERVICE_DBUS_ADAPTOR_H_ +#define APMANAGER_DBUS_SERVICE_DBUS_ADAPTOR_H_ + +#include <base/macros.h> + +#include <dbus_bindings/org.chromium.apmanager.Service.h> + +#include "apmanager/service_adaptor_interface.h" + +namespace apmanager { + +class Service; + +class ServiceDBusAdaptor : public org::chromium::apmanager::ServiceInterface, + public ServiceAdaptorInterface { + public: + ServiceDBusAdaptor(const scoped_refptr<dbus::Bus>& bus, + brillo::dbus_utils::ExportedObjectManager* object_manager, + Service* service); + ~ServiceDBusAdaptor() override; + + // Implementation of org::chromium::apmanager::ServiceInterface + void Start( + std::unique_ptr<brillo::dbus_utils::DBusMethodResponse<>> + response) override; + bool Stop(brillo::ErrorPtr* error) override; + + // Implementation of ServiceAdaptorInterface. + RPCObjectIdentifier GetRpcObjectIdentifier() override; + void SetConfig(Config* config) override; + void SetState(const std::string& state) override; + + private: + org::chromium::apmanager::ServiceAdaptor adaptor_; + dbus::ObjectPath object_path_; + brillo::dbus_utils::DBusObject dbus_object_; + Service* service_; + + DISALLOW_COPY_AND_ASSIGN(ServiceDBusAdaptor); +}; + +} // namespace apmanager + +#endif // APMANAGER_DBUS_SERVICE_DBUS_ADAPTOR_H_ diff --git a/mock_control.cc b/mock_control.cc index bf4c0fa..2ce18f8 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<ServiceAdaptorInterface> MockControl::CreateServiceAdaptor( + Service* /* service */) { + return std::unique_ptr<ServiceAdaptorInterface>(CreateServiceAdaptorRaw()); +} + std::unique_ptr<FirewallProxyInterface> MockControl::CreateFirewallProxy( const base::Closure& /* service_appeared_callback */, const base::Closure& /* service_vanished_callback */) { diff --git a/mock_control.h b/mock_control.h index 4782f4f..4009c78 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(CreateServiceAdaptorRaw, ServiceAdaptorInterface*()); MOCK_METHOD0(CreateShillProxyRaw, ShillProxyInterface*()); // These functions use the mock methods above for creating @@ -47,6 +48,8 @@ class MockControl : public ControlInterface { Config* config, int service_identifier) override; std::unique_ptr<DeviceAdaptorInterface> CreateDeviceAdaptor( Device* device) override; + std::unique_ptr<ServiceAdaptorInterface> CreateServiceAdaptor( + Service* service) override; std::unique_ptr<FirewallProxyInterface> CreateFirewallProxy( const base::Closure& service_appeared_callback, const base::Closure& service_vanished_callback) override; diff --git a/service_adaptor_interface.h b/service_adaptor_interface.h new file mode 100644 index 0000000..7a7bf48 --- /dev/null +++ b/service_adaptor_interface.h @@ -0,0 +1,39 @@ +// +// 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_SERVICE_ADAPTOR_INTERFACE_H_ +#define APMANAGER_SERVICE_ADAPTOR_INTERFACE_H_ + +#include <string> + +#include "apmanager/rpc_interface.h" + +namespace apmanager { + +class Config; + +class ServiceAdaptorInterface { + public: + virtual ~ServiceAdaptorInterface() {} + + virtual RPCObjectIdentifier GetRpcObjectIdentifier() = 0; + virtual void SetConfig(Config* config) = 0; + virtual void SetState(const std::string& state) = 0; +}; + +} // namespace apmanager + +#endif // APMANAGER_SERVICE_ADAPTOR_INTERFACE_H_ |