summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2015-12-07 15:15:55 -0800
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-12-10 16:42:06 +0000
commit40803165a6e4a2362a6e99a4f1e6484cc2de11f1 (patch)
tree4ebbbe758b31bfecfae38e7ac13e67b484d9b3bc
parentd64f1cc74633cae7527b6b8f6e21356c3f00efe7 (diff)
downloadshill-40803165a6e4a2362a6e99a4f1e6484cc2de11f1.tar.gz
shill-test-proxy: Parse XML RPC data structures
Convert the received XML RPC structure into the corresponding class instance. The type of stucture received is encoded in the member |xmlrpc_struct_type_key|. All of these class members have been declared under public so that they can be easily accessed by |proxy_rpc_server| after parsing. These are "classes" instead of "structs" because |AssociationParameters| composite data type defined here contains a |SecurityConfig| object. Bug: 26069117 Change-Id: I34cfef3bfd7e3030cbe61bbec66adfe34e4d015e TEST: mmm system/connectivity/shill
-rw-r--r--test-rpc-proxy/proxy_rpc_in_data_types.cc134
-rw-r--r--test-rpc-proxy/proxy_rpc_in_data_types.h82
-rw-r--r--test-rpc-proxy/proxy_rpc_out_data_types.cc45
-rw-r--r--test-rpc-proxy/proxy_rpc_out_data_types.h42
4 files changed, 303 insertions, 0 deletions
diff --git a/test-rpc-proxy/proxy_rpc_in_data_types.cc b/test-rpc-proxy/proxy_rpc_in_data_types.cc
new file mode 100644
index 00000000..1e24f5d2
--- /dev/null
+++ b/test-rpc-proxy/proxy_rpc_in_data_types.cc
@@ -0,0 +1,134 @@
+//
+// 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 "proxy_rpc_in_data_types.h"
+#include "proxy_util.h"
+
+namespace {
+// Autotest Server test encodes the object type in this key.
+static const char kXmlRpcStructTypeKey[] = "xmlrpc_struct_type_key";
+
+void AssertStructTypeStringFromXmlRpcValue(
+ XmlRpc::XmlRpcValue* xml_rpc_value_in,
+ std::string expected_type) {
+ if ((*xml_rpc_value_in)[kXmlRpcStructTypeKey] != expected_type) {
+ LOG(FATAL) << "Unexpected object received. Expected: " << expected_type
+ << "Recieved: " << (*xml_rpc_value_in)[kXmlRpcStructTypeKey];
+ }
+}
+
+ProxyShillWifiClient::StationType ParseStationTypeFromXmlRpcValue(
+ XmlRpc::XmlRpcValue* xml_rpc_value_in) {
+ ProxyShillWifiClient::StationType station_type;
+ std::string station_type_as_string;
+ GetStringValueFromXmlRpcValueStructMember(
+ xml_rpc_value_in, "station_type", "managed", &station_type_as_string);
+ if (station_type_as_string == "managed") {
+ station_type = ProxyShillWifiClient::kStationTypeManaged;
+ } else if (station_type_as_string == "ibss") {
+ station_type = ProxyShillWifiClient::kStationTypeIBSS;
+ } else {
+ station_type = ProxyShillWifiClient::kStationTypeUnknown;
+ }
+ return station_type;
+}
+
+ProxyShillWifiClient::AutoConnectType ParseAutoConnectTypeFromXmlRpcValue(
+ XmlRpc::XmlRpcValue* xml_rpc_value_in) {
+ ProxyShillWifiClient::AutoConnectType autoconnect_type;
+ bool autoconnect_type_as_bool;
+ if (GetBoolValueFromXmlRpcValueStructMember(
+ xml_rpc_value_in, "autoconnect", false, &autoconnect_type_as_bool)) {
+ if (autoconnect_type_as_bool) {
+ autoconnect_type = ProxyShillWifiClient::kAutoConnectTypeEnabled;
+ } else {
+ autoconnect_type = ProxyShillWifiClient::kAutoConnectTypeDisabled;
+ }
+ } else {
+ autoconnect_type = ProxyShillWifiClient::kAutoConnectTypeUnspecified;
+ }
+ return autoconnect_type;
+}
+
+} // namespace
+
+const int BgscanConfiguration::kDefaultShortIntervalSeconds = 30;
+const int BgscanConfiguration::kDefaultLongIntervalSeconds = 180;
+const int BgscanConfiguration::kDefaultSignalThreshold = -50;
+const char BgscanConfiguration::kDefaultScanMethod[] = "default";
+const int AssociationParameters::kDefaultDiscoveryTimeoutSeconds = 15;
+const int AssociationParameters::kDefaultAssociationTimeoutSeconds = 15;
+const int AssociationParameters::kDefaultConfigurationTimeoutSeconds = 15;
+
+BgscanConfiguration::BgscanConfiguration(
+ XmlRpc::XmlRpcValue* xml_rpc_value_in) {
+ AssertStructTypeStringFromXmlRpcValue(
+ xml_rpc_value_in, "BgscanConfiguration");
+ GetStringValueFromXmlRpcValueStructMember(
+ xml_rpc_value_in, "interface", std::string(), &interface_);
+ GetIntValueFromXmlRpcValueStructMember(
+ xml_rpc_value_in, "signal", kDefaultSignalThreshold, &signal_threshold_);
+ GetIntValueFromXmlRpcValueStructMember(
+ xml_rpc_value_in, "short_interval", kDefaultShortIntervalSeconds,
+ &short_interval_);
+ GetIntValueFromXmlRpcValueStructMember(
+ xml_rpc_value_in, "short_interval", kDefaultLongIntervalSeconds,
+ &long_interval_);
+ GetStringValueFromXmlRpcValueStructMember(
+ xml_rpc_value_in, "method", kDefaultScanMethod, &method_);
+}
+
+AssociationParameters::AssociationParameters(
+ XmlRpc::XmlRpcValue* xml_rpc_value_in) {
+ AssertStructTypeStringFromXmlRpcValue(
+ xml_rpc_value_in, "AssociationParameters");
+ GetStringValueFromXmlRpcValueStructMember(
+ xml_rpc_value_in, "ssid", std::string(), &ssid_);
+ GetIntValueFromXmlRpcValueStructMember(
+ xml_rpc_value_in, "discovery_timeout",
+ kDefaultDiscoveryTimeoutSeconds, &discovery_timeout_seconds_);
+ GetIntValueFromXmlRpcValueStructMember(
+ xml_rpc_value_in, "association_timeout",
+ kDefaultAssociationTimeoutSeconds, &association_timeout_seconds_);
+ GetIntValueFromXmlRpcValueStructMember(
+ xml_rpc_value_in, "configuration_timeout",
+ kDefaultConfigurationTimeoutSeconds, &configuration_timeout_seconds_);
+ GetBoolValueFromXmlRpcValueStructMember(
+ xml_rpc_value_in, "is_hidden", false, &is_hidden_);
+ GetBoolValueFromXmlRpcValueStructMember(
+ xml_rpc_value_in, "save_credentials", false, &save_credentials_);
+ station_type_ = ParseStationTypeFromXmlRpcValue(xml_rpc_value_in);
+ GetStringValueFromXmlRpcValueStructMember(
+ xml_rpc_value_in, "guid", std::string(), &guid_);
+ GetBoolValueFromXmlRpcValueStructMember(
+ xml_rpc_value_in, "expect_failure", false, &expect_failure_);
+ autoconnect_type_ = ParseAutoConnectTypeFromXmlRpcValue(xml_rpc_value_in);
+ bgscan_config_ = std::unique_ptr<BgscanConfiguration>(
+ new BgscanConfiguration(&(*xml_rpc_value_in)["bgscan_config"]));
+ security_config_ = SecurityConfig::CreateSecurityConfigObject(
+ &(*xml_rpc_value_in)["security_config"]);
+}
+
+ConfigureServiceParameters::ConfigureServiceParameters(
+ XmlRpc::XmlRpcValue* xml_rpc_value_in) {
+ AssertStructTypeStringFromXmlRpcValue(
+ xml_rpc_value_in, "ConfigureServiceParameters");
+ GetStringValueFromXmlRpcValueStructMember(
+ xml_rpc_value_in, "guid", std::string(), &guid_);
+ GetStringValueFromXmlRpcValueStructMember(
+ xml_rpc_value_in, "passphrase", std::string(), &passphrase_);
+ autoconnect_type_ = ParseAutoConnectTypeFromXmlRpcValue(xml_rpc_value_in);
+}
diff --git a/test-rpc-proxy/proxy_rpc_in_data_types.h b/test-rpc-proxy/proxy_rpc_in_data_types.h
new file mode 100644
index 00000000..8eb30557
--- /dev/null
+++ b/test-rpc-proxy/proxy_rpc_in_data_types.h
@@ -0,0 +1,82 @@
+//
+// 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 PROXY_RPC_IN_DATA_TYPES_H
+#define PROXY_RPC_IN_DATA_TYPES_H
+
+#include <string>
+
+#include <XmlRpcValue.h>
+
+#include "proxy_shill_wifi_client.h"
+#include "proxy_rpc_security_types.h"
+
+// Describes how to configure wpa_supplicant on a DUT.
+class BgscanConfiguration {
+ public:
+ static const int kDefaultShortIntervalSeconds;
+ static const int kDefaultLongIntervalSeconds;
+ static const int kDefaultSignalThreshold;
+ static const char kDefaultScanMethod[];
+
+ BgscanConfiguration(XmlRpc::XmlRpcValue* xml_rpc_value_in);
+
+ std::string interface_;
+ int signal_threshold_;
+ int short_interval_;
+ int long_interval_;
+ std::string method_;
+};
+
+// Describes parameters used in WiFi connection attempts.
+class AssociationParameters {
+ public:
+ static const int kDefaultDiscoveryTimeoutSeconds;
+ static const int kDefaultAssociationTimeoutSeconds;
+ static const int kDefaultConfigurationTimeoutSeconds;
+
+ AssociationParameters(XmlRpc::XmlRpcValue* xml_rpc_value_in);
+
+ std::string ssid_;
+ int discovery_timeout_seconds_;
+ int association_timeout_seconds_;
+ int configuration_timeout_seconds_;
+ bool is_hidden_;
+ bool save_credentials_;
+ ProxyShillWifiClient::StationType station_type_;
+ std::string guid_;
+ bool expect_failure_;
+ ProxyShillWifiClient::AutoConnectType autoconnect_type_;
+ std::unique_ptr<BgscanConfiguration> bgscan_config_;
+ std::unique_ptr<SecurityConfig> security_config_;
+};
+
+// Describes a group of optional settings for use with ConfigureService.
+// The Manager in shill has a method ConfigureService which takes a dictionary
+// of parameters, and uses some of them to look up a service, and sets the
+// remainder of the properties on the service. This struct represents
+// some of the optional parameters that can be set in this way. Current
+// consumers of this interface look up the service by GUID.
+class ConfigureServiceParameters {
+ public:
+ ConfigureServiceParameters(XmlRpc::XmlRpcValue* xml_rpc_value_in);
+
+ std::string guid_;
+ std::string passphrase_;
+ ProxyShillWifiClient::AutoConnectType autoconnect_type_;
+};
+
+#endif // PROXY_RPC_IN_DATA_TYPES_H
diff --git a/test-rpc-proxy/proxy_rpc_out_data_types.cc b/test-rpc-proxy/proxy_rpc_out_data_types.cc
new file mode 100644
index 00000000..dc56e85d
--- /dev/null
+++ b/test-rpc-proxy/proxy_rpc_out_data_types.cc
@@ -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.
+//
+
+#include "proxy_rpc_out_data_types.h"
+
+namespace {
+// Autotest Server test encodes the object type in this key.
+static const char kXmlRpcStructTypeKey[] = "xmlrpc_struct_type_key";
+} // namespace
+
+AssociationResult::AssociationResult(
+ bool success,
+ double discovery_time,
+ double association_time,
+ double configuration_time,
+ const std::string& failure_reason)
+ : success_(success),
+ discovery_time_(discovery_time),
+ association_time_(association_time),
+ configuration_time_(configuration_time),
+ failure_reason_(failure_reason) {}
+
+XmlRpc::XmlRpcValue AssociationResult::ConvertToXmlRpcValue() {
+ XmlRpc::XmlRpcValue value;
+ value["discovery_time"] = discovery_time_;
+ value["association_time"] = association_time_;
+ value["configuration_time"] = configuration_time_;
+ value["failure_reason"] = failure_reason_;
+ value["success"] = success_;
+ value[kXmlRpcStructTypeKey] = "AssociationResult";
+ return value;
+}
diff --git a/test-rpc-proxy/proxy_rpc_out_data_types.h b/test-rpc-proxy/proxy_rpc_out_data_types.h
new file mode 100644
index 00000000..c6721f94
--- /dev/null
+++ b/test-rpc-proxy/proxy_rpc_out_data_types.h
@@ -0,0 +1,42 @@
+//
+// 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 PROXY_RPC_OUT_DATA_TYPES_H
+#define PROXY_RPC_OUT_DATA_TYPES_H
+
+#include <string>
+
+#include <XmlRpcValue.h>
+
+// Describes the result of an association attempt.
+class AssociationResult {
+ public:
+ AssociationResult(bool success,
+ double discovery_time,
+ double association_time,
+ double configuration_time,
+ const std::string& failure_reason);
+ XmlRpc::XmlRpcValue ConvertToXmlRpcValue();
+
+ private:
+ bool success_;
+ double discovery_time_;
+ double association_time_;
+ double configuration_time_;
+ std::string failure_reason_;
+};
+
+#endif // PROXY_RPC_OUT_DATA_TYPES_H