1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:38:12 +00:00
serenity/Ladybird/SQLServer/main.cpp
Timothy Flynn 2cb3ae132a Ladybird: Implement SQLServer for Ladybird :^)
This adds a SQLServer binary for Ladybird to make use of Serenity's SQL
implementation. This has to use the same IPC socket handling that was
used to make WebContent and WebDriver work out-of-process.

Unlike Serenity, Ladybird creates a new SQLServer instance for each
Ladybird instance. In the future, we should try to make sure there is
only one SQLServer instance at a time, and allow multiple Ladybird
instances to communicate with it.
2022-12-25 07:58:58 -07:00

41 lines
1.4 KiB
C++

/*
* Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#define AK_DONT_REPLACE_STD
#include <AK/DeprecatedString.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/Directory.h>
#include <LibCore/EventLoop.h>
#include <LibCore/StandardPaths.h>
#include <LibCore/Stream.h>
#include <LibCore/SystemServerTakeover.h>
#include <LibMain/Main.h>
#include <QSocketNotifier>
#include <SQLServer/ConnectionFromClient.h>
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
int sql_server_fd_passing_socket { -1 };
Core::ArgsParser args_parser;
args_parser.add_option(sql_server_fd_passing_socket, "File descriptor of the passing socket for the SQLServer connection", "sql-server-fd-passing-socket", 's', "sql_server_fd_passing_socket");
args_parser.parse(arguments);
VERIFY(sql_server_fd_passing_socket >= 0);
auto database_path = DeprecatedString::formatted("{}/Ladybird", Core::StandardPaths::data_directory());
TRY(Core::Directory::create(database_path, Core::Directory::CreateDirectories::Yes));
Core::EventLoop loop;
auto socket = TRY(Core::take_over_socket_from_system_server("SQLServer"sv));
auto client = TRY(SQLServer::ConnectionFromClient::try_create(move(socket), 1));
client->set_fd_passing_socket(TRY(Core::Stream::LocalSocket::adopt_fd(sql_server_fd_passing_socket)));
client->set_database_path(move(database_path));
return loop.exec();
}