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