2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
2021-07-25 15:54:09 -03:00
|
|
|
* Copyright (c) 2021, kleines Filmröllchen <malu.bertsch@gmail.com>
|
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>
|
|
|
|
|
#include <LibCore/File.h>
|
2020-02-17 11:25:03 -03:00
|
|
|
#include <LibCore/LocalServer.h>
|
2019-07-12 14:28:01 -03:00
|
|
|
|
|
|
|
|
int main(int, char**)
|
|
|
|
|
{
|
2021-05-13 18:20:26 -03:00
|
|
|
if (pledge("stdio recvfd thread accept cpath rpath wpath unix", nullptr) < 0) {
|
2020-01-11 17:27:17 -03:00
|
|
|
perror("pledge");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2020-02-17 11:25:03 -03:00
|
|
|
|
2021-08-21 11:33:54 -03:00
|
|
|
auto config = Core::ConfigFile::open_for_app("Audio", Core::ConfigFile::AllowWriting::Yes);
|
2021-07-25 15:54:09 -03:00
|
|
|
if (unveil(config->filename().characters(), "rwc") < 0) {
|
|
|
|
|
perror("unveil");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if (unveil("/dev/audio", "wc") < 0) {
|
|
|
|
|
perror("unveil");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
unveil(nullptr, nullptr);
|
|
|
|
|
|
2020-02-17 11:25:03 -03:00
|
|
|
Core::EventLoop event_loop;
|
2021-07-25 15:54:09 -03:00
|
|
|
AudioServer::Mixer mixer { config };
|
2020-02-17 11:25:03 -03:00
|
|
|
|
|
|
|
|
auto server = Core::LocalServer::construct();
|
|
|
|
|
bool ok = server->take_over_from_system_server();
|
2021-02-23 16:42:32 -03:00
|
|
|
VERIFY(ok);
|
2020-02-17 11:25:03 -03:00
|
|
|
server->on_ready_to_accept = [&] {
|
|
|
|
|
auto client_socket = server->accept();
|
|
|
|
|
if (!client_socket) {
|
2021-01-09 14:51:44 -03:00
|
|
|
dbgln("AudioServer: accept failed.");
|
2020-02-17 11:25:03 -03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
static int s_next_client_id = 0;
|
|
|
|
|
int client_id = ++s_next_client_id;
|
2020-07-06 08:23:39 -03:00
|
|
|
IPC::new_client_connection<AudioServer::ClientConnection>(client_socket.release_nonnull(), client_id, mixer);
|
2020-02-17 11:25:03 -03:00
|
|
|
};
|
|
|
|
|
|
2021-07-25 15:54:09 -03:00
|
|
|
if (pledge("stdio recvfd thread accept cpath rpath wpath", nullptr) < 0) {
|
2020-01-11 17:27:17 -03:00
|
|
|
perror("pledge");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2020-01-21 11:40:48 -03:00
|
|
|
|
2020-08-06 23:33:30 -03:00
|
|
|
unveil(nullptr, nullptr);
|
|
|
|
|
|
2019-07-13 14:42:03 -03:00
|
|
|
return event_loop.exec();
|
2019-07-12 14:28:01 -03:00
|
|
|
}
|