From 87fd2f130ad1b297f81af3a4c63ceff522c74c78 Mon Sep 17 00:00:00 2001 From: hai007 Date: Wed, 14 Jun 2023 16:17:44 -0700 Subject: [PATCH] Remove redundant design of fast pair wrapper. PiperOrigin-RevId: 540410011 --- fastpair/dart/BUILD | 60 -------------------- fastpair/dart/fast_pair_wrapper.cc | 43 -------------- fastpair/dart/fast_pair_wrapper.h | 54 ------------------ fastpair/dart/fast_pair_wrapper_impl.cc | 50 ---------------- fastpair/dart/fast_pair_wrapper_impl.h | 55 ------------------ fastpair/dart/fast_pair_wrapper_impl_test.cc | 35 ------------ fastpair/dart/fast_pair_wrapper_test.cc | 53 ----------------- 7 files changed, 350 deletions(-) delete mode 100644 fastpair/dart/BUILD delete mode 100644 fastpair/dart/fast_pair_wrapper.cc delete mode 100644 fastpair/dart/fast_pair_wrapper.h delete mode 100644 fastpair/dart/fast_pair_wrapper_impl.cc delete mode 100644 fastpair/dart/fast_pair_wrapper_impl.h delete mode 100644 fastpair/dart/fast_pair_wrapper_impl_test.cc delete mode 100644 fastpair/dart/fast_pair_wrapper_test.cc diff --git a/fastpair/dart/BUILD b/fastpair/dart/BUILD deleted file mode 100644 index e6cdab0b..00000000 --- a/fastpair/dart/BUILD +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright 2023 Google LLC -# -# 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 -# -# https://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. - -licenses(["notice"]) - -cc_library( - name = "fastpair_wrapper", - srcs = [ - "fast_pair_wrapper.cc", - "fast_pair_wrapper_impl.cc", - ], - hdrs = [ - "fast_pair_wrapper.h", - "fast_pair_wrapper_impl.h", - ], - copts = ["-Ithird_party"], - visibility = [ - "//fastpair:__subpackages__", - ], - deps = [ - "//fastpair/common", - "//fastpair/repository:device_repository", - "//fastpair/scanning:scanner", - "//internal/platform:logging", - "//internal/platform:types", - ], -) - -cc_test( - name = "fastpair_wrapper_test", - size = "small", - timeout = "short", - srcs = [ - "fast_pair_wrapper_impl_test.cc", - "fast_pair_wrapper_test.cc", - ], - copts = [ - "-Ithird_party", - ], - shard_count = 8, - deps = [ - ":fastpair_wrapper", - "//internal/platform:test_util", - "//internal/platform/implementation:types", - "//internal/platform/implementation/g3", - "@com_github_protobuf_matchers//protobuf-matchers", - "@com_google_googletest//:gtest_main", - ], -) diff --git a/fastpair/dart/fast_pair_wrapper.cc b/fastpair/dart/fast_pair_wrapper.cc deleted file mode 100644 index f57af7a1..00000000 --- a/fastpair/dart/fast_pair_wrapper.cc +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2022 Google LLC -// -// 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 -// -// https://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 "fastpair/dart/fast_pair_wrapper.h" - -#include - -#include "internal/platform/logging.h" - -namespace nearby { -namespace fastpair { -namespace { - -using StatusCodes = FastPairWrapper::StatusCodes; -constexpr char kUnknownStatusCodesString[] = "Unknown_StatusCodes"; - -} // namespace - -std::string FastPairWrapper::StatusCodeToString(StatusCodes status_code) { - switch (status_code) { - case StatusCodes::kOk: - return "kOk"; - case StatusCodes::kError: - return "kError"; - } - NEARBY_LOGS(ERROR) << "Unknown value for Status codes: " - << static_cast(status_code); - return kUnknownStatusCodesString; -} - -} // namespace fastpair -} // namespace nearby diff --git a/fastpair/dart/fast_pair_wrapper.h b/fastpair/dart/fast_pair_wrapper.h deleted file mode 100644 index e33289ad..00000000 --- a/fastpair/dart/fast_pair_wrapper.h +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2022 Google LLC -// -// 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 -// -// https://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 THIRD_PARTY_NEARBY_FASTPAIR_DART_FAST_PAIR_WRAPPER_H_ -#define THIRD_PARTY_NEARBY_FASTPAIR_DART_FAST_PAIR_WRAPPER_H_ - -#include -#include - -namespace nearby { -namespace fastpair { - -class FastPairWrapper { - public: - enum class StatusCodes { - // The operation successed. - kOk = 0, - // The operation failed. - kError = 1, - }; - - static std::string StatusCodeToString(StatusCodes status_code); - - virtual ~FastPairWrapper() = default; - - // Obtain the scanning status - virtual bool IsScanning() = 0; - - // Obtain the pairing status - virtual bool IsPairing() = 0; - - // Server Access trigger just for adapter implementation testing, will be - // delete after success - virtual bool IsServerAccessing() = 0; - - // Trigger function of the scanning - virtual void StartScan() = 0; -}; - -} // namespace fastpair -} // namespace nearby - -#endif // THIRD_PARTY_NEARBY_FASTPAIR_DART_FAST_PAIR_WRAPPER_H_ diff --git a/fastpair/dart/fast_pair_wrapper_impl.cc b/fastpair/dart/fast_pair_wrapper_impl.cc deleted file mode 100644 index af95e421..00000000 --- a/fastpair/dart/fast_pair_wrapper_impl.cc +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2022 Google LLC -// -// 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 -// -// https://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 "fastpair/dart/fast_pair_wrapper_impl.h" - -#include - -#include "fastpair/common/protocol.h" -#include "fastpair/scanning/scanner_broker_impl.h" -#include "internal/platform/logging.h" - -namespace nearby { -namespace fastpair { - -FastPairWrapperImpl::FastPairWrapperImpl() { - NEARBY_LOGS(INFO) << "FastPairWrapperImpl starts."; -} -FastPairWrapperImpl::~FastPairWrapperImpl() = default; - -void FastPairWrapperImpl::StartScan() { - Mediums mediums; - scanner_broker_ = - std::make_unique(mediums, &executor_, &devices_); - if (is_scanning_) { - NEARBY_LOGS(VERBOSE) << __func__ << ": We're currently scanning. "; - return; - } - is_scanning_ = true; - scanner_broker_->StartScanning(Protocol::kFastPairInitialPairing); -} - -bool FastPairWrapperImpl::IsScanning() { return is_scanning_; } - -bool FastPairWrapperImpl::IsPairing() { return is_connecting_; } - -bool FastPairWrapperImpl::IsServerAccessing() { return is_server_access_; } - -} // namespace fastpair -} // namespace nearby diff --git a/fastpair/dart/fast_pair_wrapper_impl.h b/fastpair/dart/fast_pair_wrapper_impl.h deleted file mode 100644 index f9c72ea5..00000000 --- a/fastpair/dart/fast_pair_wrapper_impl.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2022 Google LLC -// -// 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 -// -// https://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 THIRD_PARTY_NEARBY_FASTPAIR_DART_FAST_PAIR_WRAPPER_IMPL_H_ -#define THIRD_PARTY_NEARBY_FASTPAIR_DART_FAST_PAIR_WRAPPER_IMPL_H_ - -#include -#include - -#include "fastpair/dart/fast_pair_wrapper.h" -#include "fastpair/repository/fast_pair_device_repository.h" -#include "fastpair/scanning/scanner_broker.h" -#include "internal/platform/single_thread_executor.h" - -namespace nearby { -namespace fastpair { - -class FastPairScannerImpl; - -class FastPairWrapperImpl : public FastPairWrapper { - public: - explicit FastPairWrapperImpl(); - ~FastPairWrapperImpl() override; - - bool IsScanning() override; - bool IsPairing() override; - bool IsServerAccessing() override; - void StartScan() override; - - private: - SingleThreadExecutor executor_; - FastPairDeviceRepository devices_{&executor_}; - std::unique_ptr scanner_broker_; - - // True if we are currently scanning for remote devices. - bool is_scanning_ = false; - bool is_connecting_ = false; - bool is_server_access_ = false; -}; - -} // namespace fastpair -} // namespace nearby - -#endif // THIRD_PARTY_NEARBY_FASTPAIR_DART_FAST_PAIR_WRAPPER_IMPL_H_ diff --git a/fastpair/dart/fast_pair_wrapper_impl_test.cc b/fastpair/dart/fast_pair_wrapper_impl_test.cc deleted file mode 100644 index 065c3bca..00000000 --- a/fastpair/dart/fast_pair_wrapper_impl_test.cc +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2022 Google LLC -// -// 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 -// -// https://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 "fastpair/dart/fast_pair_wrapper_impl.h" - -#include - -#include "gtest/gtest.h" -#include "internal/platform/medium_environment.h" - -namespace nearby { -namespace fastpair { -namespace FastPairWrapperUnitTests { - -TEST(FastPairWrapperImplTest, StartScanningSuccess) { - FastPairWrapperImpl wrapper; - EXPECT_FALSE(wrapper.IsScanning()); - EXPECT_FALSE(wrapper.IsPairing()); - EXPECT_FALSE(wrapper.IsServerAccessing()); -} - -} // namespace FastPairWrapperUnitTests -} // namespace fastpair -} // namespace nearby diff --git a/fastpair/dart/fast_pair_wrapper_test.cc b/fastpair/dart/fast_pair_wrapper_test.cc deleted file mode 100644 index 9417be72..00000000 --- a/fastpair/dart/fast_pair_wrapper_test.cc +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2022 Google LLC -// -// 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 -// -// https://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 "fastpair/dart/fast_pair_wrapper.h" - -#include -#include - -#include "gtest/gtest.h" - -namespace nearby { -namespace fastpair { -using ::nearby::fastpair::FastPairWrapper; -using StatusCodes = FastPairWrapper::StatusCodes; - -struct StatusCodeToStringData { - StatusCodes status_code; - std::string expected_string_result; -}; - -std::vector GetTestData() { - static std::vector* kStatusCodeToStringData = - new std::vector({ - {StatusCodes::kOk, "kOk"}, - {StatusCodes::kError, "kError"}, - }); - - return *kStatusCodeToStringData; -} - -using StatusCodeToString = testing::TestWithParam; - -TEST_P(StatusCodeToString, ToStringResultMatches) { - EXPECT_EQ(GetParam().expected_string_result, - FastPairWrapper::StatusCodeToString(GetParam().status_code)); -} - -INSTANTIATE_TEST_CASE_P(StatusCodeToString, StatusCodeToString, - testing::ValuesIn(GetTestData())); - -} // namespace fastpair -} // namespace nearby