2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2021-11-29 17:15:44 -03:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
2022-01-13 08:07:00 -03:00
|
|
|
* Copyright (c) 2021, kleines Filmröllchen <filmroellchen@serenityos.org>
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2020-06-12 12:00:03 -03:00
|
|
|
#include "Mixer.h"
|
2021-07-25 15:54:09 -03:00
|
|
|
#include <LibCore/ConfigFile.h>
|
2020-02-17 11:25:03 -03:00
|
|
|
#include <LibCore/LocalServer.h>
|
2021-11-29 17:15:44 -03:00
|
|
|
#include <LibCore/System.h>
|
|
|
|
|
#include <LibMain/Main.h>
|
2019-07-12 14:28:01 -03:00
|
|
|
|
2021-11-29 17:15:44 -03:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments)
|
2019-07-12 14:28:01 -03:00
|
|
|
{
|
2021-11-29 17:15:44 -03:00
|
|
|
TRY(Core::System::pledge("stdio recvfd thread accept cpath rpath wpath unix"));
|
2020-02-17 11:25:03 -03:00
|
|
|
|
2022-02-06 10:33:42 -03:00
|
|
|
auto config = TRY(Core::ConfigFile::open_for_app("Audio", Core::ConfigFile::AllowWriting::Yes));
|
2022-07-11 14:32:29 -03:00
|
|
|
TRY(Core::System::unveil(config->filename(), "rwc"sv));
|
2021-11-29 17:15:44 -03:00
|
|
|
TRY(Core::System::unveil("/dev/audio", "wc"));
|
|
|
|
|
TRY(Core::System::unveil(nullptr, nullptr));
|
2021-07-25 15:54:09 -03:00
|
|
|
|
2020-02-17 11:25:03 -03:00
|
|
|
Core::EventLoop event_loop;
|
2021-11-29 17:15:44 -03:00
|
|
|
auto mixer = TRY(AudioServer::Mixer::try_create(config));
|
|
|
|
|
auto server = TRY(Core::LocalServer::try_create());
|
2021-12-06 12:27:57 -03:00
|
|
|
TRY(server->take_over_from_system_server());
|
2021-11-29 14:42:01 -03:00
|
|
|
|
2022-01-14 10:12:49 -03:00
|
|
|
server->on_accept = [&](NonnullOwnPtr<Core::Stream::LocalSocket> client_socket) {
|
2020-02-17 11:25:03 -03:00
|
|
|
static int s_next_client_id = 0;
|
|
|
|
|
int client_id = ++s_next_client_id;
|
2022-02-25 07:18:30 -03:00
|
|
|
(void)IPC::new_client_connection<AudioServer::ConnectionFromClient>(move(client_socket), client_id, *mixer);
|
2020-02-17 11:25:03 -03:00
|
|
|
};
|
|
|
|
|
|
2021-11-29 17:15:44 -03:00
|
|
|
TRY(Core::System::pledge("stdio recvfd thread accept cpath rpath wpath"));
|
|
|
|
|
TRY(Core::System::unveil(nullptr, nullptr));
|
2020-08-06 23:33:30 -03:00
|
|
|
|
2019-07-13 14:42:03 -03:00
|
|
|
return event_loop.exec();
|
2019-07-12 14:28:01 -03:00
|
|
|
}
|