From f8669cf16d688aea469b5aa6962a99d21784333b Mon Sep 17 00:00:00 2001 From: Guogang Li Date: Tue, 3 Sep 2024 14:47:46 -0700 Subject: [PATCH] Clean up logging implementations PiperOrigin-RevId: 670714192 --- internal/platform/implementation/apple/BUILD | 5 +- .../implementation/apple/count_down_latch.cc | 3 + .../implementation/apple/count_down_latch.h | 3 + .../apple/count_down_latch_test.cc | 9 +- .../implementation/apple/log_message.h | 65 ---------- .../implementation/apple/log_message.mm | 117 ------------------ .../platform/implementation/apple/platform.mm | 6 - internal/platform/implementation/g3/BUILD | 8 +- .../platform/implementation/g3/log_message.cc | 84 ------------- .../platform/implementation/g3/log_message.h | 42 ------- .../platform/implementation/g3/platform.cc | 23 +++- .../platform/implementation/windows/BUILD | 4 - .../implementation/windows/log_message.cc | 75 ----------- .../implementation/windows/log_message.h | 44 ------- .../implementation/windows/platform.cc | 27 ++-- 15 files changed, 60 insertions(+), 455 deletions(-) delete mode 100644 internal/platform/implementation/apple/log_message.h delete mode 100644 internal/platform/implementation/apple/log_message.mm delete mode 100644 internal/platform/implementation/g3/log_message.cc delete mode 100644 internal/platform/implementation/g3/log_message.h delete mode 100644 internal/platform/implementation/windows/log_message.cc delete mode 100644 internal/platform/implementation/windows/log_message.h diff --git a/internal/platform/implementation/apple/BUILD b/internal/platform/implementation/apple/BUILD index 4ab088e7..14912f31 100644 --- a/internal/platform/implementation/apple/BUILD +++ b/internal/platform/implementation/apple/BUILD @@ -25,7 +25,6 @@ objc_library( srcs = [ "crypto.mm", "device_info.mm", - "log_message.mm", "multi_thread_executor.mm", "platform.mm", "preferences_manager.mm", @@ -35,7 +34,6 @@ objc_library( ], hdrs = [ "device_info.h", - "log_message.h", "multi_thread_executor.h", "preferences_manager.h", "scheduled_executor.h", @@ -150,8 +148,10 @@ cc_library( "mutex.h", ], deps = [ + "//internal/platform:base", "//internal/platform/implementation:platform", "//internal/platform/implementation:types", + "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/synchronization", "@com_google_absl//absl/time", @@ -170,6 +170,7 @@ cc_test( shard_count = 16, deps = [ ":Platform_cc", + "//internal/platform/implementation/g3:crypto", "@com_github_protobuf_matchers//protobuf-matchers", "@com_google_absl//absl/synchronization", "@com_google_absl//absl/time", diff --git a/internal/platform/implementation/apple/count_down_latch.cc b/internal/platform/implementation/apple/count_down_latch.cc index e081e9a9..98c8de8f 100644 --- a/internal/platform/implementation/apple/count_down_latch.cc +++ b/internal/platform/implementation/apple/count_down_latch.cc @@ -13,6 +13,9 @@ // limitations under the License. #include "internal/platform/implementation/apple/count_down_latch.h" +#include "absl/synchronization/mutex.h" +#include "absl/time/time.h" +#include "internal/platform/exception.h" namespace nearby { namespace apple { diff --git a/internal/platform/implementation/apple/count_down_latch.h b/internal/platform/implementation/apple/count_down_latch.h index 7504df19..ff54ca77 100644 --- a/internal/platform/implementation/apple/count_down_latch.h +++ b/internal/platform/implementation/apple/count_down_latch.h @@ -15,7 +15,10 @@ #ifndef PLATFORM_IMPL_APPLE_COUNT_DOWN_LATCH_H_ #define PLATFORM_IMPL_APPLE_COUNT_DOWN_LATCH_H_ +#include "absl/base/thread_annotations.h" #include "absl/synchronization/mutex.h" +#include "absl/time/time.h" +#include "internal/platform/exception.h" #include "internal/platform/implementation/count_down_latch.h" namespace nearby { diff --git a/internal/platform/implementation/apple/count_down_latch_test.cc b/internal/platform/implementation/apple/count_down_latch_test.cc index 50012813..77b655be 100644 --- a/internal/platform/implementation/apple/count_down_latch_test.cc +++ b/internal/platform/implementation/apple/count_down_latch_test.cc @@ -14,7 +14,10 @@ #include "internal/platform/implementation/apple/count_down_latch.h" +#include + #include "gtest/gtest.h" +#include "absl/time/time.h" #include "thread/fiber/fiber.h" namespace nearby { @@ -56,11 +59,11 @@ TEST(CountDownLatchTest, LatchAwaitWithTimeoutCanExpire) { auto response = latch.Await(absl::Milliseconds(100)); - EXPECT_TRUE(response.ok()); + EXPECT_FALSE(response.ok()); EXPECT_FALSE(response.result()); } -TEST(CountDownLatchTest, InitialCountZero_AwaitDoesNotBlock) { +TEST(CountDownLatchTest, InitialCountZeroAwaitDoesNotBlock) { CountDownLatch latch(0); auto response = latch.Await(); @@ -68,7 +71,7 @@ TEST(CountDownLatchTest, InitialCountZero_AwaitDoesNotBlock) { EXPECT_TRUE(response.Ok()); } -TEST(CountDownLatchTest, InitialCountNegative_AwaitDoesNotBlock) { +TEST(CountDownLatchTest, InitialCountNegativeAwaitDoesNotBlock) { CountDownLatch latch(-1); auto response = latch.Await(); diff --git a/internal/platform/implementation/apple/log_message.h b/internal/platform/implementation/apple/log_message.h deleted file mode 100644 index 3cc117fb..00000000 --- a/internal/platform/implementation/apple/log_message.h +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2020 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_LOG_MESSAGE_H_ -#define PLATFORM_IMPL_APPLE_LOG_MESSAGE_H_ - -#include -#include -#include - -#include "absl/strings/string_view.h" -#include "internal/platform/implementation/log_message.h" -#include "GoogleToolboxForMac/GTMLogger.h" - -namespace nearby { -namespace apple { - -class LogStreamer final { - public: - explicit LogStreamer(GTMLoggerLevel severity, absl::string_view func); - - ~LogStreamer(); - - std::ostream& stream() { return stream_; } - - private: - GTMLoggerLevel severity_; - std::string func_; - std::ostringstream stream_; -}; - -// Concrete LogMessage implementation -class LogMessage : public api::LogMessage { - public: - LogMessage(const char* file, int line, Severity severity); - ~LogMessage() override = default; - - LogMessage(const LogMessage&) = delete; - LogMessage& operator=(const LogMessage&) = delete; - - void Print(const char* format, ...) override; - - std::ostream& Stream() override; - - private: - LogStreamer log_streamer_; - GTMLoggerLevel severity_; - std::string func_; -}; - -} // namespace apple -} // namespace nearby - -#endif // PLATFORM_IMPL_APPLE_LOG_MESSAGE_H_ diff --git a/internal/platform/implementation/apple/log_message.mm b/internal/platform/implementation/apple/log_message.mm deleted file mode 100644 index afb5afba..00000000 --- a/internal/platform/implementation/apple/log_message.mm +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2020 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 "internal/platform/implementation/apple/log_message.h" - -#include -#include - -#include "internal/platform/implementation/log_message.h" - -namespace nearby { -namespace apple { - -api::LogMessage::Severity gMinLogSeverity = api::LogMessage::Severity::kInfo; - -GTMLoggerLevel ConvertSeverity(api::LogMessage::Severity severity) { - switch (severity) { - case api::LogMessage::Severity::kVerbose: - return kGTMLoggerLevelDebug; - case api::LogMessage::Severity::kInfo: - return kGTMLoggerLevelInfo; - case api::LogMessage::Severity::kWarning: - return kGTMLoggerLevelInfo; - case api::LogMessage::Severity::kError: - return kGTMLoggerLevelError; - case api::LogMessage::Severity::kFatal: - return kGTMLoggerLevelAssert; - } -} - -// GTMLogger expects a function name, but we only have file and line. So format the info as -// {basename(file)}:{line} and use that as the function name. -std::string ConvertFileAndLine(absl::string_view filepath, int line) { - size_t path = filepath.find_last_of('/'); - if (path != filepath.npos) filepath.remove_prefix(path + 1); - return std::string(filepath) + ":" + std::to_string(line); -} - -LogStreamer::LogStreamer(GTMLoggerLevel severity, absl::string_view func) - : severity_(severity), func_(func) {} - -LogStreamer::~LogStreamer() { - switch (severity_) { - case kGTMLoggerLevelDebug: - [[GTMLogger sharedLogger] logFuncDebug:func_.c_str() msg:@"%@", @(stream_.str().c_str())]; - break; - case kGTMLoggerLevelInfo: - [[GTMLogger sharedLogger] logFuncInfo:func_.c_str() msg:@"%@", @(stream_.str().c_str())]; - break; - case kGTMLoggerLevelError: - [[GTMLogger sharedLogger] logFuncError:func_.c_str() msg:@"%@", @(stream_.str().c_str())]; - break; - case kGTMLoggerLevelAssert: - [[GTMLogger sharedLogger] logFuncAssert:func_.c_str() msg:@"%@", @(stream_.str().c_str())]; - break; - case kGTMLoggerLevelUnknown: - // no-op - break; - } -} - -LogMessage::LogMessage(const char* file, int line, Severity severity) - : log_streamer_(ConvertSeverity(severity), ConvertFileAndLine(file, line)), - severity_(ConvertSeverity(severity)), - func_(ConvertFileAndLine(file, line)) {} - -void LogMessage::Print(const char* format, ...) { - va_list ap; - va_start(ap, format); - NSString *msg = [[NSString alloc] initWithFormat:@(format) arguments:ap]; - switch (severity_) { - case kGTMLoggerLevelDebug: - [[GTMLogger sharedLogger] logFuncDebug:func_.c_str() msg:@"%@", msg]; - break; - case kGTMLoggerLevelInfo: - [[GTMLogger sharedLogger] logFuncInfo:func_.c_str() msg:@"%@", msg]; - break; - case kGTMLoggerLevelError: - [[GTMLogger sharedLogger] logFuncError:func_.c_str() msg:@"%@", msg]; - break; - case kGTMLoggerLevelAssert: - [[GTMLogger sharedLogger] logFuncAssert:func_.c_str() msg:@"%@", msg]; - break; - case kGTMLoggerLevelUnknown: - // no-op - break; - } - va_end(ap); -} - -std::ostream& LogMessage::Stream() { return log_streamer_.stream(); } - -} // namespace apple - -namespace api { - -// static -void LogMessage::SetMinLogSeverity(Severity severity) { apple::gMinLogSeverity = severity; } - -// static -bool LogMessage::ShouldCreateLogMessage(Severity severity) { - return severity >= apple::gMinLogSeverity; -} - -} // namespace api -} // namespace nearby diff --git a/internal/platform/implementation/apple/platform.mm b/internal/platform/implementation/apple/platform.mm index 781a50ea..74120b2e 100644 --- a/internal/platform/implementation/apple/platform.mm +++ b/internal/platform/implementation/apple/platform.mm @@ -26,7 +26,6 @@ #include "internal/platform/implementation/apple/condition_variable.h" #include "internal/platform/implementation/apple/count_down_latch.h" #include "internal/platform/implementation/apple/device_info.h" -#import "internal/platform/implementation/apple/log_message.h" #import "internal/platform/implementation/apple/multi_thread_executor.h" #include "internal/platform/implementation/apple/mutex.h" #include "internal/platform/implementation/apple/preferences_manager.h" @@ -135,11 +134,6 @@ std::unique_ptr ImplementationPlatform::CreateOutputFile(const std:: return shared::IOFile::CreateOutputFile(file_path); } -std::unique_ptr ImplementationPlatform::CreateLogMessage( - const char* file, int line, LogMessage::Severity severity) { - return std::make_unique(file, line, severity); -} - // Java-like Executors std::unique_ptr ImplementationPlatform::CreateSingleThreadExecutor() { return std::make_unique(); diff --git a/internal/platform/implementation/g3/BUILD b/internal/platform/implementation/g3/BUILD index 89363cde..fc881b7d 100644 --- a/internal/platform/implementation/g3/BUILD +++ b/internal/platform/implementation/g3/BUILD @@ -17,7 +17,6 @@ cc_library( name = "types", testonly = True, srcs = [ - "log_message.cc", "preferences_manager.cc", "scheduled_executor.cc", "system_clock.cc", @@ -27,7 +26,6 @@ cc_library( "atomic_reference.h", "condition_variable.h", "device_info.h", - "log_message.h", "multi_thread_executor.h", "mutex.h", "preferences_manager.h", @@ -116,7 +114,7 @@ cc_library( srcs = [ "crypto.cc", ], - visibility = ["//visibility:private"], + visibility = ["//internal/platform/implementation:__subpackages__"], deps = [ "//internal/platform:base", "//internal/platform/implementation:types", @@ -156,16 +154,20 @@ cc_library( ":comm", ":crypto", # build_cleaner: keep ":types", + "//internal/platform:base", "//internal/platform:test_util", "//internal/platform/implementation:comm", "//internal/platform/implementation:platform", "//internal/platform/implementation:types", "//internal/platform/implementation/shared:count_down_latch", "//internal/platform/implementation/shared:file", + "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/memory", + "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", "@com_google_absl//absl/time", + "@com_google_nisaba//nisaba/port:thread_pool", ], ) diff --git a/internal/platform/implementation/g3/log_message.cc b/internal/platform/implementation/g3/log_message.cc deleted file mode 100644 index 27ccb7d4..00000000 --- a/internal/platform/implementation/g3/log_message.cc +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2020 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 "internal/platform/implementation/g3/log_message.h" - -#include -#include - -namespace nearby { -namespace g3 { - -namespace { - -// This is a partial copy of base::StringAppendV for OSS compilation. -void NearbyStringAppendV(std::string* dst, const char* format, va_list ap) { - // Fixed size buffer 1024 should be big enough. - static const int kSpaceLength = 1024; - char space[kSpaceLength]; - int result = vsnprintf(space, kSpaceLength, format, ap); - va_end(ap); - dst->append(space, result); -} -} // namespace - -api::LogMessage::Severity g_min_log_severity = api::LogMessage::Severity::kInfo; - -inline absl::LogSeverity ConvertSeverity(api::LogMessage::Severity severity) { - switch (severity) { - // api::LogMessage::Severity kVerbose and kInfo is mapped to - // absl::LogSeverity kInfo since absl::LogSeverity doesn't have kVerbose - // level. - case api::LogMessage::Severity::kVerbose: - case api::LogMessage::Severity::kInfo: - return absl::LogSeverity::kInfo; - case api::LogMessage::Severity::kWarning: - return absl::LogSeverity::kWarning; - case api::LogMessage::Severity::kError: - return absl::LogSeverity::kError; - case api::LogMessage::Severity::kFatal: - return absl::LogSeverity::kFatal; - } -} - -LogMessage::LogMessage(const char* file, int line, Severity severity) - : log_streamer_(ConvertSeverity(severity), file, line) {} - -LogMessage::~LogMessage() = default; - -void LogMessage::Print(const char* format, ...) { - va_list ap; - va_start(ap, format); - std::string result; - NearbyStringAppendV(&result, format, ap); - log_streamer_.stream() << result; - va_end(ap); -} - -std::ostream& LogMessage::Stream() { return log_streamer_.stream(); } - -} // namespace g3 - -namespace api { - -void LogMessage::SetMinLogSeverity(Severity severity) { - g3::g_min_log_severity = severity; -} - -bool LogMessage::ShouldCreateLogMessage(Severity severity) { - return severity >= g3::g_min_log_severity; -} - -} // namespace api -} // namespace nearby diff --git a/internal/platform/implementation/g3/log_message.h b/internal/platform/implementation/g3/log_message.h deleted file mode 100644 index 357a03d6..00000000 --- a/internal/platform/implementation/g3/log_message.h +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2020 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_G3_LOG_MESSAGE_H_ -#define PLATFORM_IMPL_G3_LOG_MESSAGE_H_ - -#include "absl/log/log_streamer.h" -#include "internal/platform/implementation/log_message.h" - -namespace nearby { -namespace g3 { - -// See documentation in -// cpp/platform/api/log_message.h -class LogMessage : public api::LogMessage { - public: - LogMessage(const char* file, int line, Severity severity); - ~LogMessage() override; - - void Print(const char* format, ...) override; - - std::ostream& Stream() override; - - private: - google::LogMessage log_streamer_; -}; - -} // namespace g3 -} // namespace nearby - -#endif // PLATFORM_IMPL_G3_LOG_MESSAGE_H_ diff --git a/internal/platform/implementation/g3/platform.cc b/internal/platform/implementation/g3/platform.cc index 75696816..a2b81be0 100644 --- a/internal/platform/implementation/g3/platform.cc +++ b/internal/platform/implementation/g3/platform.cc @@ -15,27 +15,45 @@ #include "internal/platform/implementation/platform.h" #include +#include #include #include #include +#include "absl/base/attributes.h" #include "absl/memory/memory.h" +#include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "absl/time/time.h" #include "internal/platform/implementation/atomic_boolean.h" #include "internal/platform/implementation/atomic_reference.h" +#include "internal/platform/implementation/ble.h" +#include "internal/platform/implementation/ble_v2.h" #include "internal/platform/implementation/bluetooth_adapter.h" #include "internal/platform/implementation/bluetooth_classic.h" #include "internal/platform/implementation/condition_variable.h" +#include "internal/platform/implementation/count_down_latch.h" +#include "internal/platform/implementation/credential_storage.h" +#include "internal/platform/implementation/device_info.h" +#include "internal/platform/implementation/http_loader.h" +#include "internal/platform/implementation/input_file.h" #include "internal/platform/implementation/log_message.h" #include "internal/platform/implementation/mutex.h" +#include "internal/platform/implementation/output_file.h" #include "internal/platform/implementation/preferences_manager.h" #include "internal/platform/implementation/scheduled_executor.h" #include "internal/platform/implementation/server_sync.h" #include "internal/platform/implementation/shared/count_down_latch.h" #include "internal/platform/implementation/submittable_executor.h" +#include "internal/platform/implementation/timer.h" +#include "internal/platform/implementation/wifi_direct.h" +#include "internal/platform/implementation/wifi_hotspot.h" +#include "internal/platform/implementation/wifi_lan.h" +#include "internal/platform/os_name.h" +#include "internal/platform/payload_id.h" +#include "thread/thread.h" #ifndef NO_WEBRTC #include "internal/platform/implementation/g3/webrtc.h" #include "internal/platform/implementation/webrtc.h" @@ -49,7 +67,6 @@ #include "internal/platform/implementation/g3/condition_variable.h" #include "internal/platform/implementation/g3/credential_storage_impl.h" #include "internal/platform/implementation/g3/device_info.h" -#include "internal/platform/implementation/g3/log_message.h" #include "internal/platform/implementation/g3/multi_thread_executor.h" #include "internal/platform/implementation/g3/mutex.h" #include "internal/platform/implementation/g3/preferences_manager.h" @@ -74,7 +91,7 @@ std::string ImplementationPlatform::GetCustomSavePath( std::string ImplementationPlatform::GetDownloadPath( const std::string& parent_folder, const std::string& file_name) { - return absl::StrCat("/tmp/", file_name); + return absl::StrCat("/tmp/", file_name); } OSName ImplementationPlatform::GetCurrentOS() { return OSName::kLinux; } @@ -150,7 +167,7 @@ std::unique_ptr ImplementationPlatform::CreateOutputFile( std::unique_ptr ImplementationPlatform::CreateLogMessage( const char* file, int line, LogMessage::Severity severity) { - return std::make_unique(file, line, severity); + return nullptr; } std::unique_ptr diff --git a/internal/platform/implementation/windows/BUILD b/internal/platform/implementation/windows/BUILD index b51c8751..0678fa34 100644 --- a/internal/platform/implementation/windows/BUILD +++ b/internal/platform/implementation/windows/BUILD @@ -18,7 +18,6 @@ cc_library( name = "types", srcs = [ "device_info.cc", - "log_message.cc", "timer.cc", ], hdrs = [ @@ -31,7 +30,6 @@ cc_library( "future.h", "input_file.h", "listenable_future.h", - "log_message.h", "mutex.h", "output_file.h", "preferences_manager.h", @@ -63,7 +61,6 @@ cc_library( "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/functional:any_invocable", - "@com_google_absl//absl/log", "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", "@com_google_absl//absl/synchronization", @@ -241,7 +238,6 @@ cc_library( "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/functional:any_invocable", - "@com_google_absl//absl/log:check", "@com_google_absl//absl/memory", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", diff --git a/internal/platform/implementation/windows/log_message.cc b/internal/platform/implementation/windows/log_message.cc deleted file mode 100644 index 9a78884d..00000000 --- a/internal/platform/implementation/windows/log_message.cc +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2020 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 "internal/platform/implementation/windows/log_message.h" - -#include -#include -#include - -#include "strings/strappendv.h" -#include "absl/base/log_severity.h" -#include "internal/platform/implementation/log_message.h" - -namespace nearby { -namespace windows { - -api::LogMessage::Severity g_min_log_severity = api::LogMessage::Severity::kInfo; - -inline absl::LogSeverity ConvertSeverity(api::LogMessage::Severity severity) { - switch (severity) { - // api::LogMessage::Severity kVerbose and kInfo is mapped to - // absl::LogSeverity kInfo since absl::LogSeverity doesn't have kVerbose - // level. - case api::LogMessage::Severity::kVerbose: - case api::LogMessage::Severity::kInfo: - return absl::LogSeverity::kInfo; - case api::LogMessage::Severity::kWarning: - return absl::LogSeverity::kWarning; - case api::LogMessage::Severity::kError: - return absl::LogSeverity::kError; - case api::LogMessage::Severity::kFatal: - return absl::LogSeverity::kFatal; - } -} - -LogMessage::LogMessage(const char* file, int line, Severity severity) - : log_streamer_(ConvertSeverity(severity), file, line) {} - -LogMessage::~LogMessage() = default; - -void LogMessage::Print(const char* format, ...) { - va_list ap; - va_start(ap, format); - std::string result; - strings::StrAppendV(&result, format, ap); - log_streamer_.stream() << result; - va_end(ap); -} - -std::ostream& LogMessage::Stream() { return log_streamer_.stream(); } - -} // namespace windows - -namespace api { - -void LogMessage::SetMinLogSeverity(Severity severity) { - windows::g_min_log_severity = severity; -} - -bool LogMessage::ShouldCreateLogMessage(Severity severity) { - return severity >= windows::g_min_log_severity; -} -} // namespace api -} // namespace nearby diff --git a/internal/platform/implementation/windows/log_message.h b/internal/platform/implementation/windows/log_message.h deleted file mode 100644 index 5214c5aa..00000000 --- a/internal/platform/implementation/windows/log_message.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2020 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_WINDOWS_LOG_MESSAGE_H_ -#define PLATFORM_IMPL_WINDOWS_LOG_MESSAGE_H_ - -#include - -#include "absl/log/log_streamer.h" -#include "internal/platform/implementation/log_message.h" - -namespace nearby { -namespace windows { - -// See documentation in -// cpp/platform/api/log_message.h -class LogMessage : public api::LogMessage { - public: - LogMessage(const char* file, int line, Severity severity); - ~LogMessage() override; - - void Print(const char* format, ...) override; - - std::ostream& Stream() override; - - private: - google::LogMessage log_streamer_; -}; - -} // namespace windows -} // namespace nearby - -#endif // PLATFORM_IMPL_WINDOWS_LOG_MESSAGE_H_ diff --git a/internal/platform/implementation/windows/platform.cc b/internal/platform/implementation/windows/platform.cc index 97bc62be..63255a7f 100644 --- a/internal/platform/implementation/windows/platform.cc +++ b/internal/platform/implementation/windows/platform.cc @@ -27,15 +27,33 @@ #include #include +#include #include #include #include +#include "absl/base/attributes.h" #include "absl/status/statusor.h" #include "absl/strings/string_view.h" +#include "internal/platform/implementation/atomic_boolean.h" +#include "internal/platform/implementation/atomic_reference.h" +#include "internal/platform/implementation/ble.h" +#include "internal/platform/implementation/ble_v2.h" +#include "internal/platform/implementation/bluetooth_adapter.h" +#include "internal/platform/implementation/bluetooth_classic.h" +#include "internal/platform/implementation/condition_variable.h" +#include "internal/platform/implementation/count_down_latch.h" #include "internal/platform/implementation/credential_storage.h" #include "internal/platform/implementation/http_loader.h" +#include "internal/platform/implementation/input_file.h" +#include "internal/platform/implementation/mutex.h" +#include "internal/platform/implementation/output_file.h" +#include "internal/platform/implementation/scheduled_executor.h" +#include "internal/platform/implementation/server_sync.h" #include "internal/platform/implementation/shared/count_down_latch.h" +#include "internal/platform/implementation/submittable_executor.h" +#include "internal/platform/implementation/wifi.h" +#include "internal/platform/implementation/wifi_lan.h" #include "internal/platform/implementation/windows/atomic_boolean.h" #include "internal/platform/implementation/windows/atomic_reference.h" #include "internal/platform/implementation/windows/ble_medium.h" @@ -47,7 +65,6 @@ #include "internal/platform/implementation/windows/file.h" #include "internal/platform/implementation/windows/file_path.h" #include "internal/platform/implementation/windows/http_loader.h" -#include "internal/platform/implementation/windows/log_message.h" #include "internal/platform/implementation/windows/mutex.h" #include "internal/platform/implementation/windows/preferences_manager.h" #include "internal/platform/implementation/windows/scheduled_executor.h" @@ -59,6 +76,8 @@ #include "internal/platform/implementation/windows/wifi_hotspot.h" #include "internal/platform/implementation/windows/wifi_lan.h" #include "internal/platform/logging.h" +#include "internal/platform/os_name.h" +#include "internal/platform/payload_id.h" namespace nearby { namespace api { @@ -226,12 +245,6 @@ std::unique_ptr ImplementationPlatform::CreateOutputFile( return windows::IOFile::CreateOutputFile(file_path); } -// TODO(b/184975123): replace with real implementation. -std::unique_ptr ImplementationPlatform::CreateLogMessage( - const char* file, int line, LogMessage::Severity severity) { - return std::make_unique(file, line, severity); -} - std::unique_ptr ImplementationPlatform::CreateSingleThreadExecutor() { return std::make_unique();