// 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 "platform/api/mutex.h" #include "platform/base/payload_id.h" #import "platform/impl/ios/Source/Internal/GNCCore.h" #include "platform/impl/ios/Source/Platform/atomic_boolean.h" #include "platform/impl/ios/Source/Platform/atomic_uint32.h" #include "platform/impl/ios/Source/Platform/condition_variable.h" #include "platform/impl/ios/Source/Platform/count_down_latch.h" #include "platform/impl/ios/Source/Platform/input_file.h" #import "platform/impl/ios/Source/Platform/log_message.h" #import "platform/impl/ios/Source/Platform/multi_thread_executor.h" #include "platform/impl/ios/Source/Platform/mutex.h" #import "platform/impl/ios/Source/Platform/scheduled_executor.h" #import "platform/impl/ios/Source/Platform/single_thread_executor.h" #import "platform/impl/ios/Source/Platform/utils.h" #include "platform/impl/ios/Source/Platform/wifi_lan.h" #include "platform/impl/shared/file.h" namespace location { namespace nearby { namespace api { namespace { std::string GetPayloadPath(PayloadId payload_id) { // This is to get a file path, e.g. /tmp/[payload_id], for the storage of payload file. // NOTE: Per // https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html // Files saved in the /tmp directory will be deleted by the system. Callers should be responsible // for copying the files to the permanent storage. NSString* payloadIdString = ObjCStringFromCppString(std::to_string(payload_id)); return CppStringFromObjCString( [NSTemporaryDirectory() stringByAppendingPathComponent:payloadIdString]); } } // namespace // Atomics: std::unique_ptr ImplementationPlatform::CreateAtomicBoolean(bool initial_value) { return std::make_unique(initial_value); } std::unique_ptr ImplementationPlatform::CreateAtomicUint32( std::uint32_t initial_value) { return std::make_unique(initial_value); } std::unique_ptr ImplementationPlatform::CreateCountDownLatch(std::int32_t count) { return std::make_unique(count); } std::unique_ptr ImplementationPlatform::CreateMutex(Mutex::Mode mode) { // iOS does not support unchecked Mutex in debug mode, therefore // ios::Mutex is used for both kRegular and kRegularNoCheck. if (mode == Mutex::Mode::kRecursive) { return absl::make_unique(); } else { return absl::make_unique(); } } std::unique_ptr ImplementationPlatform::CreateConditionVariable(Mutex* mutex) { return std::make_unique(static_cast(mutex)); } std::unique_ptr ImplementationPlatform::CreateInputFile(PayloadId payload_id, std::int64_t total_size) { // Extract the NSURL object with payload_id from |GNCCore| which stores the maps. If the retrieved // NSURL object is not nil, we create InputFile by ios::InputFile. The difference is // that ios::InputFile implements to read bytes from local real file for sending. GNCCore* core = GNCGetCore(); NSURL* url = [core extractURLWithPayloadID:payload_id]; if (url != nil) { return absl::make_unique(url); } else { 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); } // Java-like Executors std::unique_ptr ImplementationPlatform::CreateSingleThreadExecutor() { return std::make_unique(); } std::unique_ptr ImplementationPlatform::CreateMultiThreadExecutor( int max_concurrency) { return std::make_unique(max_concurrency); } std::unique_ptr ImplementationPlatform::CreateScheduledExecutor() { return std::make_unique(); } // Mediums std::unique_ptr ImplementationPlatform::CreateBluetoothAdapter() { return nullptr; } std::unique_ptr ImplementationPlatform::CreateBluetoothClassicMedium( api::BluetoothAdapter& adapter) { return nullptr; } std::unique_ptr ImplementationPlatform::CreateBleMedium(api::BluetoothAdapter& adapter) { return nullptr; } std::unique_ptr ImplementationPlatform::CreateBleV2Medium( api::BluetoothAdapter& adapter) { return nullptr; } std::unique_ptr ImplementationPlatform::CreateServerSyncMedium() { return nullptr; } std::unique_ptr ImplementationPlatform::CreateWifiMedium() { return nullptr; } std::unique_ptr ImplementationPlatform::CreateWifiLanMedium() { return std::make_unique(); } std::unique_ptr ImplementationPlatform::CreateWebRtcMedium() { return nullptr; } } // namespace api } // namespace nearby } // namespace location