diff --git a/cpp/core/BUILD b/cpp/core/BUILD index c5957521..ef9ebf87 100644 --- a/cpp/core/BUILD +++ b/cpp/core/BUILD @@ -21,7 +21,7 @@ cc_library( "core.h", ], visibility = [ - "//googlemac/iPhone/Shared/Nearby/Connections_v2:__subpackages__", + "//googlemac/iPhone/Shared/Nearby/Connections:__subpackages__", "//location/nearby/connections/windows:__subpackages__", ], deps = [ diff --git a/cpp/platform/api/BUILD b/cpp/platform/api/BUILD index cad98313..0eee7e0c 100644 --- a/cpp/platform/api/BUILD +++ b/cpp/platform/api/BUILD @@ -34,7 +34,7 @@ cc_library( "system_clock.h", ], visibility = [ - "//googlemac/iPhone/Shared/Nearby/Connections_v2:__subpackages__", + "//googlemac/iPhone/Shared/Nearby/Connections:__subpackages__", "//platform/base:__pkg__", "//platform/impl:__subpackages__", "//platform/public:__pkg__", @@ -81,7 +81,7 @@ cc_library( "platform.h", ], visibility = [ - "//googlemac/iPhone/Shared/Nearby/Connections_v2:__subpackages__", + "//googlemac/iPhone/Shared/Nearby/Connections:__subpackages__", "//platform/base:__pkg__", "//platform/impl:__subpackages__", "//platform/public:__pkg__", diff --git a/cpp/platform/impl/ios/BUILD b/cpp/platform/impl/ios/BUILD deleted file mode 100644 index 4d84ab30..00000000 --- a/cpp/platform/impl/ios/BUILD +++ /dev/null @@ -1,66 +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. - -objc_library( - name = "types", - srcs = [ - "log_message.mm", - "scheduled_executor.mm", - ], - hdrs = [ - "atomic_boolean.h", - "atomic_reference.h", - "condition_variable.h", - "count_down_latch.h", - "log_message.h", - "multi_thread_executor.h", - "mutex.h", - "scheduled_executor.h", - "single_thread_executor.h", - ], - visibility = [ - "//platform/impl/ios:__pkg__", - ], - deps = [ - "//base", - "//platform/api:platform", - "//platform/api:types", - "//platform/base", - "//platform/base:util", - "//platform/impl/shared:posix_mutex", - "//absl/base:core_headers", - "//absl/synchronization", - "//absl/time", - "//thread", - ], -) - -objc_library( - name = "ios", - srcs = [ - "platform.mm", - ], - visibility = ["//platform:__subpackages__"], - deps = [ - ":types", - "//platform/api:comm", - "//platform/api:platform", - "//platform/api:types", - "//platform/impl/shared:file", - "//absl/base:core_headers", - "//absl/memory", - "//absl/strings", - "//absl/time", - ], -) diff --git a/cpp/platform/impl/ios/atomic_boolean.h b/cpp/platform/impl/ios/atomic_boolean.h deleted file mode 100644 index d992a477..00000000 --- a/cpp/platform/impl/ios/atomic_boolean.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_IOS_ATOMIC_BOOLEAN_H_ -#define PLATFORM_IMPL_IOS_ATOMIC_BOOLEAN_H_ - -#include - -#include "platform/api/atomic_boolean.h" - -namespace location { -namespace nearby { -namespace ios { - -class AtomicBoolean : public api::AtomicBoolean { - public: - explicit AtomicBoolean(bool initial_value) : value_(initial_value) {} - ~AtomicBoolean() override = default; - - bool Get() const override { return value_.load(); } - bool Set(bool value) override { return value_.exchange(value); } - - private: - std::atomic_bool value_; -}; - -} // namespace ios -} // namespace nearby -} // namespace location - -#endif // PLATFORM_IMPL_IOS_ATOMIC_BOOLEAN_H_ diff --git a/cpp/platform/impl/ios/atomic_reference.h b/cpp/platform/impl/ios/atomic_reference.h deleted file mode 100644 index df0ebe5f..00000000 --- a/cpp/platform/impl/ios/atomic_reference.h +++ /dev/null @@ -1,47 +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_IOS_ATOMIC_REFERENCE_H_ -#define PLATFORM_IMPL_IOS_ATOMIC_REFERENCE_H_ - -#include -#include - -#include "platform/api/atomic_reference.h" - -namespace location { -namespace nearby { -namespace ios { - -class AtomicUint32 : public api::AtomicUint32 { - public: - explicit AtomicUint32(std::int32_t value) : value_(value) {} - ~AtomicUint32() override = default; - - std::uint32_t Get() const override { - return value_; - } - void Set(std::uint32_t value) override { - value_ = value; - } - - private: - std::atomic value_; -}; - -} // namespace ios -} // namespace nearby -} // namespace location - -#endif // PLATFORM_IMPL_IOS_ATOMIC_REFERENCE_H_ diff --git a/cpp/platform/impl/ios/condition_variable.h b/cpp/platform/impl/ios/condition_variable.h deleted file mode 100644 index ad6be993..00000000 --- a/cpp/platform/impl/ios/condition_variable.h +++ /dev/null @@ -1,51 +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_IOS_CONDITION_VARIABLE_H_ -#define PLATFORM_IMPL_IOS_CONDITION_VARIABLE_H_ - -#include "platform/api/condition_variable.h" -#include "platform/base/exception.h" -#include "platform/impl/ios/mutex.h" -#include "absl/synchronization/mutex.h" - -namespace location { -namespace nearby { -namespace ios { - -class ConditionVariable : public api::ConditionVariable { - public: - explicit ConditionVariable(ios::Mutex* mutex) : mutex_(&mutex->mutex_) {} - ~ConditionVariable() override = default; - - Exception Wait() override { - cond_var_.Wait(mutex_); - return {Exception::kSuccess}; - } - Exception Wait(absl::Duration timeout) override { - cond_var_.WaitWithTimeout(mutex_, timeout); - return {Exception::kSuccess}; - } - void Notify() override { cond_var_.SignalAll(); } - - private: - absl::Mutex* mutex_; - absl::CondVar cond_var_; -}; - -} // namespace ios -} // namespace nearby -} // namespace location - -#endif // PLATFORM_IMPL_IOS_CONDITION_VARIABLE_H_ diff --git a/cpp/platform/impl/ios/count_down_latch.h b/cpp/platform/impl/ios/count_down_latch.h deleted file mode 100644 index ae069ffe..00000000 --- a/cpp/platform/impl/ios/count_down_latch.h +++ /dev/null @@ -1,69 +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_IOS_COUNT_DOWN_LATCH_H_ -#define PLATFORM_IMPL_IOS_COUNT_DOWN_LATCH_H_ - -#include "platform/api/count_down_latch.h" -#include "absl/base/thread_annotations.h" -#include "absl/synchronization/mutex.h" -#include "absl/time/clock.h" - -namespace location { -namespace nearby { -namespace ios { - -class CountDownLatch final : public api::CountDownLatch { - public: - explicit CountDownLatch(int count) : count_(count) {} - CountDownLatch(const CountDownLatch&) = delete; - CountDownLatch& operator=(const CountDownLatch&) = delete; - CountDownLatch(CountDownLatch&&) = delete; - CountDownLatch& operator=(CountDownLatch&&) = delete; - ExceptionOr Await(absl::Duration timeout) override { - absl::MutexLock lock(&mutex_); - absl::Time deadline = absl::Now() + timeout; - while (count_ > 0) { - if (cond_.WaitWithDeadline(&mutex_, deadline)) { - return ExceptionOr(false); - } - } - return ExceptionOr(true); - } - Exception Await() override { - absl::MutexLock lock(&mutex_); - while (count_ > 0) { - cond_.Wait(&mutex_); - } - return {Exception::kSuccess}; - } - void CountDown() override { - absl::MutexLock lock(&mutex_); - if (count_ > 0 && --count_ == 0) { - cond_.SignalAll(); - } - } - - private: - absl::Mutex mutex_; // Mutex to be used with cond_.Wait...() method family. - absl::CondVar cond_; // Condition to synchronize up to N waiting threads. - int count_ - ABSL_GUARDED_BY(mutex_); // When zero, latch should release all waiters. -}; - -} // namespace ios -} // namespace nearby -} // namespace location - -#endif // PLATFORM_IMPL_IOS_COUNT_DOWN_LATCH_H_ diff --git a/cpp/platform/impl/ios/log_message.h b/cpp/platform/impl/ios/log_message.h deleted file mode 100644 index 8b72c075..00000000 --- a/cpp/platform/impl/ios/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_IOS_LOG_MESSAGE_H_ -#define PLATFORM_IMPL_IOS_LOG_MESSAGE_H_ - -#include "base/logging.h" -#include "platform/api/log_message.h" - -namespace location { -namespace nearby { -namespace ios { - -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: - absl::LogStreamer log_streamer_; -}; - -} // namespace ios -} // namespace nearby -} // namespace location - -#endif // PLATFORM_IMPL_IOS_LOG_MESSAGE_H_ diff --git a/cpp/platform/impl/ios/log_message.mm b/cpp/platform/impl/ios/log_message.mm deleted file mode 100644 index 167fd875..00000000 --- a/cpp/platform/impl/ios/log_message.mm +++ /dev/null @@ -1,70 +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 "platform/impl/ios/log_message.h" - -#include - -#include "base/stringprintf.h" - -namespace location { -namespace nearby { -namespace ios { - -api::LogMessage::Severity kMinLogSeverity = api::LogMessage::Severity::kInfo; - -inline absl::LogSeverity ConvertSeverity(api::LogMessage::Severity severity) { - switch (severity) { - 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; - StringAppendV(&result, format, ap); - log_streamer_.stream() << result; - va_end(ap); -} - -std::ostream& LogMessage::Stream() { return log_streamer_.stream(); } - -} // namespace ios - -namespace api { - -void LogMessage::SetMinLogSeverity(Severity severity) { - ios::kMinLogSeverity = severity; -} - -bool LogMessage::ShouldCreateLogMessage(Severity severity) { - return severity >= ios::kMinLogSeverity; -} - -} // namespace api -} // namespace nearby -} // namespace location diff --git a/cpp/platform/impl/ios/multi_thread_executor.h b/cpp/platform/impl/ios/multi_thread_executor.h deleted file mode 100644 index 873b7e11..00000000 --- a/cpp/platform/impl/ios/multi_thread_executor.h +++ /dev/null @@ -1,71 +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_IOS_MULTI_THREAD_EXECUTOR_H_ -#define PLATFORM_IMPL_IOS_MULTI_THREAD_EXECUTOR_H_ - -#include - -#include "platform/api/submittable_executor.h" -#include "platform/impl/ios/count_down_latch.h" -#include "absl/time/clock.h" -#include "thread/threadpool.h" - -namespace location { -namespace nearby { -namespace ios { - -class MultiThreadExecutor : public api::SubmittableExecutor { - public: - explicit MultiThreadExecutor(int max_parallelism) - : thread_pool_(max_parallelism) { - thread_pool_.StartWorkers(); - } - void Execute(Runnable&& runnable) override { - if (!shutdown_) { - thread_pool_.Schedule(std::move(runnable)); - } - } - bool DoSubmit(Runnable&& runnable) override { - if (shutdown_) return false; - thread_pool_.Schedule(std::move(runnable)); - return true; - } - void Shutdown() override { DoShutdown(); } - ~MultiThreadExecutor() override { DoShutdown(); } - - int GetTid(int index) const override { - const auto* thread = thread_pool_.thread(index); - return thread ? *(int*)(thread->tid()) : 0; - } - - void ScheduleAfter(absl::Duration delay, Runnable&& runnable) { - if (shutdown_) return; - thread_pool_.ScheduleAt(absl::Now() + delay, std::move(runnable)); - } - bool InShutdown() const { return shutdown_; } - - private: - void DoShutdown() { - shutdown_ = true; - } - std::atomic_bool shutdown_ = false; - ThreadPool thread_pool_; -}; - -} // namespace ios -} // namespace nearby -} // namespace location - -#endif // PLATFORM_IMPL_IOS_MULTI_THREAD_EXECUTOR_H_ diff --git a/cpp/platform/impl/ios/mutex.h b/cpp/platform/impl/ios/mutex.h deleted file mode 100644 index a43e44a5..00000000 --- a/cpp/platform/impl/ios/mutex.h +++ /dev/null @@ -1,61 +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_IOS_MUTEX_H_ -#define PLATFORM_IMPL_IOS_MUTEX_H_ - -#include "platform/api/mutex.h" -#include "platform/impl/shared/posix_mutex.h" -#include "absl/synchronization/mutex.h" - -namespace location { -namespace nearby { -namespace ios { - -class ABSL_LOCKABLE Mutex : public api::Mutex { - public: - explicit Mutex(bool check) : check_(check) {} - ~Mutex() override = default; - Mutex(Mutex&&) = delete; - Mutex& operator=(Mutex&&) = delete; - Mutex(const Mutex&) = delete; - Mutex& operator=(const Mutex&) = delete; - - void Lock() ABSL_EXCLUSIVE_LOCK_FUNCTION() override { - mutex_.Lock(); - if (!check_) mutex_.ForgetDeadlockInfo(); - } - void Unlock() ABSL_UNLOCK_FUNCTION() override { mutex_.Unlock(); } - - private: - friend class ConditionVariable; - absl::Mutex mutex_; - bool check_; -}; - -class ABSL_LOCKABLE RecursiveMutex : public posix::Mutex { - public: - ~RecursiveMutex() override = default; - RecursiveMutex() = default; - RecursiveMutex(RecursiveMutex&&) = delete; - RecursiveMutex& operator=(RecursiveMutex&&) = delete; - RecursiveMutex(const RecursiveMutex&) = delete; - RecursiveMutex& operator=(const RecursiveMutex&) = delete; -}; - -} // namespace ios -} // namespace nearby -} // namespace location - -#endif // PLATFORM_IMPL_IOS_MUTEX_H_ diff --git a/cpp/platform/impl/ios/platform.mm b/cpp/platform/impl/ios/platform.mm deleted file mode 100644 index fd808922..00000000 --- a/cpp/platform/impl/ios/platform.mm +++ /dev/null @@ -1,138 +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 "platform/api/platform.h" - -#include -#include - -#include "platform/api/atomic_boolean.h" -#include "platform/api/atomic_reference.h" -#include "platform/api/condition_variable.h" -#include "platform/api/count_down_latch.h" -#include "platform/api/log_message.h" -#include "platform/api/mutex.h" -#include "platform/api/scheduled_executor.h" -#include "platform/api/submittable_executor.h" -#include "platform/impl/ios/atomic_boolean.h" -#include "platform/impl/ios/atomic_reference.h" -#include "platform/impl/ios/condition_variable.h" -#include "platform/impl/ios/count_down_latch.h" -#include "platform/impl/ios/log_message.h" -#include "platform/impl/ios/multi_thread_executor.h" -#include "platform/impl/ios/mutex.h" -#include "platform/impl/ios/scheduled_executor.h" -#include "platform/impl/ios/single_thread_executor.h" -#include "platform/impl/shared/file.h" -#include "absl/memory/memory.h" - -namespace location { -namespace nearby { -namespace api { - -namespace { -std::string GetPayloadPath(PayloadId payload_id) { - return absl::StrCat("/tmp/", payload_id); -} -} // namespace - -std::unique_ptr ImplementationPlatform::CreateAtomicBoolean(bool initial_value) { - return absl::make_unique(initial_value); -} - -std::unique_ptr ImplementationPlatform::CreateAtomicUint32(std::uint32_t value) { - return absl::make_unique(value); -} - -std::unique_ptr ImplementationPlatform::CreateCountDownLatch( - std::int32_t count) { - return absl::make_unique(count); -} - -std::unique_ptr ImplementationPlatform::CreateMutex(Mutex::Mode mode) { - if (mode == Mutex::Mode::kRecursive) - return absl::make_unique(); - else - return absl::make_unique(mode == Mutex::Mode::kRegular); -} - -std::unique_ptr ImplementationPlatform::CreateConditionVariable(Mutex* mutex) { - return std::unique_ptr( - new ios::ConditionVariable(static_cast(mutex))); -} - -std::unique_ptr ImplementationPlatform::CreateInputFile(PayloadId payload_id, - std::int64_t total_size) { - return absl::make_unique(GetPayloadPath(payload_id), total_size); -} - -std::unique_ptr ImplementationPlatform::CreateOutputFile(PayloadId payload_id) { - return absl::make_unique(GetPayloadPath(payload_id)); -} - -std::unique_ptr ImplementationPlatform::CreateLogMessage( - const char* file, int line, LogMessage::Severity severity) { - return absl::make_unique(file, line, severity); -} - -std::unique_ptr ImplementationPlatform::CreateSingleThreadExecutor() { - return absl::make_unique(); -} - -std::unique_ptr ImplementationPlatform::CreateMultiThreadExecutor( - int max_concurrency) { - return absl::make_unique(max_concurrency); -} - -std::unique_ptr ImplementationPlatform::CreateScheduledExecutor() { - return absl::make_unique(); -} - -std::unique_ptr ImplementationPlatform::CreateBluetoothAdapter() { - return std::unique_ptr(); -} - -std::unique_ptr ImplementationPlatform::CreateBluetoothClassicMedium( - api::BluetoothAdapter& adapter) { - return std::unique_ptr(); -} - -std::unique_ptr ImplementationPlatform::CreateBleMedium(api::BluetoothAdapter& adapter) { - return std::unique_ptr(); -} - -std::unique_ptr ImplementationPlatform::CreateBleV2Medium( - api::BluetoothAdapter& adapter) { - return std::unique_ptr(); -} - -std::unique_ptr ImplementationPlatform::CreateServerSyncMedium() { - return std::unique_ptr(); -} - -std::unique_ptr ImplementationPlatform::CreateWifiMedium() { - return std::unique_ptr(); -} - -std::unique_ptr ImplementationPlatform::CreateWifiLanMedium() { - return std::unique_ptr(); -} - -std::unique_ptr ImplementationPlatform::CreateWebRtcMedium() { - return std::unique_ptr(); -} - -} // namespace api -} // namespace nearby -} // namespace location diff --git a/cpp/platform/impl/ios/scheduled_executor.h b/cpp/platform/impl/ios/scheduled_executor.h deleted file mode 100644 index 9ef95581..00000000 --- a/cpp/platform/impl/ios/scheduled_executor.h +++ /dev/null @@ -1,57 +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_IOS_SCHEDULED_EXECUTOR_H_ -#define PLATFORM_IMPL_IOS_SCHEDULED_EXECUTOR_H_ - -#include -#include - -#include "platform/api/cancelable.h" -#include "platform/api/scheduled_executor.h" -#include "platform/base/runnable.h" -#include "platform/impl/ios/single_thread_executor.h" -#include "absl/time/clock.h" -#include "thread/threadpool.h" - -namespace location { -namespace nearby { -namespace ios { - -class ScheduledExecutor final : public api::ScheduledExecutor { - public: - ScheduledExecutor() = default; - ~ScheduledExecutor() override { - executor_.Shutdown(); - } - - void Execute(Runnable&& runnable) override { - executor_.Execute(std::move(runnable)); - } - std::shared_ptr Schedule(Runnable&& runnable, - absl::Duration delay) override; - void Shutdown() override { executor_.Shutdown(); } - - int GetTid(int index) const override { - return executor_.GetTid(index); - } - private: - SingleThreadExecutor executor_; -}; - -} // namespace ios -} // namespace nearby -} // namespace location - -#endif // PLATFORM_IMPL_IOS_SCHEDULED_EXECUTOR_H_ diff --git a/cpp/platform/impl/ios/scheduled_executor.mm b/cpp/platform/impl/ios/scheduled_executor.mm deleted file mode 100644 index c12b9844..00000000 --- a/cpp/platform/impl/ios/scheduled_executor.mm +++ /dev/null @@ -1,79 +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 "platform/impl/ios/scheduled_executor.h" - -#include -#include - -#include "platform/api/cancelable.h" -#include "platform/base/runnable.h" -#include "absl/time/clock.h" - -namespace location { -namespace nearby { -namespace ios { - -namespace { - -class ScheduledCancelable : public api::Cancelable { - public: - bool Cancel() override { - Status expected = kNotRun; - while (expected == kNotRun) { - if (status_.compare_exchange_strong(expected, kCanceled)) { - return true; - } - } - return false; - } - bool MarkExecuted() { - Status expected = kNotRun; - while (expected == kNotRun) { - if (status_.compare_exchange_strong(expected, kExecuted)) { - return true; - } - } - return false; - } - - private: - enum Status { - kNotRun, - kExecuted, - kCanceled, - }; - std::atomic status_ = kNotRun; -}; - -} // namespace - -std::shared_ptr ScheduledExecutor::Schedule( - Runnable&& runnable, absl::Duration delay) { - auto scheduled_cancelable = std::make_shared(); - if (executor_.InShutdown()) { - return scheduled_cancelable; - } - executor_.ScheduleAfter( - delay, [this, scheduled_cancelable, runnable(std::move(runnable))]() { - if (!executor_.InShutdown() && scheduled_cancelable->MarkExecuted()) { - runnable(); - } - }); - return scheduled_cancelable; -} - -} // namespace ios -} // namespace nearby -} // namespace location diff --git a/cpp/platform/impl/ios/single_thread_executor.h b/cpp/platform/impl/ios/single_thread_executor.h deleted file mode 100644 index 7bd12a0e..00000000 --- a/cpp/platform/impl/ios/single_thread_executor.h +++ /dev/null @@ -1,34 +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_IOS_SINGLE_THREAD_EXECUTOR_H_ -#define PLATFORM_IMPL_IOS_SINGLE_THREAD_EXECUTOR_H_ - -#include "platform/impl/ios/multi_thread_executor.h" - -namespace location { -namespace nearby { -namespace ios { - -class SingleThreadExecutor final : public MultiThreadExecutor { - public: - SingleThreadExecutor() : MultiThreadExecutor(1) {} - ~SingleThreadExecutor() override = default; -}; - -} // namespace ios -} // namespace nearby -} // namespace location - -#endif // PLATFORM_IMPL_IOS_SINGLE_THREAD_EXECUTOR_H_ diff --git a/cpp/platform/impl/shared/BUILD b/cpp/platform/impl/shared/BUILD index 64f96218..2b85fa65 100644 --- a/cpp/platform/impl/shared/BUILD +++ b/cpp/platform/impl/shared/BUILD @@ -21,7 +21,6 @@ cc_library( "posix_mutex.h", ], visibility = [ - "//googlemac/iPhone/Shared/Nearby/Connections_v2:__subpackages__", "//platform/impl:__subpackages__", ], deps = ["//platform/api:types"], @@ -35,9 +34,6 @@ cc_library( hdrs = [ "posix_condition_variable.h", ], - visibility = [ - "//googlemac/iPhone/Shared/Nearby/Connections_v2:__subpackages__", - ], deps = [ ":posix_mutex", "//platform/api:types", @@ -49,7 +45,7 @@ cc_library( srcs = ["file.cc"], hdrs = ["file.h"], visibility = [ - "//googlemac/iPhone/Shared/Nearby/Connections_v2:__subpackages__", + "//googlemac/iPhone/Shared/Nearby/Connections:__subpackages__", "//platform/impl:__subpackages__", ], deps = [ diff --git a/proto/connections/BUILD b/proto/connections/BUILD index d1f87572..d9814b6d 100644 --- a/proto/connections/BUILD +++ b/proto/connections/BUILD @@ -21,7 +21,7 @@ proto_library( ], cc_api_version = 2, visibility = [ - "//googlemac/iPhone/Shared/Nearby/Connections_v2:__subpackages__", + "//googlemac/iPhone/Shared/Nearby/Connections:__subpackages__", ], )