Renamed to "wrapper" and move fastpair windows adapter-related code into dart folder to followed the nearby structure change from platform based clients to language based in third_party.

PiperOrigin-RevId: 513635793
This commit is contained in:
hai007
2023-03-02 14:12:32 -08:00
committed by Copybara-Service
parent b0e5b059d9
commit 9542a4812d
14 changed files with 204 additions and 195 deletions
-47
View File
@@ -11,56 +11,9 @@
# 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"])
package_group(
name = "nearby_fastpair",
packages = [
"//fastpair/...",
],
)
cc_library(
name = "fastpair_controller",
srcs = [
"fast_pair_controller.cc",
"fast_pair_controller_impl.cc",
],
hdrs = [
"fast_pair_controller.h",
"fast_pair_controller_impl.h",
],
copts = ["-Ithird_party"],
visibility = [
"//fastpair:__subpackages__",
],
deps = [
"//fastpair/scanning/fastpair:scanning",
"//internal/platform:base",
"//internal/platform:logging",
],
)
cc_test(
name = "fastpair_controller_test",
size = "small",
timeout = "short",
srcs = [
"fast_pair_controller_impl_test.cc",
"fast_pair_controller_test.cc",
],
copts = [
"-Ithird_party",
],
shard_count = 8,
deps = [
":fastpair_controller",
"//fastpair/scanning/fastpair:scanning",
"//internal/platform:logging",
"//internal/platform:test_util",
"//internal/platform/implementation/g3",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_googletest//:gtest_main",
],
)
@@ -1,72 +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/client/windows/fast_pair_controller_adapter.h"
#include "fastpair/fast_pair_controller.h"
#include "fastpair/fast_pair_controller_impl.h"
#include "internal/platform/logging.h"
namespace nearby {
namespace fastpair {
namespace windows {
static FastPairController *pController_ = nullptr;
void *InitFastPairController() {
FastPairControllerImpl *pController = new FastPairControllerImpl();
pController_ = pController;
return pController;
}
void CloseFastPairController(FastPairController *pController) {
NEARBY_LOGS(INFO) << "[[ Closing Fast Pair Controller. ]]";
if (pController_ != nullptr) delete pController_;
NEARBY_LOGS(INFO) << "[[ Successfully closed Fast Pair Controller. ]]";
}
void __stdcall StartScan(FastPairController *pController) {
NEARBY_LOGS(INFO) << "StartScan is called";
if (pController_ == nullptr) {
NEARBY_LOGS(INFO) << "The pController is a null pointer.";
return;
}
return pController_->StartScan();
}
bool __stdcall IsScanning(FastPairController *pController) {
if (pController_ == nullptr) {
return false;
}
return static_cast<FastPairController *>(pController_)->IsScanning();
}
bool __stdcall IsPairing(FastPairController *pController) {
if (pController_ == nullptr) {
return false;
}
// return connecting
return static_cast<FastPairController *>(pController_)->IsPairing();
}
bool __stdcall IsServerAccessing(FastPairController *pController) {
if (pController_ == nullptr) {
return false;
}
return static_cast<FastPairController *>(pController_)->IsServerAccessing();
}
} // namespace windows
} // namespace fastpair
} // namespace nearby
+58
View File
@@ -0,0 +1,58 @@
# 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/scanning/fastpair:scanning",
"//internal/platform:logging",
"//internal/platform/implementation: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",
],
)
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "fastpair/fast_pair_controller.h"
#include "fastpair/dart/fast_pair_wrapper.h"
#include <string>
@@ -22,12 +22,12 @@ namespace nearby {
namespace fastpair {
namespace {
using StatusCodes = FastPairController::StatusCodes;
using StatusCodes = FastPairWrapper::StatusCodes;
constexpr char kUnknownStatusCodesString[] = "Unknown_StatusCodes";
} // namespace
std::string FastPairController::StatusCodeToString(StatusCodes status_code) {
std::string FastPairWrapper::StatusCodeToString(StatusCodes status_code) {
switch (status_code) {
case StatusCodes::kOk:
return "kOk";
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef THIRD_PARTY_NEARBY_FASTPAIR_FAST_PAIR_CONTROLLER_H_
#define THIRD_PARTY_NEARBY_FASTPAIR_FAST_PAIR_CONTROLLER_H_
#ifndef THIRD_PARTY_NEARBY_FASTPAIR_DART_FAST_PAIR_WRAPPER_H_
#define THIRD_PARTY_NEARBY_FASTPAIR_DART_FAST_PAIR_WRAPPER_H_
#include <functional>
#include <string>
@@ -21,7 +21,7 @@
namespace nearby {
namespace fastpair {
class FastPairController {
class FastPairWrapper {
public:
enum class StatusCodes {
// The operation successed.
@@ -32,7 +32,7 @@ class FastPairController {
static std::string StatusCodeToString(StatusCodes status_code);
virtual ~FastPairController() = default;
virtual ~FastPairWrapper() = default;
// Obtain the scanning status
virtual bool IsScanning() = 0;
@@ -51,4 +51,4 @@ class FastPairController {
} // namespace fastpair
} // namespace nearby
#endif // THIRD_PARTY_NEARBY_FAST_PAIR_FASTPAIR_CONTROLLER_H_
#endif // THIRD_PARTY_NEARBY_FASTPAIR_DART_FAST_PAIR_WRAPPER_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "fastpair/fast_pair_controller_impl.h"
#include "fastpair/dart/fast_pair_wrapper_impl.h"
#include <memory>
@@ -22,12 +22,12 @@
namespace nearby {
namespace fastpair {
FastPairControllerImpl::FastPairControllerImpl() {
NEARBY_LOGS(INFO) << "FastPairControllerImpl starts.";
FastPairWrapperImpl::FastPairWrapperImpl() {
NEARBY_LOGS(INFO) << "FastPairWrapperImpl starts.";
}
FastPairControllerImpl::~FastPairControllerImpl() = default;
FastPairWrapperImpl::~FastPairWrapperImpl() = default;
void FastPairControllerImpl::StartScan() {
void FastPairWrapperImpl::StartScan() {
scanner_ = std::make_unique<FastPairScannerImpl>();
if (is_scanning_) {
NEARBY_LOGS(VERBOSE) << __func__ << ": We're currently scanning. ";
@@ -37,11 +37,11 @@ void FastPairControllerImpl::StartScan() {
scanner_->StartScanning();
}
bool FastPairControllerImpl::IsScanning() { return is_scanning_; }
bool FastPairWrapperImpl::IsScanning() { return is_scanning_; }
bool FastPairControllerImpl::IsPairing() { return is_connecting_; }
bool FastPairWrapperImpl::IsPairing() { return is_connecting_; }
bool FastPairControllerImpl::IsServerAccessing() { return is_server_access_; }
bool FastPairWrapperImpl::IsServerAccessing() { return is_server_access_; }
} // namespace fastpair
} // namespace nearby
@@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef THIRD_PARTY_NEARBY_FASTPAIR_FAST_PAIR_CONTROLLER_IMPL_H_
#define THIRD_PARTY_NEARBY_FASTPAIR_FAST_PAIR_CONTROLLER_IMPL_H_
#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/fast_pair_controller.h"
#include "fastpair/dart/fast_pair_wrapper.h"
#include "fastpair/scanning/fastpair/fast_pair_scanner_impl.h"
namespace nearby {
@@ -26,11 +26,10 @@ namespace fastpair {
class FastPairScannerImpl;
class FastPairControllerImpl : public FastPairController,
public FastPairScannerImpl {
class FastPairWrapperImpl : public FastPairWrapper, public FastPairScannerImpl {
public:
explicit FastPairControllerImpl();
~FastPairControllerImpl() override;
explicit FastPairWrapperImpl();
~FastPairWrapperImpl() override;
bool IsScanning() override;
bool IsPairing() override;
@@ -49,4 +48,4 @@ class FastPairControllerImpl : public FastPairController,
} // namespace fastpair
} // namespace nearby
#endif // THIRD_PARTY_NEARBY_FASTPAIR_FAST_PAIR_CONTROLLER_IMPL_H_
#endif // THIRD_PARTY_NEARBY_FASTPAIR_DART_FAST_PAIR_WRAPPER_IMPL_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "fastpair/fast_pair_controller_impl.h"
#include "fastpair/dart/fast_pair_wrapper_impl.h"
#include <memory>
@@ -23,30 +23,30 @@
namespace nearby {
namespace fastpair {
namespace FastPairControllerUnitTests {
class FastPairControllerImplTest : public ::testing::Test {
namespace FastPairWrapperUnitTests {
class FastPairWrapperImplTest : public ::testing::Test {
public:
void SetUp() override {
controller_.reset();
controller_ = std::make_unique<FastPairControllerImpl>();
wrapper_.reset();
wrapper_ = std::make_unique<FastPairWrapperImpl>();
}
protected:
std::shared_ptr<FastPairControllerImpl> controller_;
std::shared_ptr<FastPairWrapperImpl> wrapper_;
MediumEnvironment& env_{MediumEnvironment::Instance()};
};
TEST_F(FastPairControllerImplTest, StartScanningSuccess) {
TEST_F(FastPairWrapperImplTest, StartScanningSuccess) {
env_.Start();
EXPECT_FALSE(controller_->IsScanning());
EXPECT_FALSE(controller_->IsPairing());
EXPECT_FALSE(controller_->IsServerAccessing());
controller_->StartScan();
EXPECT_FALSE(wrapper_->IsScanning());
EXPECT_FALSE(wrapper_->IsPairing());
EXPECT_FALSE(wrapper_->IsServerAccessing());
wrapper_->StartScan();
SystemClock::Sleep(absl::Milliseconds(200));
EXPECT_TRUE(controller_->IsScanning());
EXPECT_TRUE(wrapper_->IsScanning());
env_.Stop();
}
} // namespace FastPairControllerUnitTests
} // namespace FastPairWrapperUnitTests
} // namespace fastpair
} // namespace nearby
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "fastpair/fast_pair_controller.h"
#include "fastpair/dart/fast_pair_wrapper.h"
#include <string>
#include <vector>
@@ -21,8 +21,8 @@
namespace nearby {
namespace fastpair {
using ::nearby::fastpair::FastPairController;
using StatusCodes = FastPairController::StatusCodes;
using ::nearby::fastpair::FastPairWrapper;
using StatusCodes = FastPairWrapper::StatusCodes;
struct StatusCodeToStringData {
StatusCodes status_code;
@@ -43,7 +43,7 @@ using StatusCodeToString = testing::TestWithParam<StatusCodeToStringData>;
TEST_P(StatusCodeToString, ToStringResultMatches) {
EXPECT_EQ(GetParam().expected_string_result,
FastPairController::StatusCodeToString(GetParam().status_code));
FastPairWrapper::StatusCodeToString(GetParam().status_code));
}
INSTANTIATE_TEST_CASE_P(StatusCodeToString, StatusCodeToString,
@@ -1,4 +1,4 @@
# Copyright 2022 Google LLC
# 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.
@@ -18,10 +18,10 @@ licenses(["notice"])
lexan.cc_windows_dll(
name = "fastpair_adapter",
srcs = [
"fast_pair_controller_adapter.cc",
"fast_pair_wrapper_adapter.cc",
],
hdrs = [
"fast_pair_controller_adapter.h",
"fast_pair_wrapper_adapter.h",
],
copts = [
"-Ithird_party",
@@ -35,7 +35,7 @@ lexan.cc_windows_dll(
"//location/nearby/apps/better_together/windows/fast_pair:__subpackages__",
],
deps = [
"//fastpair:fastpair_controller",
"//fastpair/dart:fastpair_wrapper",
"//internal/platform:logging",
"//internal/platform/implementation/windows",
"//internal/platform/implementation/windows/generated:types",
@@ -46,12 +46,12 @@ lexan.cc_windows_dll(
lexan.cc_windows_dll(
name = "fastpair_dart",
srcs = [
"fast_pair_controller_adapter.cc",
"fast_pair_controller_adapter_dart.cc",
"fast_pair_wrapper_adapter.cc",
"fast_pair_wrapper_adapter_dart.cc",
],
hdrs = [
"fast_pair_controller_adapter.h",
"fast_pair_controller_adapter_dart.h",
"fast_pair_wrapper_adapter.h",
"fast_pair_wrapper_adapter_dart.h",
],
copts = [
"-Ithird_party",
@@ -65,7 +65,7 @@ lexan.cc_windows_dll(
"//location/nearby/apps/better_together/windows/fast_pair:__subpackages__",
],
deps = [
"//fastpair:fastpair_controller",
"//fastpair/dart:fastpair_wrapper",
"//internal/platform:logging",
"//internal/platform/implementation/windows",
"//internal/platform/implementation/windows/generated:types",
@@ -0,0 +1,72 @@
// 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/windows/fast_pair_wrapper_adapter.h"
#include "fastpair/dart/fast_pair_wrapper.h"
#include "fastpair/dart/fast_pair_wrapper_impl.h"
#include "internal/platform/logging.h"
namespace nearby {
namespace fastpair {
namespace windows {
static FastPairWrapper *pWrapper_ = nullptr;
void *InitFastPairWrapper() {
FastPairWrapperImpl *pWrapper = new FastPairWrapperImpl();
pWrapper_ = pWrapper;
return pWrapper;
}
void CloseFastPairWrapper(FastPairWrapper *pWrapper) {
NEARBY_LOGS(INFO) << "[[ Closing Fast Pair Wrapper. ]]";
if (pWrapper_ != nullptr) delete pWrapper_;
NEARBY_LOGS(INFO) << "[[ Successfully closed Fast Pair Wrapper. ]]";
}
void __stdcall StartScan(FastPairWrapper *pWrapper) {
NEARBY_LOGS(INFO) << "StartScan is called";
if (pWrapper_ == nullptr) {
NEARBY_LOGS(INFO) << "The pWrapper is a null pointer.";
return;
}
return pWrapper_->StartScan();
}
bool __stdcall IsScanning(FastPairWrapper *pWrapper) {
if (pWrapper_ == nullptr) {
return false;
}
return static_cast<FastPairWrapper *>(pWrapper_)->IsScanning();
}
bool __stdcall IsPairing(FastPairWrapper *pWrapper) {
if (pWrapper_ == nullptr) {
return false;
}
// return connecting
return static_cast<FastPairWrapper *>(pWrapper_)->IsPairing();
}
bool __stdcall IsServerAccessing(FastPairWrapper *pWrapper) {
if (pWrapper_ == nullptr) {
return false;
}
return static_cast<FastPairWrapper *>(pWrapper_)->IsServerAccessing();
}
} // namespace windows
} // namespace fastpair
} // namespace nearby
@@ -12,39 +12,38 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef THIRD_PARTY_NEARBY_FASTPAIR_CLIENT_WINDOWS_FAST_PAIR_CONTROLLER_ADAPTER_H_
#define THIRD_PARTY_NEARBY_FASTPAIR_CLIENT_WINDOWS_FAST_PAIR_CONTROLLER_ADAPTER_H_
#ifndef THIRD_PARTY_NEARBY_FASTPAIR_DART_WINDOWS_FAST_PAIR_WRAPPER_ADAPTER_H_
#define THIRD_PARTY_NEARBY_FASTPAIR_DART_WINDOWS_FAST_PAIR_WRAPPER_ADAPTER_H_
#define DLL_EXPORT extern "C" __declspec(dllexport)
#include "fastpair/fast_pair_controller.h"
#include "fastpair/dart/fast_pair_wrapper.h"
namespace nearby {
namespace fastpair {
namespace windows {
// Initiate a default FastPairController instance.
// Initiate a default FastPairWrapper instance.
// Return the instance handle to client
DLL_EXPORT void *__stdcall InitFastPairController();
DLL_EXPORT void *__stdcall InitFastPairWrapper();
// Closes the controller with stopping all endpoints, then free the memory.
DLL_EXPORT void __stdcall CloseFastPairController(
FastPairController *pController);
// Closes the Wrapper with stopping all endpoints, then free the memory.
DLL_EXPORT void __stdcall CloseFastPairWrapper(FastPairWrapper *pWrapper);
DLL_EXPORT void __stdcall StartScan(FastPairController *pController);
DLL_EXPORT void __stdcall StartScan(FastPairWrapper *pWrapper);
// Obtain scanning status
DLL_EXPORT bool __stdcall IsScanning(FastPairController *pController);
DLL_EXPORT bool __stdcall IsScanning(FastPairWrapper *pWrapper);
// Obtain connecting status
DLL_EXPORT bool __stdcall IsPairing(FastPairController *pController);
DLL_EXPORT bool __stdcall IsPairing(FastPairWrapper *pWrapper);
// Server Access trigger just for adapter implementation testing, will be delete
// after success
DLL_EXPORT bool __stdcall IsServerAccessing(FastPairController *pController);
DLL_EXPORT bool __stdcall IsServerAccessing(FastPairWrapper *pWrapper);
} // namespace windows
} // namespace fastpair
} // namespace nearby
#endif // THIRD_PARTY_NEARBY_FASTPAIR_CLIENT_WINDOWS_FAST_PAIR_CONTROLLER_ADAPTER_H_
#endif // THIRD_PARTY_NEARBY_FASTPAIR_DART_WINDOWS_FAST_PAIR_WRAPPER_ADAPTER_H_
@@ -12,21 +12,21 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "fastpair/client/windows/fast_pair_controller_adapter_dart.h"
#include "fastpair/dart/windows/fast_pair_wrapper_adapter_dart.h"
#include "fastpair/client/windows/fast_pair_controller_adapter.h"
#include "fastpair/dart/windows/fast_pair_wrapper_adapter.h"
namespace nearby {
namespace fastpair {
namespace windows {
void StartScanDart(FastPairController *pController) {
if (IsScanning(pController)) return;
StartScan(pController);
void StartScanDart(FastPairWrapper *pWrapper) {
if (IsScanning(pWrapper)) return;
StartScan(pWrapper);
}
void ServerAccessDart(FastPairController *pController) {
IsServerAccessing(pController);
void ServerAccessDart(FastPairWrapper *pWrapper) {
IsServerAccessing(pWrapper);
}
} // namespace windows
@@ -12,22 +12,22 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef THIRD_PARTY_NEARBY_FASTPAIR_CLIENT_WINDOWS_FAST_PAIR_CONTROLLER_ADAPTER_DART_H_
#define THIRD_PARTY_NEARBY_FASTPAIR_CLIENT_WINDOWS_FAST_PAIR_CONTROLLER_ADAPTER_DART_H_
#ifndef THIRD_PARTY_NEARBY_FASTPAIR_DART_WINDOWS_FAST_PAIR_WRAPPER_ADAPTER_DART_H_
#define THIRD_PARTY_NEARBY_FASTPAIR_DART_WINDOWS_FAST_PAIR_WRAPPER_ADAPTER_DART_H_
#include "third_party/dart_lang/v2/runtime/include/dart_api_dl.h"
#include "fastpair/client/windows/fast_pair_controller_adapter.h"
#include "fastpair/dart/windows/fast_pair_wrapper_adapter.h"
namespace nearby {
namespace fastpair {
namespace windows {
DLL_EXPORT void __stdcall StartScanDart(FastPairController* pController);
DLL_EXPORT void __stdcall StartScanDart(FastPairWrapper* pWrapper);
DLL_EXPORT void __stdcall ServerAccessDart(FastPairController* pController);
DLL_EXPORT void __stdcall ServerAccessDart(FastPairWrapper* pWrapper);
} // namespace windows
} // namespace fastpair
} // namespace nearby
#endif // THIRD_PARTY_NEARBY_FASTPAIR_CLIENT_WINDOWS_FAST_PAIR_CONTROLLER_ADAPTER_DART_H_
#endif // THIRD_PARTY_NEARBY_FASTPAIR_DART_WINDOWS_FAST_PAIR_WRAPPER_ADAPTER_DART_H_