mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-22 02:09:24 +00:00
Everywhere: Hoist the Libraries folder to the top-level
This commit is contained in:
parent
950e819ee7
commit
93712b24bf
Notes:
github-actions[bot]
2024-11-10 11:51:52 +00:00
Author: https://github.com/trflynn89
Commit: 93712b24bf
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2256
Reviewed-by: https://github.com/sideshowbarker
4547 changed files with 104 additions and 113 deletions
82
Libraries/LibWebView/Process.h
Normal file
82
Libraries/LibWebView/Process.h
Normal file
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <AK/WeakPtr.h>
|
||||
#include <LibCore/Process.h>
|
||||
#include <LibIPC/Connection.h>
|
||||
#include <LibIPC/Transport.h>
|
||||
#include <LibWebView/ProcessType.h>
|
||||
|
||||
namespace WebView {
|
||||
|
||||
class Process {
|
||||
AK_MAKE_NONCOPYABLE(Process);
|
||||
AK_MAKE_DEFAULT_MOVABLE(Process);
|
||||
|
||||
public:
|
||||
Process(ProcessType type, RefPtr<IPC::ConnectionBase> connection, Core::Process process);
|
||||
~Process();
|
||||
|
||||
template<typename ClientType>
|
||||
struct ProcessAndClient;
|
||||
|
||||
template<typename ClientType, typename... ClientArguments>
|
||||
static ErrorOr<ProcessAndClient<ClientType>> spawn(ProcessType type, Core::ProcessSpawnOptions const& options, ClientArguments&&... client_arguments);
|
||||
|
||||
ProcessType type() const { return m_type; }
|
||||
Optional<String> const& title() const { return m_title; }
|
||||
void set_title(Optional<String> title) { m_title = move(title); }
|
||||
|
||||
template<typename ConnectionFromClient>
|
||||
Optional<ConnectionFromClient&> client()
|
||||
{
|
||||
if (auto strong_connection = m_connection.strong_ref())
|
||||
return verify_cast<ConnectionFromClient>(*strong_connection);
|
||||
return {};
|
||||
}
|
||||
|
||||
pid_t pid() const { return m_process.pid(); }
|
||||
|
||||
struct ProcessPaths {
|
||||
ByteString socket_path;
|
||||
ByteString pid_path;
|
||||
};
|
||||
static ErrorOr<ProcessPaths> paths_for_process(StringView process_name);
|
||||
static ErrorOr<Optional<pid_t>> get_process_pid(StringView process_name, StringView pid_path);
|
||||
static ErrorOr<int> create_ipc_socket(ByteString const& socket_path);
|
||||
|
||||
private:
|
||||
struct ProcessAndIPCTransport {
|
||||
Core::Process process;
|
||||
IPC::Transport transport;
|
||||
};
|
||||
static ErrorOr<ProcessAndIPCTransport> spawn_and_connect_to_process(Core::ProcessSpawnOptions const& options);
|
||||
|
||||
Core::Process m_process;
|
||||
ProcessType m_type;
|
||||
Optional<String> m_title;
|
||||
WeakPtr<IPC::ConnectionBase> m_connection;
|
||||
};
|
||||
|
||||
template<typename ClientType>
|
||||
struct Process::ProcessAndClient {
|
||||
Process process;
|
||||
NonnullRefPtr<ClientType> client;
|
||||
};
|
||||
|
||||
template<typename ClientType, typename... ClientArguments>
|
||||
ErrorOr<Process::ProcessAndClient<ClientType>> Process::spawn(ProcessType type, Core::ProcessSpawnOptions const& options, ClientArguments&&... client_arguments)
|
||||
{
|
||||
auto [core_process, transport] = TRY(spawn_and_connect_to_process(options));
|
||||
auto client = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ClientType { move(transport), forward<ClientArguments>(client_arguments)... }));
|
||||
|
||||
return ProcessAndClient<ClientType> { Process { type, client, move(core_process) }, client };
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue