/* * Copyright (c) 2024, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #if defined(AK_OS_SERENITY) # error "Singleton process utilities are not to be used on SerenityOS" #endif namespace Core { namespace Detail { struct ProcessSocket { NonnullOwnPtr socket; pid_t pid { 0 }; }; ErrorOr launch_and_connect_to_process(StringView process_name, ReadonlySpan candidate_process_paths, ReadonlySpan command_line_arguments); } template struct SingletonProcess { NonnullRefPtr client; pid_t pid { 0 }; }; template ErrorOr> launch_singleton_process(StringView process_name, ReadonlySpan candidate_process_paths, ReadonlySpan command_line_arguments = {}) { auto process_socket = TRY(Detail::launch_and_connect_to_process(process_name, candidate_process_paths, command_line_arguments)); auto client = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ClientType { move(process_socket.socket) })); return SingletonProcess { move(client), process_socket.pid }; } }