Remove redundant design of fast pair wrapper.

PiperOrigin-RevId: 540410011
This commit is contained in:
hai007
2023-06-14 16:18:48 -07:00
committed by Copybara-Service
parent cf9170ba16
commit 87fd2f130a
7 changed files with 0 additions and 350 deletions
-60
View File
@@ -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",
],
)
-43
View File
@@ -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 <string>
#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<int>(status_code);
return kUnknownStatusCodesString;
}
} // namespace fastpair
} // namespace nearby
-54
View File
@@ -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 <functional>
#include <string>
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_
-50
View File
@@ -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 <memory>
#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<ScannerBrokerImpl>(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
-55
View File
@@ -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 <functional>
#include <memory>
#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<ScannerBroker> 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_
@@ -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 <memory>
#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
-53
View File
@@ -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 <string>
#include <vector>
#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<StatusCodeToStringData> GetTestData() {
static std::vector<StatusCodeToStringData>* kStatusCodeToStringData =
new std::vector<StatusCodeToStringData>({
{StatusCodes::kOk, "kOk"},
{StatusCodes::kError, "kError"},
});
return *kStatusCodeToStringData;
}
using StatusCodeToString = testing::TestWithParam<StatusCodeToStringData>;
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