mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 07:36:10 -04:00
Migrate Timer from location/nearby to third_party/nearby
PiperOrigin-RevId: 501928835
This commit is contained in:
committed by
Copybara-Service
parent
868e42f5f2
commit
f94aa7548b
@@ -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",
|
||||
|
||||
@@ -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<DeviceInfo> CreateDeviceInfo();
|
||||
|
||||
// Timer API
|
||||
static std::unique_ptr<Timer> CreateTimer();
|
||||
};
|
||||
|
||||
} // namespace api
|
||||
|
||||
@@ -7,7 +7,6 @@ cc_library(
|
||||
],
|
||||
hdrs = [
|
||||
"device_info.h",
|
||||
"timer.h",
|
||||
],
|
||||
visibility = [
|
||||
"//fastpair:__subpackages__",
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include <memory>
|
||||
|
||||
#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<g3::DeviceInfo>();
|
||||
}
|
||||
|
||||
std::unique_ptr<api::Timer> ImplementationFastPairPlatform::CreateTimer() {
|
||||
return std::make_unique<g3::Timer>();
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
} // namespace nearby
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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<windows::DeviceInfo>();
|
||||
}
|
||||
|
||||
std::unique_ptr<api::Timer> ImplementationFastPairPlatform::CreateTimer() {
|
||||
return std::make_unique<windows::Timer>();
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
} // namespace nearby
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include "absl/random/random.h"
|
||||
#include "fastpair/internal/public/timer_impl.h"
|
||||
#include "internal/platform/timer_impl.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace fastpair {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -34,6 +34,7 @@ cc_library(
|
||||
"settable_future.h",
|
||||
"submittable_executor.h",
|
||||
"system_clock.h",
|
||||
"timer.h",
|
||||
],
|
||||
defines = ["NO_WEBRTC"],
|
||||
visibility = [
|
||||
|
||||
@@ -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",
|
||||
],
|
||||
|
||||
@@ -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<WebResponse> ImplementationPlatform::SendRequest(
|
||||
return absl::UnimplementedError("");
|
||||
}
|
||||
|
||||
// TODO(b/261511529): Add implementation.
|
||||
std::unique_ptr<Timer> ImplementationPlatform::CreateTimer() {
|
||||
return std::make_unique<apple::Timer>();
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
} // namespace nearby
|
||||
|
||||
@@ -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 <functional>
|
||||
#include <utility>
|
||||
|
||||
#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<void()> callback) override;
|
||||
|
||||
bool Stop() override;
|
||||
|
||||
bool FireNow() override;
|
||||
};
|
||||
|
||||
} // namespace apple
|
||||
} // namespace nearby
|
||||
|
||||
#endif
|
||||
#endif // PLATFORM_IMPL_APPLE_TIMER_H_
|
||||
@@ -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 <functional>
|
||||
#include <utility>
|
||||
|
||||
#include "internal/platform/implementation/timer.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace apple {
|
||||
|
||||
bool Timer::Create(int delay, int interval, std::function<void()> callback) { return true; }
|
||||
|
||||
bool Timer::Stop() { return true; }
|
||||
|
||||
bool Timer::FireNow() { return true; }
|
||||
|
||||
} // namespace apple
|
||||
} // namespace nearby
|
||||
@@ -31,6 +31,7 @@ cc_library(
|
||||
"pipe.h",
|
||||
"scheduled_executor.h",
|
||||
"single_thread_executor.h",
|
||||
"timer.h",
|
||||
],
|
||||
defines = ["NO_WEBRTC"],
|
||||
visibility = ["//visibility:private"],
|
||||
|
||||
@@ -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<g3::Mutex*>(mutex)));
|
||||
}
|
||||
|
||||
std::unique_ptr<Timer> ImplementationPlatform::CreateTimer() {
|
||||
return std::make_unique<g3::Timer>();
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
} // namespace nearby
|
||||
|
||||
@@ -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 <functional>
|
||||
#include <utility>
|
||||
|
||||
#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_
|
||||
@@ -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<WifiLanMedium> CreateWifiLanMedium();
|
||||
static std::unique_ptr<WifiHotspotMedium> CreateWifiHotspotMedium();
|
||||
static std::unique_ptr<WifiDirectMedium> CreateWifiDirectMedium();
|
||||
static std::unique_ptr<Timer> CreateTimer();
|
||||
#ifndef NO_WEBRTC
|
||||
static std::unique_ptr<WebRtcMedium> CreateWebRtcMedium();
|
||||
#endif
|
||||
|
||||
@@ -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 <functional>
|
||||
|
||||
@@ -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<void()> 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_
|
||||
@@ -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"],
|
||||
|
||||
@@ -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<WebResponse> ImplementationPlatform::SendRequest(
|
||||
return http_loader.GetResponse();
|
||||
}
|
||||
|
||||
std::unique_ptr<Timer> ImplementationPlatform::CreateTimer() {
|
||||
return std::make_unique<windows::Timer>();
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
} // namespace nearby
|
||||
|
||||
+2
-13
@@ -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 <functional>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "internal/platform/logging.h"
|
||||
|
||||
@@ -35,9 +34,6 @@ bool Timer::Create(int delay, int interval, std::function<void()> 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<void()> 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<WAITORTIMERCALLBACK>(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.";
|
||||
+5
-5
@@ -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 <windows.h>
|
||||
|
||||
#include <functional>
|
||||
|
||||
#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_
|
||||
+9
-7
@@ -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 <chrono> // NOLINT
|
||||
#include <functional> // NOLINT
|
||||
#include <memory>
|
||||
#include <thread> // 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<void()> callback = [&count]() { ++count; };
|
||||
|
||||
std::unique_ptr<api::Timer> timer =
|
||||
api::ImplementationFastPairPlatform::CreateTimer();
|
||||
std::unique_ptr<nearby::api::Timer> 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<void()> callback = [&count]() { count++; };
|
||||
|
||||
std::unique_ptr<api::Timer> timer =
|
||||
api::ImplementationFastPairPlatform::CreateTimer();
|
||||
std::unique_ptr<nearby::api::Timer> 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<void()> 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());
|
||||
@@ -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 <functional>
|
||||
|
||||
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<void()> 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_
|
||||
@@ -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 <functional>
|
||||
#include <utility>
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "internal/platform/logging.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace fastpair {
|
||||
|
||||
bool TimerImpl::Start(int delay, int period, std::function<void()> callback) {
|
||||
if (internal_timer_ != nullptr) {
|
||||
@@ -32,7 +31,7 @@ bool TimerImpl::Start(int delay, int period, std::function<void()> 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
|
||||
@@ -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 <functional>
|
||||
#include <memory>
|
||||
|
||||
#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<api::Timer> internal_timer_ = nullptr;
|
||||
};
|
||||
|
||||
} // namespace fastpair
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_PUBLIC_TIMER_IMPL_H_
|
||||
#endif // PLATFORM_PUBLIC_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,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
|
||||
Reference in New Issue
Block a user