1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:48:12 +00:00
serenity/Applications/SoundPlayer/main.cpp
Andreas Kling 26a31c7efb Kernel: Add "accept" pledge promise for accepting incoming connections
This patch adds a new "accept" promise that allows you to call accept()
on an already listening socket. This lets programs set up a socket for
for listening and then dropping "inet" and/or "unix" so that only
incoming (and existing) connections are allowed from that point on.
No new outgoing connections or listening server sockets can be created.

In addition to accept() it also allows getsockopt() with SOL_SOCKET
and SO_PEERCRED, which is used to find the PID/UID/GID of the socket
peer. This is used by our IPC library when creating shared buffers that
should only be accessible to a specific peer process.

This allows us to drop "unix" in WindowServer and LookupServer. :^)

It also makes the debugging/introspection RPC sockets in CEventLoop
based programs work again.
2020-01-17 11:19:06 +01:00

82 lines
2.5 KiB
C++

#include "SoundPlayerWidget.h"
#include <LibAudio/AClientConnection.h>
#include <LibDraw/CharacterBitmap.h>
#include <LibGUI/GAboutDialog.h>
#include <LibGUI/GAction.h>
#include <LibGUI/GApplication.h>
#include <LibGUI/GFilePicker.h>
#include <LibGUI/GMenu.h>
#include <LibGUI/GMenuBar.h>
#include <LibGUI/GWindow.h>
#include <stdio.h>
int main(int argc, char** argv)
{
if (pledge("stdio shared_buffer accept rpath unix cpath fattr", nullptr) < 0) {
perror("pledge");
return 1;
}
GApplication app(argc, argv);
if (pledge("stdio shared_buffer accept rpath unix", nullptr) < 0) {
perror("pledge");
return 1;
}
auto audio_client = AClientConnection::construct();
audio_client->handshake();
if (pledge("stdio shared_buffer accept rpath", nullptr) < 0) {
perror("pledge");
return 1;
}
auto window = GWindow::construct();
window->set_title("SoundPlayer");
window->set_resizable(false);
window->set_rect(300, 300, 350, 140);
window->set_icon(GraphicsBitmap::load_from_file("/res/icons/16x16/app-sound-player.png"));
auto menubar = make<GMenuBar>();
auto app_menu = GMenu::construct("SoundPlayer");
auto player = SoundPlayerWidget::construct(window, audio_client);
if (argc > 1) {
String path = argv[1];
player->open_file(path);
player->manager().play();
}
auto hide_scope = GAction::create("Hide scope", { Mod_Ctrl, Key_H }, [&](GAction& action) {
action.set_checked(!action.is_checked());
player->hide_scope(action.is_checked());
});
hide_scope->set_checkable(true);
app_menu->add_action(GCommonActions::make_open_action([&](auto&) {
Optional<String> path = GFilePicker::get_open_filepath("Open wav file...");
if (path.has_value()) {
player->open_file(path.value());
}
}));
app_menu->add_action(move(hide_scope));
app_menu->add_separator();
app_menu->add_action(GCommonActions::make_quit_action([&](auto&) {
app.quit();
}));
auto help_menu = GMenu::construct("Help");
help_menu->add_action(GAction::create("About", [](auto&) {
GAboutDialog::show("SoundPlayer", GraphicsBitmap::load_from_file("/res/icons/32x32/app-sound-player.png"));
}));
menubar->add_menu(move(app_menu));
menubar->add_menu(move(help_menu));
app.set_menubar(move(menubar));
window->set_main_widget(player);
window->show();
return app.exec();
}