From 5be09d7edff924e7486d743e9d15edf07f555341 Mon Sep 17 00:00:00 2001 From: Mikhail Burakov Date: Mon, 18 Nov 2024 06:34:31 +0100 Subject: WIP --- main.cc | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 main.cc (limited to 'main.cc') diff --git a/main.cc b/main.cc new file mode 100644 index 0000000..ba723a1 --- /dev/null +++ b/main.cc @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2024 Mikhail Burakov. This file is part of streamer. + * + * streamer is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * streamer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with streamer. If not, see . + */ + +#include + +#include +#include +#include +#include +#include +#include + +#include "util.h" + +namespace { + +volatile sig_atomic_t g_signal; +void OnSignal(int status) { g_signal = status; } + +void SetupSignalHandler(int sig, void (*func)(int)) { + struct sigaction sa {}; + sa.sa_handler = func; + if (sigemptyset(&sa.sa_mask) || sigaddset(&sa.sa_mask, sig)) { + throw std::system_error(errno, std::system_category(), + FROM_HERE "Failed to configure signal set"); + } + if (sigaction(sig, &sa, NULL)) { + throw std::system_error(errno, std::system_category(), + FROM_HERE "Failed to set signal action"); + } +} + +} // namespace + +int main(int argc, char* argv[]) { + try { + if (argc < 2) { + throw std::runtime_error(FROM_HERE "Usage: streamer "); + } + + int port = std::atoi(argv[1]); + if (0 >= port || port > UINT16_MAX) { + throw std::runtime_error(FROM_HERE "Invalid port number"); + } + + pw_init(&argc, &argv); + Defer defer_pw_deinit([] { pw_deinit(); }); + + SetupSignalHandler(SIGINT, OnSignal); + SetupSignalHandler(SIGPIPE, SIG_IGN); + SetupSignalHandler(SIGTERM, OnSignal); + + while (!g_signal) { + // BLAH + } + + return EXIT_SUCCESS; + } catch (const std::exception& ex) { + std::cerr << ex.what() << std::endl; + return EXIT_FAILURE; + } +} -- cgit v1.2.3