// filepath: /workspace/internal/platform/implementation/linux/platform.cc // Minimal Linux implementation of ImplementationPlatform. #include "internal/platform/implementation/platform.h" #include #include #include "bluetooth_adapter.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "internal/platform/implementation/atomic_boolean.h" #include "internal/platform/implementation/atomic_reference.h" #include "internal/platform/implementation/count_down_latch.h" #include "internal/platform/implementation/http_loader.h" #include "internal/platform/implementation/shared/count_down_latch.h" #include "internal/platform/implementation/linux/atomics.h" #include "internal/platform/implementation/linux/multi_thread_executor.h" #include "internal/platform/implementation/linux/scheduled_executor.h" #include "internal/platform/implementation/linux/device_info.h" #include "internal/platform/implementation/shared/posix_mutex.h" #include "internal/platform/implementation/shared/posix_condition_variable.h" #include namespace nearby { namespace api { std::string ImplementationPlatform::GetCustomSavePath(const std::string& parent_folder, const std::string& file_name) { return absl::StrCat(parent_folder, "/", file_name); } std::string ImplementationPlatform::GetDownloadPath(const std::string& parent_folder, const std::string& file_name) { return absl::StrCat("/tmp/", file_name); } std::string ImplementationPlatform::GetDownloadPath(const std::string& file_name) { return absl::StrCat("/tmp/", file_name); } std::string ImplementationPlatform::GetAppDataPath(const std::string& file_name) { return absl::StrCat("/tmp/", file_name); } OSName ImplementationPlatform::GetCurrentOS() { return OSName::kLinux; } std::unique_ptr ImplementationPlatform::CreateAtomicBoolean(bool initial_value) { return std::make_unique(initial_value); } std::unique_ptr ImplementationPlatform::CreateAtomicUint32(std::uint32_t value) { return std::make_unique(value); } std::unique_ptr ImplementationPlatform::CreateCountDownLatch(std::int32_t count) { return std::make_unique(count); } #pragma push_macro("CreateMutex") #undef CreateMutex std::unique_ptr ImplementationPlatform::CreateMutex(Mutex::Mode mode) { // Use the shared POSIX mutex implementation. The posix::Mutex is recursive by // design (uses PTHREAD_MUTEX_RECURSIVE), so return it for both regular and // recursive modes to use a consistent POSIX implementation across Linux. return std::make_unique(); } #pragma pop_macro("CreateMutex") std::unique_ptr ImplementationPlatform::CreateConditionVariable(Mutex* mutex) { if (mutex == nullptr) return nullptr; // Expect a posix::Mutex instance here; if it's not, return nullptr. auto* derived = dynamic_cast(mutex); if (!derived) return nullptr; return std::make_unique(derived); } std::unique_ptr ImplementationPlatform::CreateInputFile(PayloadId, std::int64_t) { return nullptr; } std::unique_ptr ImplementationPlatform::CreateInputFile(const std::string&, size_t) { return nullptr; } std::unique_ptr ImplementationPlatform::CreateOutputFile(PayloadId) { return nullptr; } std::unique_ptr ImplementationPlatform::CreateOutputFile(const std::string&) { return nullptr; } std::unique_ptr ImplementationPlatform::CreateLogMessage(const char* file, int line, LogMessage::Severity severity) { return nullptr; } std::unique_ptr ImplementationPlatform::CreateSingleThreadExecutor() { return std::make_unique(1); } std::unique_ptr ImplementationPlatform::CreateMultiThreadExecutor(std::int32_t max_concurrency) { return std::make_unique(static_cast(max_concurrency)); } std::unique_ptr ImplementationPlatform::CreateScheduledExecutor() { return std::unique_ptr(new linux::ScheduledExecutor()); } std::unique_ptr ImplementationPlatform::CreateAwdlMedium() { return nullptr; } std::unique_ptr ImplementationPlatform::CreateBluetoothAdapter() { static auto connection = sdbus::createConnection(); return std::make_unique(*connection, "/org/bluez/hci0"); } std::unique_ptr ImplementationPlatform::CreateBluetoothClassicMedium(BluetoothAdapter&) { return nullptr; } std::unique_ptr ImplementationPlatform::CreateBleMedium(BluetoothAdapter&) { return nullptr; } std::unique_ptr ImplementationPlatform::CreateBleV2Medium(api::BluetoothAdapter&) { return nullptr; } std::unique_ptr ImplementationPlatform::CreateCredentialStorage() { return nullptr; } std::unique_ptr ImplementationPlatform::CreateServerSyncMedium() { return nullptr; } std::unique_ptr ImplementationPlatform::CreateWifiMedium() { return nullptr; } std::unique_ptr ImplementationPlatform::CreateWifiLanMedium() { return nullptr; } std::unique_ptr ImplementationPlatform::CreateWifiHotspotMedium() { return nullptr; } std::unique_ptr ImplementationPlatform::CreateWifiDirectMedium() { return nullptr; } std::unique_ptr ImplementationPlatform::CreateTimer() { return nullptr; } std::unique_ptr ImplementationPlatform::CreateDeviceInfo() { return std::make_unique(); } #ifndef NO_WEBRTC std::unique_ptr ImplementationPlatform::CreateWebRtcMedium() { return nullptr; } #endif absl::StatusOr ImplementationPlatform::SendRequest(const WebRequest& request) { return absl::UnimplementedError("HTTP loader not implemented on this minimal linux platform"); } #ifndef NEARBY_CHROMIUM std::unique_ptr ImplementationPlatform::CreatePreferencesManager(absl::string_view path) { return nullptr; } #endif } // namespace api } // namespace nearby