From f94aa7548b95a901be190bde5f9b5149ea0358b8 Mon Sep 17 00:00:00 2001 From: Qin Wang Date: Fri, 13 Jan 2023 13:40:53 -0800 Subject: [PATCH] Migrate Timer from location/nearby to third_party/nearby PiperOrigin-RevId: 501928835 --- Package.swift | 1 + fastpair/internal/api/fast_pair_platform.h | 4 -- fastpair/internal/impl/g3/BUILD | 1 - .../internal/impl/g3/fast_pair_platform.cc | 5 --- fastpair/internal/impl/windows/BUILD | 4 +- .../impl/windows/fast_pair_platform.cc | 5 --- fastpair/internal/public/BUILD | 4 -- fastpair/internal/public/task_runner_impl.cc | 2 +- fastpair/internal/public/task_runner_impl.h | 2 +- internal/platform/BUILD | 5 +++ internal/platform/implementation/BUILD | 1 + internal/platform/implementation/apple/BUILD | 2 + .../platform/implementation/apple/platform.mm | 6 +++ .../platform/implementation/apple/timer.h | 43 +++++++++++++++++++ .../platform/implementation/apple/timer.mm | 32 ++++++++++++++ internal/platform/implementation/g3/BUILD | 1 + .../platform/implementation/g3/platform.cc | 5 +++ .../platform/implementation}/g3/timer.h | 10 ++--- internal/platform/implementation/platform.h | 2 + .../platform/implementation}/timer.h | 21 ++++----- .../platform/implementation/windows/BUILD | 5 +++ .../implementation/windows/platform.cc | 5 +++ .../platform/implementation}/windows/timer.cc | 15 +------ .../platform/implementation}/windows/timer.h | 10 ++--- .../implementation}/windows/timer_test.cc | 16 ++++--- .../public => internal/platform}/timer.h | 31 ++++++------- .../platform}/timer_impl.cc | 8 ++-- .../public => internal/platform}/timer_impl.h | 15 +++---- .../platform}/timer_impl_test.cc | 6 +-- 29 files changed, 165 insertions(+), 102 deletions(-) create mode 100644 internal/platform/implementation/apple/timer.h create mode 100644 internal/platform/implementation/apple/timer.mm rename {fastpair/internal/impl => internal/platform/implementation}/g3/timer.h (84%) rename {fastpair/internal/api => internal/platform/implementation}/timer.h (68%) rename {fastpair/internal/impl => internal/platform/implementation}/windows/timer.cc (81%) rename {fastpair/internal/impl => internal/platform/implementation}/windows/timer.h (80%) rename {fastpair/internal/impl => internal/platform/implementation}/windows/timer_test.cc (80%) rename {fastpair/internal/public => internal/platform}/timer.h (53%) rename {fastpair/internal/public => internal/platform}/timer_impl.cc (88%) rename {fastpair/internal/public => internal/platform}/timer_impl.h (73%) rename {fastpair/internal/public => internal/platform}/timer_impl_test.cc (92%) diff --git a/Package.swift b/Package.swift index 9d6fceb3..f9c990ce 100644 --- a/Package.swift +++ b/Package.swift @@ -491,6 +491,7 @@ let package = Package( "internal/platform/scheduled_executor_test.cc", "internal/platform/count_down_latch_test.cc", "internal/platform/pipe_test.cc", + "internal/platform/timer_impl_test.cc", "internal/platform/uuid_test.cc", "internal/platform/wifi_lan_connection_info_test.cc", "internal/platform/wifi_direct_test.cc", diff --git a/fastpair/internal/api/fast_pair_platform.h b/fastpair/internal/api/fast_pair_platform.h index f7699ea3..8a5f57aa 100644 --- a/fastpair/internal/api/fast_pair_platform.h +++ b/fastpair/internal/api/fast_pair_platform.h @@ -21,7 +21,6 @@ #include "absl/strings/string_view.h" #include "fastpair/internal/api/device_info.h" -#include "fastpair/internal/api/timer.h" namespace nearby { namespace api { @@ -29,9 +28,6 @@ namespace api { class ImplementationFastPairPlatform { public: static std::unique_ptr CreateDeviceInfo(); - - // Timer API - static std::unique_ptr CreateTimer(); }; } // namespace api diff --git a/fastpair/internal/impl/g3/BUILD b/fastpair/internal/impl/g3/BUILD index 3e27aed7..a681651c 100644 --- a/fastpair/internal/impl/g3/BUILD +++ b/fastpair/internal/impl/g3/BUILD @@ -7,7 +7,6 @@ cc_library( ], hdrs = [ "device_info.h", - "timer.h", ], visibility = [ "//fastpair:__subpackages__", diff --git a/fastpair/internal/impl/g3/fast_pair_platform.cc b/fastpair/internal/impl/g3/fast_pair_platform.cc index d50c966e..1dc7fbed 100644 --- a/fastpair/internal/impl/g3/fast_pair_platform.cc +++ b/fastpair/internal/impl/g3/fast_pair_platform.cc @@ -17,7 +17,6 @@ #include #include "fastpair/internal/impl/g3/device_info.h" -#include "fastpair/internal/impl/g3/timer.h" namespace nearby { namespace api { @@ -27,9 +26,5 @@ ImplementationFastPairPlatform::CreateDeviceInfo() { return std::make_unique(); } -std::unique_ptr ImplementationFastPairPlatform::CreateTimer() { - return std::make_unique(); -} - } // namespace api } // namespace nearby diff --git a/fastpair/internal/impl/windows/BUILD b/fastpair/internal/impl/windows/BUILD index cad340ae..de441ceb 100644 --- a/fastpair/internal/impl/windows/BUILD +++ b/fastpair/internal/impl/windows/BUILD @@ -29,13 +29,11 @@ cc_library( "ble_gatt_client.cc", "device_info.cc", "fast_pair_platform.cc", - "timer.cc", "utils.cc", ], hdrs = [ "ble_gatt_client.h", "device_info.h", - "timer.h", "utils.h", ], copts = [ @@ -63,7 +61,6 @@ cc_test( timeout = "short", srcs = [ "device_info_test.cc", - "timer_test.cc", ], copts = [ "-Ithird_party/nearby/internal/platform/implementation/windows/generated", @@ -75,6 +72,7 @@ cc_test( "//fastpair/internal/api:platform", "//internal/platform:base", "//internal/platform:logging", + "//internal/platform/implementation:types", "//internal/platform/implementation/windows", "//internal/platform/implementation/windows/generated:types", "@com_github_protobuf_matchers//protobuf-matchers", diff --git a/fastpair/internal/impl/windows/fast_pair_platform.cc b/fastpair/internal/impl/windows/fast_pair_platform.cc index f7f217eb..170356e8 100644 --- a/fastpair/internal/impl/windows/fast_pair_platform.cc +++ b/fastpair/internal/impl/windows/fast_pair_platform.cc @@ -20,7 +20,6 @@ #include "absl/strings/string_view.h" #include "fastpair/internal/impl/windows/device_info.h" -#include "fastpair/internal/impl/windows/timer.h" namespace nearby { namespace api { @@ -30,9 +29,5 @@ ImplementationFastPairPlatform::CreateDeviceInfo() { return std::make_unique(); } -std::unique_ptr ImplementationFastPairPlatform::CreateTimer() { - return std::make_unique(); -} - } // namespace api } // namespace nearby diff --git a/fastpair/internal/public/BUILD b/fastpair/internal/public/BUILD index 9f561a84..f74a3d79 100644 --- a/fastpair/internal/public/BUILD +++ b/fastpair/internal/public/BUILD @@ -5,7 +5,6 @@ cc_library( hdrs = [ "device_info.h", "task_runner.h", - "timer.h", ], visibility = ["//fastpair:__subpackages__"], deps = [ @@ -21,11 +20,9 @@ cc_library( name = "fastpair_context", srcs = [ "task_runner_impl.cc", - "timer_impl.cc", ], hdrs = [ "task_runner_impl.h", - "timer_impl.h", ], visibility = ["//fastpair:__subpackages__"], deps = [ @@ -65,7 +62,6 @@ cc_test( timeout = "short", srcs = [ "task_runner_impl_test.cc", - "timer_impl_test.cc", ], shard_count = 8, deps = [ diff --git a/fastpair/internal/public/task_runner_impl.cc b/fastpair/internal/public/task_runner_impl.cc index effd8e6a..cc23bc97 100644 --- a/fastpair/internal/public/task_runner_impl.cc +++ b/fastpair/internal/public/task_runner_impl.cc @@ -21,7 +21,7 @@ #include #include "absl/random/random.h" -#include "fastpair/internal/public/timer_impl.h" +#include "internal/platform/timer_impl.h" namespace nearby { namespace fastpair { diff --git a/fastpair/internal/public/task_runner_impl.h b/fastpair/internal/public/task_runner_impl.h index a4bb1e8e..cc7631b2 100644 --- a/fastpair/internal/public/task_runner_impl.h +++ b/fastpair/internal/public/task_runner_impl.h @@ -23,8 +23,8 @@ #include "absl/container/flat_hash_map.h" #include "absl/synchronization/mutex.h" #include "fastpair/internal/public/task_runner.h" -#include "fastpair/internal/public/timer.h" #include "internal/platform/multi_thread_executor.h" +#include "internal/platform/timer.h" namespace nearby { namespace fastpair { diff --git a/internal/platform/BUILD b/internal/platform/BUILD index 780b29ee..38aecb73 100644 --- a/internal/platform/BUILD +++ b/internal/platform/BUILD @@ -305,6 +305,7 @@ cc_library( "monitored_runnable.cc", "pending_job_registry.cc", "pipe.cc", + "timer_impl.cc", ], hdrs = [ "atomic_boolean.h", @@ -334,6 +335,8 @@ cc_library( "system_clock.h", "thread_check_callable.h", "thread_check_runnable.h", + "timer.h", + "timer_impl.h", ], defines = ["NO_WEBRTC"], visibility = [ @@ -341,6 +344,7 @@ cc_library( "//fastpair:__subpackages__", "//internal/platform/implementation/windows:__subpackages__", "//location/nearby/cpp/fastpair:__subpackages__", + "//location/nearby/testing/nearby_native:__subpackages__", "//presence:__subpackages__", ], deps = [ @@ -436,6 +440,7 @@ cc_test( "pipe_test.cc", "scheduled_executor_test.cc", "single_thread_executor_test.cc", + "timer_impl_test.cc", "uuid_test.cc", "wifi_direct_test.cc", "wifi_hotspot_test.cc", diff --git a/internal/platform/implementation/BUILD b/internal/platform/implementation/BUILD index 169ca97e..e0f29748 100644 --- a/internal/platform/implementation/BUILD +++ b/internal/platform/implementation/BUILD @@ -34,6 +34,7 @@ cc_library( "settable_future.h", "submittable_executor.h", "system_clock.h", + "timer.h", ], defines = ["NO_WEBRTC"], visibility = [ diff --git a/internal/platform/implementation/apple/BUILD b/internal/platform/implementation/apple/BUILD index 270606b2..4d8025dd 100644 --- a/internal/platform/implementation/apple/BUILD +++ b/internal/platform/implementation/apple/BUILD @@ -30,6 +30,7 @@ objc_library( "multi_thread_executor.mm", "platform.mm", "scheduled_executor.mm", + "timer.mm", "utils.mm", "wifi_lan.mm", ], @@ -40,6 +41,7 @@ objc_library( "multi_thread_executor.h", "scheduled_executor.h", "single_thread_executor.h", + "timer.h", "utils.h", "wifi_lan.h", ], diff --git a/internal/platform/implementation/apple/platform.mm b/internal/platform/implementation/apple/platform.mm index ce494b62..7e4bb715 100644 --- a/internal/platform/implementation/apple/platform.mm +++ b/internal/platform/implementation/apple/platform.mm @@ -27,6 +27,7 @@ #include "internal/platform/implementation/apple/mutex.h" #import "internal/platform/implementation/apple/scheduled_executor.h" #import "internal/platform/implementation/apple/single_thread_executor.h" +#include "internal/platform/implementation/apple/timer.h" #import "internal/platform/implementation/apple/utils.h" #include "internal/platform/implementation/apple/wifi_lan.h" #include "internal/platform/implementation/mutex.h" @@ -176,5 +177,10 @@ absl::StatusOr ImplementationPlatform::SendRequest( return absl::UnimplementedError(""); } +// TODO(b/261511529): Add implementation. +std::unique_ptr ImplementationPlatform::CreateTimer() { + return std::make_unique(); +} + } // namespace api } // namespace nearby diff --git a/internal/platform/implementation/apple/timer.h b/internal/platform/implementation/apple/timer.h new file mode 100644 index 00000000..c53f4493 --- /dev/null +++ b/internal/platform/implementation/apple/timer.h @@ -0,0 +1,43 @@ +// Copyright 2021 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 PLATFORM_IMPL_APPLE_TIMER_H_ +#define PLATFORM_IMPL_APPLE_TIMER_H_ +#ifdef __cplusplus + +#include +#include + +#include "internal/platform/implementation/timer.h" + +namespace nearby { +namespace apple { + +class Timer : public api::Timer { + public: + Timer() = default; + ~Timer() override = default; + + bool Create(int delay, int interval, std::function callback) override; + + bool Stop() override; + + bool FireNow() override; +}; + +} // namespace apple +} // namespace nearby + +#endif +#endif // PLATFORM_IMPL_APPLE_TIMER_H_ diff --git a/internal/platform/implementation/apple/timer.mm b/internal/platform/implementation/apple/timer.mm new file mode 100644 index 00000000..7af7a432 --- /dev/null +++ b/internal/platform/implementation/apple/timer.mm @@ -0,0 +1,32 @@ +// Copyright 2021 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. + +#import "internal/platform/implementation/apple/timer.h" + +#include +#include + +#include "internal/platform/implementation/timer.h" + +namespace nearby { +namespace apple { + +bool Timer::Create(int delay, int interval, std::function callback) { return true; } + +bool Timer::Stop() { return true; } + +bool Timer::FireNow() { return true; } + +} // namespace apple +} // namespace nearby diff --git a/internal/platform/implementation/g3/BUILD b/internal/platform/implementation/g3/BUILD index a00c416f..7c3008bf 100644 --- a/internal/platform/implementation/g3/BUILD +++ b/internal/platform/implementation/g3/BUILD @@ -31,6 +31,7 @@ cc_library( "pipe.h", "scheduled_executor.h", "single_thread_executor.h", + "timer.h", ], defines = ["NO_WEBRTC"], visibility = ["//visibility:private"], diff --git a/internal/platform/implementation/g3/platform.cc b/internal/platform/implementation/g3/platform.cc index 2dc4b19c..d092d233 100644 --- a/internal/platform/implementation/g3/platform.cc +++ b/internal/platform/implementation/g3/platform.cc @@ -53,6 +53,7 @@ #include "internal/platform/implementation/g3/mutex.h" #include "internal/platform/implementation/g3/scheduled_executor.h" #include "internal/platform/implementation/g3/single_thread_executor.h" +#include "internal/platform/implementation/g3/timer.h" #include "internal/platform/implementation/g3/wifi.h" #include "internal/platform/implementation/g3/wifi_direct.h" #include "internal/platform/implementation/g3/wifi_hotspot.h" @@ -224,5 +225,9 @@ ImplementationPlatform::CreateConditionVariable(Mutex* mutex) { new g3::ConditionVariable(static_cast(mutex))); } +std::unique_ptr ImplementationPlatform::CreateTimer() { + return std::make_unique(); +} + } // namespace api } // namespace nearby diff --git a/fastpair/internal/impl/g3/timer.h b/internal/platform/implementation/g3/timer.h similarity index 84% rename from fastpair/internal/impl/g3/timer.h rename to internal/platform/implementation/g3/timer.h index 1ca6d5f8..6ca9ae74 100644 --- a/fastpair/internal/impl/g3/timer.h +++ b/internal/platform/implementation/g3/timer.h @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2021 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_IMPL_G3_TIMER_H_ -#define THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_IMPL_G3_TIMER_H_ +#ifndef PLATFORM_IMPL_G3_TIMER_H_ +#define PLATFORM_IMPL_G3_TIMER_H_ #include #include -#include "fastpair/internal/api/timer.h" +#include "internal/platform/implementation/timer.h" namespace nearby { namespace g3 { @@ -68,4 +68,4 @@ class Timer : public api::Timer { } // namespace g3 } // namespace nearby -#endif // THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_IMPL_G3_TIMER_H_ +#endif // PLATFORM_IMPL_G3_TIMER_H_ diff --git a/internal/platform/implementation/platform.h b/internal/platform/implementation/platform.h index 9fda07a5..1e6e0028 100644 --- a/internal/platform/implementation/platform.h +++ b/internal/platform/implementation/platform.h @@ -41,6 +41,7 @@ #include "internal/platform/implementation/settable_future.h" #include "internal/platform/implementation/submittable_executor.h" #include "internal/platform/implementation/system_clock.h" +#include "internal/platform/implementation/timer.h" #ifndef NO_WEBRTC #include "internal/platform/implementation/webrtc.h" #endif @@ -128,6 +129,7 @@ class ImplementationPlatform { static std::unique_ptr CreateWifiLanMedium(); static std::unique_ptr CreateWifiHotspotMedium(); static std::unique_ptr CreateWifiDirectMedium(); + static std::unique_ptr CreateTimer(); #ifndef NO_WEBRTC static std::unique_ptr CreateWebRtcMedium(); #endif diff --git a/fastpair/internal/api/timer.h b/internal/platform/implementation/timer.h similarity index 68% rename from fastpair/internal/api/timer.h rename to internal/platform/implementation/timer.h index c154987f..8abbb537 100644 --- a/fastpair/internal/api/timer.h +++ b/internal/platform/implementation/timer.h @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2021 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef LOCATION_NEARBY_CPP_FASTPAIR_INTERNAL_API_TIMER_H_ -#define LOCATION_NEARBY_CPP_FASTPAIR_INTERNAL_API_TIMER_H_ +#ifndef PLATFORM_API_TIMER_H_ +#define PLATFORM_API_TIMER_H_ #include @@ -26,17 +26,14 @@ class Timer { // Creates a timer based on interval. // - // @param delay - // The amount of time in milliseconds relative to the current + // @param delay The amount of time in milliseconds relative to the current // time that must elapse before the timer is signaled for the first // time. - // @param interval - // The period of the timer, in milliseconds. If this parameter + // @param interval The period of the timer, in milliseconds. If this parameter // is zero, the timer is signaled once. - // @param callback - // It will be called when timer signaled. - // @return - // return true if success, otherwise false + // @param callback it will be called when timer signaled. + // + // @return return true if success, otherwise false virtual bool Create(int delay, int interval, std::function callback) = 0; @@ -48,4 +45,4 @@ class Timer { } // namespace api } // namespace nearby -#endif // LOCATION_NEARBY_CPP_FASTPAIR_INTERNAL_API_TIMER_H_ +#endif // PLATFORM_API_TIMER_H_ diff --git a/internal/platform/implementation/windows/BUILD b/internal/platform/implementation/windows/BUILD index c6160ab1..dff4f894 100644 --- a/internal/platform/implementation/windows/BUILD +++ b/internal/platform/implementation/windows/BUILD @@ -17,6 +17,7 @@ cc_library( name = "types", srcs = [ "log_message.cc", + "timer.cc", ], hdrs = [ "atomic_boolean.h", @@ -33,13 +34,16 @@ cc_library( "scheduled_executor.h", "settable_future.h", "submittable_executor.h", + "timer.h", "utils.h", ], deps = [ "//base", "//base:stringprintf", "//internal/platform:base", + "//internal/platform:logging", "//internal/platform/implementation:types", + "//internal/platform/implementation/windows/generated:types", ], ) @@ -221,6 +225,7 @@ cc_test( "scheduled_executor_test.cc", "submittable_executor_test.cc", "thread_pool_test.cc", + "timer_test.cc", "utils_test.cc", ], copts = ["-Ithird_party/nearby/internal/platform/implementation/windows/generated -DCORE_ADAPTER_DLL"], diff --git a/internal/platform/implementation/windows/platform.cc b/internal/platform/implementation/windows/platform.cc index 7a4a28b0..3400c77c 100644 --- a/internal/platform/implementation/windows/platform.cc +++ b/internal/platform/implementation/windows/platform.cc @@ -56,6 +56,7 @@ #include "internal/platform/implementation/windows/server_sync.h" #include "internal/platform/implementation/windows/settable_future.h" #include "internal/platform/implementation/windows/submittable_executor.h" +#include "internal/platform/implementation/windows/timer.h" #include "internal/platform/implementation/windows/utils.h" #include "internal/platform/implementation/windows/webrtc.h" #include "internal/platform/implementation/windows/wifi.h" @@ -307,5 +308,9 @@ absl::StatusOr ImplementationPlatform::SendRequest( return http_loader.GetResponse(); } +std::unique_ptr ImplementationPlatform::CreateTimer() { + return std::make_unique(); +} + } // namespace api } // namespace nearby diff --git a/fastpair/internal/impl/windows/timer.cc b/internal/platform/implementation/windows/timer.cc similarity index 81% rename from fastpair/internal/impl/windows/timer.cc rename to internal/platform/implementation/windows/timer.cc index 5260add2..992a76d6 100644 --- a/fastpair/internal/impl/windows/timer.cc +++ b/internal/platform/implementation/windows/timer.cc @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2021 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,11 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastpair/internal/impl/windows/timer.h" +#include "internal/platform/implementation/windows/timer.h" #include #include -#include #include "internal/platform/logging.h" @@ -35,9 +34,6 @@ bool Timer::Create(int delay, int interval, std::function callback) { return false; } - // Creates a queue for timers. - // If succeeds, return a handle to the timer queue. - // If fails, the return value is NULL. timer_queue_handle_ = CreateTimerQueue(); if (timer_queue_handle_ == nullptr) { NEARBY_LOGS(ERROR) << "Failed to create timer queue."; @@ -48,14 +44,9 @@ bool Timer::Create(int delay, int interval, std::function callback) { interval_ = interval; callback_ = std::move(callback); - // Creates a timer-queue timer. This timer expires at the specified due time, - // then after every specified period. When the timer expires, - // the callback function is called. if (!CreateTimerQueueTimer(&handle_, timer_queue_handle_, static_cast(TimerRoutine), &callback_, delay, interval, WT_EXECUTEDEFAULT)) { - // Deletes a timer queue. - // Any pending timers in the queue are canceled and deleted. if (!DeleteTimerQueueEx(timer_queue_handle_, nullptr)) { NEARBY_LOGS(ERROR) << "Failed to create timer in timer queue."; } @@ -71,8 +62,6 @@ bool Timer::Stop() { return true; } - // Deletes a timer queue. - // Any pending timers in the queue are canceled and deleted. if (!DeleteTimerQueueTimer(timer_queue_handle_, handle_, nullptr)) { if (GetLastError() != ERROR_IO_PENDING) { NEARBY_LOGS(ERROR) << "Failed to delete timer from timer queue."; diff --git a/fastpair/internal/impl/windows/timer.h b/internal/platform/implementation/windows/timer.h similarity index 80% rename from fastpair/internal/impl/windows/timer.h rename to internal/platform/implementation/windows/timer.h index 76937ac8..993f7bdf 100644 --- a/fastpair/internal/impl/windows/timer.h +++ b/internal/platform/implementation/windows/timer.h @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2021 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_IMPL_WINDOWS_TIMER_H_ -#define THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_IMPL_WINDOWS_TIMER_H_ +#ifndef PLATFORM_IMPL_WINDOWS_TIMER_H_ +#define PLATFORM_IMPL_WINDOWS_TIMER_H_ #include #include -#include "fastpair/internal/api/timer.h" +#include "internal/platform/implementation/timer.h" namespace nearby { namespace windows { @@ -46,4 +46,4 @@ class Timer : public api::Timer { } // namespace windows } // namespace nearby -#endif // THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_IMPL_WINDOWS_TIMER_H_ +#endif // PLATFORM_IMPL_WINDOWS_TIMER_H_ diff --git a/fastpair/internal/impl/windows/timer_test.cc b/internal/platform/implementation/windows/timer_test.cc similarity index 80% rename from fastpair/internal/impl/windows/timer_test.cc rename to internal/platform/implementation/windows/timer_test.cc index 29278bbb..dd118c03 100644 --- a/fastpair/internal/impl/windows/timer_test.cc +++ b/internal/platform/implementation/windows/timer_test.cc @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2021 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,13 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "internal/platform/implementation/timer.h" + #include // NOLINT #include // NOLINT #include #include // NOLINT #include "gtest/gtest.h" -#include "fastpair/internal/api/fast_pair_platform.h" +#include "internal/platform/implementation/platform.h" namespace nearby { namespace windows { @@ -28,8 +30,8 @@ TEST(Timer, TestCreateTimer) { int count = 0; std::function callback = [&count]() { ++count; }; - std::unique_ptr timer = - api::ImplementationFastPairPlatform::CreateTimer(); + std::unique_ptr timer = + nearby::api::ImplementationPlatform::CreateTimer(); ASSERT_TRUE(timer != nullptr); EXPECT_FALSE(timer->Create(-100, 0, callback)); @@ -41,8 +43,8 @@ TEST(Timer, DISABLED_TestRepeatTimer) { int count = 0; std::function callback = [&count]() { count++; }; - std::unique_ptr timer = - api::ImplementationFastPairPlatform::CreateTimer(); + std::unique_ptr timer = + nearby::api::ImplementationPlatform::CreateTimer(); ASSERT_TRUE(timer != nullptr); EXPECT_TRUE(timer->Create(300, 300, callback)); @@ -54,7 +56,7 @@ TEST(Timer, DISABLED_TestRepeatTimer) { TEST(Timer, DISABLED_TestFireNow) { int count = 0; std::function callback = [&count]() { ++count; }; - auto timer = api::ImplementationFastPairPlatform::CreateTimer(); + auto timer = nearby::api::ImplementationPlatform::CreateTimer(); EXPECT_TRUE(timer != nullptr); EXPECT_TRUE(timer->Create(3000, 3000, callback)); EXPECT_TRUE(timer->FireNow()); diff --git a/fastpair/internal/public/timer.h b/internal/platform/timer.h similarity index 53% rename from fastpair/internal/public/timer.h rename to internal/platform/timer.h index 3f9c29d0..db142fc2 100644 --- a/fastpair/internal/public/timer.h +++ b/internal/platform/timer.h @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2021 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,38 +12,33 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_PUBLIC_TIMER_H_ -#define THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_PUBLIC_TIMER_H_ +#ifndef PLATFORM_PUBLIC_TIMER_H_ +#define PLATFORM_PUBLIC_TIMER_H_ #include namespace nearby { -namespace fastpair { - class Timer { public: virtual ~Timer() = default; // Starts the timer. // - // @param delay - // The amount of time in milliseconds relative to the current time that must - // elapse before the timer is signaled for the first time. - // @param period - // The period of the timer, in milliseconds. - // If this parameter is zero, the timer is signaled once. - // If this parameter is greater than zero, the timer is periodic. - // @param callback - // The callback is called when timer is signaled - // @return - // Returns true if succeed, otherwise false is returned. + // @param delay The amount of time in milliseconds relative to the current + // time that must elapse before the timer is signaled for the first + // time. + // @param period The period of the timer, in milliseconds. If this parameter + // is zero, the timer is signaled once. If this parameter is greater + // than zero, the timer is periodic. + // @param callback The callback is called when timer is signaled + // + // @return Returns true if succeed, otherwise false is returned. virtual bool Start(int delay, int period, std::function callback) = 0; virtual bool Stop() = 0; virtual bool IsRunning() = 0; virtual bool FireNow() = 0; }; -} // namespace fastpair } // namespace nearby -#endif // THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_PUBLIC_TIMER_H_ +#endif // PLATFORM_PUBLIC_TIMER_H_ diff --git a/fastpair/internal/public/timer_impl.cc b/internal/platform/timer_impl.cc similarity index 88% rename from fastpair/internal/public/timer_impl.cc rename to internal/platform/timer_impl.cc index 7482ac00..2c27d178 100644 --- a/fastpair/internal/public/timer_impl.cc +++ b/internal/platform/timer_impl.cc @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2021 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastpair/internal/public/timer_impl.h" +#include "internal/platform/timer_impl.h" #include #include @@ -21,7 +21,6 @@ #include "internal/platform/logging.h" namespace nearby { -namespace fastpair { bool TimerImpl::Start(int delay, int period, std::function callback) { if (internal_timer_ != nullptr) { @@ -32,7 +31,7 @@ bool TimerImpl::Start(int delay, int period, std::function callback) { delay_ = delay; period_ = period; callback_ = std::move(callback); - internal_timer_ = api::ImplementationFastPairPlatform::CreateTimer(); + internal_timer_ = api::ImplementationPlatform::CreateTimer(); if (!internal_timer_->Create(delay, period, callback_)) { NEARBY_LOGS(INFO) << "Failed to create timer."; internal_timer_ = nullptr; @@ -62,5 +61,4 @@ bool TimerImpl::FireNow() { return false; } -} // namespace fastpair } // namespace nearby diff --git a/fastpair/internal/public/timer_impl.h b/internal/platform/timer_impl.h similarity index 73% rename from fastpair/internal/public/timer_impl.h rename to internal/platform/timer_impl.h index 74c9b3ad..6694c5b6 100644 --- a/fastpair/internal/public/timer_impl.h +++ b/internal/platform/timer_impl.h @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2021 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,18 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_PUBLIC_TIMER_IMPL_H_ -#define THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_PUBLIC_TIMER_IMPL_H_ +#ifndef PLATFORM_PUBLIC_TIMER_IMPL_H_ +#define PLATFORM_PUBLIC_TIMER_IMPL_H_ #include #include -#include "fastpair/internal/api/fast_pair_platform.h" -#include "fastpair/internal/public/timer.h" +#include "internal/platform/implementation/platform.h" +#include "internal/platform/timer.h" namespace nearby { -namespace fastpair { - class TimerImpl : public Timer { public: ~TimerImpl() override { Stop(); } @@ -40,7 +38,6 @@ class TimerImpl : public Timer { std::unique_ptr internal_timer_ = nullptr; }; -} // namespace fastpair } // namespace nearby -#endif // THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_PUBLIC_TIMER_IMPL_H_ +#endif // PLATFORM_PUBLIC_TIMER_IMPL_H_ diff --git a/fastpair/internal/public/timer_impl_test.cc b/internal/platform/timer_impl_test.cc similarity index 92% rename from fastpair/internal/public/timer_impl_test.cc rename to internal/platform/timer_impl_test.cc index 984a6ecc..a79c8a4b 100644 --- a/fastpair/internal/public/timer_impl_test.cc +++ b/internal/platform/timer_impl_test.cc @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2021 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,12 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastpair/internal/public/timer_impl.h" +#include "internal/platform/timer_impl.h" #include "gtest/gtest.h" namespace nearby { -namespace fastpair { namespace { TEST(TimerImpl, TestCreateTimer) { @@ -56,5 +55,4 @@ TEST(TimerImpl, TestFireNow) { } } // namespace -} // namespace fastpair } // namespace nearby