summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Qiu <zqiu@google.com>2015-11-17 13:45:57 -0800
committerPeter Qiu <zqiu@google.com>2015-11-19 13:43:33 -0800
commit00029783fc5a927dd0cddc03bdcd8e760655ce46 (patch)
tree221f1cb590f242ee4fbcea785ffc52608f4b60a6
parentf933540bb968efa2744ee48b40ab713ccd358d51 (diff)
downloadapmanager-00029783fc5a927dd0cddc03bdcd8e760655ce46.tar.gz
Define and implement an AdaptorInterface for Config
This interface will be used by Config 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. An upcoming CL will integrate this AdaptorInterface to the Config class, to decouple Config class from the underlying RPC implementation. Bug: 24194427 TEST=Build apmanager for both Brillo and Chrome OS Change-Id: I61d46c37bac875ce4a196dcc4abb752f5880ec50
-rw-r--r--Android.mk1
-rw-r--r--apmanager.gyp1
-rw-r--r--config_adaptor_interface.h55
-rw-r--r--control_interface.h4
-rw-r--r--dbus/config_dbus_adaptor.cc178
-rw-r--r--dbus/config_dbus_adaptor.h91
-rw-r--r--dbus/dbus_control.cc8
-rw-r--r--dbus/dbus_control.h2
-rw-r--r--mock_control.cc5
-rw-r--r--mock_control.h3
10 files changed, 348 insertions, 0 deletions
diff --git a/Android.mk b/Android.mk
index 584b4cb..d2d0d00 100644
--- a/Android.mk
+++ b/Android.mk
@@ -67,6 +67,7 @@ LOCAL_SRC_FILES := \
dbus_bindings/org.chromium.apmanager.Service.dbus-xml \
config.cc \
daemon.cc \
+ dbus/config_dbus_adaptor.cc \
dbus/dbus_control.cc \
dbus/device_dbus_adaptor.cc \
dbus/firewalld_dbus_proxy.cc \
diff --git a/apmanager.gyp b/apmanager.gyp
index 290d139..755e63f 100644
--- a/apmanager.gyp
+++ b/apmanager.gyp
@@ -75,6 +75,7 @@
'sources': [
'config.cc',
'daemon.cc',
+ 'dbus/config_dbus_adaptor.cc',
'dbus/dbus_control.cc',
'dbus/device_dbus_adaptor.cc',
'dbus/permission_broker_dbus_proxy.cc',
diff --git a/config_adaptor_interface.h b/config_adaptor_interface.h
new file mode 100644
index 0000000..a7329d8
--- /dev/null
+++ b/config_adaptor_interface.h
@@ -0,0 +1,55 @@
+//
+// 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_CONFIG_ADAPTOR_INTERFACE_H_
+#define APMANAGER_CONFIG_ADAPTOR_INTERFACE_H_
+
+#include <string>
+
+namespace apmanager {
+
+class ConfigAdaptorInterface {
+ public:
+ virtual ~ConfigAdaptorInterface() {}
+
+ // Getter/setter for configuration properties.
+ virtual void SetSsid(const std::string& ssid) = 0;
+ virtual std::string GetSsid() = 0;
+ virtual void SetInterfaceName(const std::string& interface_name) = 0;
+ virtual std::string GetInterfaceName() = 0;
+ virtual void SetSecurityMode(const std::string& security_mode) = 0;
+ virtual std::string GetSecurityMode() = 0;
+ virtual void SetPassphrase(const std::string& passphrase) = 0;
+ virtual std::string GetPassphrase() = 0;
+ virtual void SetHwMode(const std::string& hw_mode) = 0;
+ virtual std::string GetHwMode() = 0;
+ virtual void SetOperationMode(const std::string& op_mode) = 0;
+ virtual std::string GetOperationMode() = 0;
+ virtual void SetChannel(uint16_t channel) = 0;
+ virtual uint16_t GetChannel() = 0;
+ virtual void SetHiddenNetwork(bool hidden) = 0;
+ virtual bool GetHiddenNetwork() = 0;
+ virtual void SetBridgeInterface(const std::string& interface_name) = 0;
+ virtual std::string GetBridgeInterface() = 0;
+ virtual void SetServerAddressIndex(uint16_t) = 0;
+ virtual uint16_t GetServerAddressIndex() = 0;
+ virtual void SetFullDeviceControl(bool full_control) = 0;
+ virtual bool GetFullDeviceControl() = 0;
+};
+
+} // namespace apmanager
+
+#endif // APMANAGER_CONFIG_ADAPTOR_INTERFACE_H_
diff --git a/control_interface.h b/control_interface.h
index 58ef1e1..4d4daf5 100644
--- a/control_interface.h
+++ b/control_interface.h
@@ -20,12 +20,14 @@
#include <base/callback.h>
#include <base/macros.h>
+#include "apmanager/config_adaptor_interface.h"
#include "apmanager/device_adaptor_interface.h"
#include "apmanager/firewall_proxy_interface.h"
#include "apmanager/shill_proxy_interface.h"
namespace apmanager {
+class Config;
class Device;
// This is the Interface for an object factory that creates adaptor/proxy
@@ -38,6 +40,8 @@ class ControlInterface {
virtual void Shutdown() = 0;
// Adaptor creation APIs.
+ virtual std::unique_ptr<ConfigAdaptorInterface> CreateConfigAdaptor(
+ Config* config, int service_identifier) = 0;
virtual std::unique_ptr<DeviceAdaptorInterface> CreateDeviceAdaptor(
Device* device) = 0;
diff --git a/dbus/config_dbus_adaptor.cc b/dbus/config_dbus_adaptor.cc
new file mode 100644
index 0000000..c99c8a0
--- /dev/null
+++ b/dbus/config_dbus_adaptor.cc
@@ -0,0 +1,178 @@
+//
+// 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/config_dbus_adaptor.h"
+
+#include <base/strings/stringprintf.h>
+#include <dbus_bindings/org.chromium.apmanager.Manager.h>
+
+#if !defined(__ANDROID__)
+#include <chromeos/dbus/service_constants.h>
+#else
+#include <dbus/apmanager/dbus-constants.h>
+#endif // __ANDROID__
+
+#include "apmanager/config.h"
+
+using brillo::dbus_utils::ExportedObjectManager;
+using brillo::ErrorPtr;
+using org::chromium::apmanager::ConfigAdaptor;
+using org::chromium::apmanager::ManagerAdaptor;
+using std::string;
+
+namespace apmanager {
+
+ConfigDBusAdaptor::ConfigDBusAdaptor(
+ const scoped_refptr<dbus::Bus>& bus,
+ ExportedObjectManager* object_manager,
+ Config* config,
+ int service_identifier)
+ : org::chromium::apmanager::ConfigAdaptor(this),
+ dbus_path_(
+ base::StringPrintf("%s/services/%d/config",
+ ManagerAdaptor::GetObjectPath().value().c_str(),
+ service_identifier)),
+ dbus_object_(object_manager, bus, dbus_path_),
+ config_(config) {
+ // Register D-Bus object.
+ dbus_object_.RegisterAndBlock();
+}
+
+ConfigDBusAdaptor::~ConfigDBusAdaptor() {}
+
+bool ConfigDBusAdaptor::ValidateSsid(ErrorPtr* error, const string& value) {
+ // TODO(zqiu): To be implemented.
+ return true;
+}
+
+bool ConfigDBusAdaptor::ValidateSecurityMode(ErrorPtr* error,
+ const string& value) {
+ // TODO(zqiu): To be implemented.
+ return true;
+}
+
+bool ConfigDBusAdaptor::ValidatePassphrase(ErrorPtr* error,
+ const string& value) {
+ // TODO(zqiu): To be implemented.
+ return true;
+}
+
+bool ConfigDBusAdaptor::ValidateHwMode(ErrorPtr* error, const string& value) {
+ // TODO(zqiu): To be implemented.
+ return true;
+}
+
+bool ConfigDBusAdaptor::ValidateOperationMode(ErrorPtr* error,
+ const string& value) {
+ // TODO(zqiu): To be implemented.
+ return true;
+}
+
+bool ConfigDBusAdaptor::ValidateChannel(ErrorPtr* error,
+ const uint16_t& value) {
+ // TODO(zqiu): To be implemented.
+ return true;
+}
+
+void ConfigDBusAdaptor::SetSsid(const string& ssid) {
+ ConfigAdaptor::SetSsid(ssid);
+}
+
+string ConfigDBusAdaptor::GetSsid() {
+ return ConfigAdaptor::GetSsid();
+}
+
+void ConfigDBusAdaptor::SetInterfaceName(const std::string& interface_name) {
+ ConfigAdaptor::SetInterfaceName(interface_name);
+}
+
+string ConfigDBusAdaptor::GetInterfaceName() {
+ return ConfigAdaptor::GetInterfaceName();
+}
+
+void ConfigDBusAdaptor::SetSecurityMode(const std::string& mode) {
+ ConfigAdaptor::SetSecurityMode(mode);
+}
+
+string ConfigDBusAdaptor::GetSecurityMode() {
+ return ConfigAdaptor::GetSecurityMode();
+}
+
+void ConfigDBusAdaptor::SetPassphrase(const std::string& passphrase) {
+ ConfigAdaptor::SetPassphrase(passphrase);
+}
+
+string ConfigDBusAdaptor::GetPassphrase() {
+ return ConfigAdaptor::GetPassphrase();
+}
+
+void ConfigDBusAdaptor::SetHwMode(const std::string& hw_mode) {
+ ConfigAdaptor::SetHwMode(hw_mode);
+}
+
+string ConfigDBusAdaptor::GetHwMode() {
+ return ConfigAdaptor::GetHwMode();
+}
+
+void ConfigDBusAdaptor::SetOperationMode(const std::string& op_mode) {
+ ConfigAdaptor::SetOperationMode(op_mode);
+}
+
+string ConfigDBusAdaptor::GetOperationMode() {
+ return ConfigAdaptor::GetOperationMode();
+}
+
+void ConfigDBusAdaptor::SetChannel(uint16_t channel) {
+ ConfigAdaptor::SetChannel(channel);
+}
+
+uint16_t ConfigDBusAdaptor::GetChannel() {
+ return ConfigAdaptor::GetChannel();
+}
+
+void ConfigDBusAdaptor::SetHiddenNetwork(bool hidden_network) {
+ ConfigAdaptor::SetHiddenNetwork(hidden_network);
+}
+
+bool ConfigDBusAdaptor::GetHiddenNetwork() {
+ return ConfigAdaptor::GetHiddenNetwork();
+}
+
+void ConfigDBusAdaptor::SetBridgeInterface(const std::string& interface_name) {
+ ConfigAdaptor::SetBridgeInterface(interface_name);
+}
+
+string ConfigDBusAdaptor::GetBridgeInterface() {
+ return ConfigAdaptor::GetBridgeInterface();
+}
+
+void ConfigDBusAdaptor::SetServerAddressIndex(uint16_t index) {
+ ConfigAdaptor::SetServerAddressIndex(index);
+}
+
+uint16_t ConfigDBusAdaptor::GetServerAddressIndex() {
+ return ConfigAdaptor::GetServerAddressIndex();
+}
+
+void ConfigDBusAdaptor::SetFullDeviceControl(bool full_control) {
+ ConfigAdaptor::SetFullDeviceControl(full_control);
+}
+
+bool ConfigDBusAdaptor::GetFullDeviceControl() {
+ return ConfigAdaptor::GetFullDeviceControl();
+}
+
+} // namespace apmanager
diff --git a/dbus/config_dbus_adaptor.h b/dbus/config_dbus_adaptor.h
new file mode 100644
index 0000000..08f1637
--- /dev/null
+++ b/dbus/config_dbus_adaptor.h
@@ -0,0 +1,91 @@
+//
+// 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_CONFIG_DBUS_ADAPTOR_H_
+#define APMANAGER_DBUS_CONFIG_DBUS_ADAPTOR_H_
+
+#include <string>
+
+#include <base/macros.h>
+#include <brillo/errors/error.h>
+#include <dbus_bindings/org.chromium.apmanager.Config.h>
+
+#include "apmanager/config_adaptor_interface.h"
+
+namespace apmanager {
+
+class Config;
+
+class ConfigDBusAdaptor
+ : public org::chromium::apmanager::ConfigAdaptor,
+ public org::chromium::apmanager::ConfigInterface,
+ public ConfigAdaptorInterface {
+ public:
+ ConfigDBusAdaptor(const scoped_refptr<dbus::Bus>& bus,
+ brillo::dbus_utils::ExportedObjectManager* object_manager,
+ Config* config,
+ int service_identifier);
+ virtual ~ConfigDBusAdaptor();
+
+ // Implementation of org::chromium::apmanager::ConfigAdaptor.
+ bool ValidateSsid(brillo::ErrorPtr* error,
+ const std::string& value) override;
+ bool ValidateSecurityMode(brillo::ErrorPtr* error,
+ const std::string& value) override;
+ bool ValidatePassphrase(brillo::ErrorPtr* error,
+ const std::string& value) override;
+ bool ValidateHwMode(brillo::ErrorPtr* error,
+ const std::string& value) override;
+ bool ValidateOperationMode(brillo::ErrorPtr* error,
+ const std::string& value) override;
+ bool ValidateChannel(brillo::ErrorPtr* error,
+ const uint16_t& value) override;
+
+ // Implementation of ConfigAdaptorInterface.
+ void SetSsid(const std::string& ssid) override;
+ std::string GetSsid() override;
+ void SetInterfaceName(const std::string& interface_name) override;
+ std::string GetInterfaceName() override;
+ void SetSecurityMode(const std::string& security_mode) override;
+ std::string GetSecurityMode() override;
+ void SetPassphrase(const std::string& passphrase) override;
+ std::string GetPassphrase() override;
+ void SetHwMode(const std::string& hw_mode) override;
+ std::string GetHwMode() override;
+ void SetOperationMode(const std::string& op_mode) override;
+ std::string GetOperationMode() override;
+ void SetChannel(uint16_t channel) override;
+ uint16_t GetChannel() override;
+ void SetHiddenNetwork(bool hidden) override;
+ bool GetHiddenNetwork() override;
+ void SetBridgeInterface(const std::string& interface_name) override;
+ std::string GetBridgeInterface() override;
+ void SetServerAddressIndex(uint16_t) override;
+ uint16_t GetServerAddressIndex() override;
+ void SetFullDeviceControl(bool full_control) override;
+ bool GetFullDeviceControl() override;
+
+ private:
+ dbus::ObjectPath dbus_path_;
+ brillo::dbus_utils::DBusObject dbus_object_;
+ Config* config_;
+
+ DISALLOW_COPY_AND_ASSIGN(ConfigDBusAdaptor);
+};
+
+} // namespace apmanager
+
+#endif // APMANAGER_DBUS_CONFIG_DBUS_ADAPTOR_H_
diff --git a/dbus/dbus_control.cc b/dbus/dbus_control.cc
index 4619af3..c3da97d 100644
--- a/dbus/dbus_control.cc
+++ b/dbus/dbus_control.cc
@@ -16,6 +16,7 @@
#include "apmanager/dbus/dbus_control.h"
+#include "apmanager/dbus/config_dbus_adaptor.h"
#include "apmanager/dbus/device_dbus_adaptor.h"
#include "apmanager/dbus/shill_dbus_proxy.h"
#include "apmanager/manager.h"
@@ -87,6 +88,13 @@ void DBusControl::OnObjectRegistrationCompleted(bool registration_success) {
manager_->Start();
}
+std::unique_ptr<ConfigAdaptorInterface> DBusControl::CreateConfigAdaptor(
+ Config* config, int service_identifier) {
+ return std::unique_ptr<ConfigAdaptorInterface>(
+ new ConfigDBusAdaptor(
+ bus_, object_manager_.get(), config, service_identifier));
+}
+
std::unique_ptr<DeviceAdaptorInterface> DBusControl::CreateDeviceAdaptor(
Device* device) {
return std::unique_ptr<DeviceAdaptorInterface>(
diff --git a/dbus/dbus_control.h b/dbus/dbus_control.h
index 4289afd..1a323e7 100644
--- a/dbus/dbus_control.h
+++ b/dbus/dbus_control.h
@@ -35,6 +35,8 @@ class DBusControl : public ControlInterface {
// Inheritted from ControlInterface.
void Init() override;
void Shutdown() override;
+ std::unique_ptr<ConfigAdaptorInterface> CreateConfigAdaptor(
+ Config* config, int service_identifier) override;
std::unique_ptr<DeviceAdaptorInterface> CreateDeviceAdaptor(
Device* device) override;
std::unique_ptr<FirewallProxyInterface> CreateFirewallProxy(
diff --git a/mock_control.cc b/mock_control.cc
index a7ae8a2..bf4c0fa 100644
--- a/mock_control.cc
+++ b/mock_control.cc
@@ -22,6 +22,11 @@ MockControl::MockControl() {}
MockControl::~MockControl() {}
+std::unique_ptr<ConfigAdaptorInterface> MockControl::CreateConfigAdaptor(
+ Config* /* config */, int /* service_identifier */) {
+ return std::unique_ptr<ConfigAdaptorInterface>(CreateConfigAdaptorRaw());
+}
+
std::unique_ptr<DeviceAdaptorInterface> MockControl::CreateDeviceAdaptor(
Device* /* device */) {
return std::unique_ptr<DeviceAdaptorInterface>(CreateDeviceAdaptorRaw());
diff --git a/mock_control.h b/mock_control.h
index 35d35f1..4782f4f 100644
--- a/mock_control.h
+++ b/mock_control.h
@@ -36,12 +36,15 @@ class MockControl : public ControlInterface {
// This allows us to set expectations for adaptor/proxy creation
// functions, since mock methods only support copyable return values,
// and unique_ptr is not copyable.
+ MOCK_METHOD0(CreateConfigAdaptorRaw, ConfigAdaptorInterface*());
MOCK_METHOD0(CreateDeviceAdaptorRaw, DeviceAdaptorInterface*());
MOCK_METHOD0(CreateFirewallProxyRaw, FirewallProxyInterface*());
MOCK_METHOD0(CreateShillProxyRaw, ShillProxyInterface*());
// These functions use the mock methods above for creating
// raw object.
+ std::unique_ptr<ConfigAdaptorInterface> CreateConfigAdaptor(
+ Config* config, int service_identifier) override;
std::unique_ptr<DeviceAdaptorInterface> CreateDeviceAdaptor(
Device* device) override;
std::unique_ptr<FirewallProxyInterface> CreateFirewallProxy(