Update monado
This commit is contained in:
@@ -19,23 +19,17 @@
|
||||
|
||||
#include "accept_connection.h"
|
||||
|
||||
#include "server/ipc_server_interface.h"
|
||||
|
||||
#include "utils/overloaded.h"
|
||||
|
||||
#include "wivrn_config.h"
|
||||
#include "wivrn_ipc.h"
|
||||
#include "wivrn_sockets.h"
|
||||
|
||||
#include <sys/poll.h>
|
||||
|
||||
static void handle_event_from_main_loop(to_monado::disconnect)
|
||||
{
|
||||
// Ignore disconnect request when no headset is connected
|
||||
}
|
||||
|
||||
static void handle_event_from_main_loop(to_monado::set_bitrate)
|
||||
{
|
||||
// Ignore bitrate request when no headset is connected
|
||||
}
|
||||
|
||||
std::unique_ptr<wivrn::TCP> wivrn::accept_connection(int watch_fd, std::function<bool()> quit)
|
||||
std::unique_ptr<wivrn::TCP> wivrn::accept_connection(ipc_server * server, int watch_fd, std::function<bool()> quit)
|
||||
{
|
||||
wivrn_ipc_socket_monado->send(from_monado::headset_disconnected{});
|
||||
|
||||
@@ -68,7 +62,15 @@ std::unique_ptr<wivrn::TCP> wivrn::accept_connection(int watch_fd, std::function
|
||||
{
|
||||
auto packet = receive_from_main();
|
||||
if (packet)
|
||||
std::visit([](auto && x) { handle_event_from_main_loop(x); }, *packet);
|
||||
std::visit(utils::overloaded{
|
||||
[server](to_monado::stop) {
|
||||
ipc_server_stop(server);
|
||||
},
|
||||
[](auto &&) {
|
||||
// Ignore request when no headset is connected
|
||||
},
|
||||
},
|
||||
*packet);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "server/ipc_server.h"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
class TCP;
|
||||
std::unique_ptr<wivrn::TCP> accept_connection(int watch_fd, std::function<bool()> quit = std::function<bool()>());
|
||||
std::unique_ptr<wivrn::TCP> accept_connection(ipc_server * server, int watch_fd, std::function<bool()> quit = std::function<bool()>());
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -34,6 +34,11 @@
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
static void handle_event_from_main_loop(to_monado::stop)
|
||||
{
|
||||
// Ignore stop request when no headset is connected
|
||||
}
|
||||
|
||||
static void handle_event_from_main_loop(to_monado::disconnect)
|
||||
{
|
||||
// Ignore disconnect request when no headset is connected
|
||||
|
||||
@@ -891,6 +891,12 @@ void wivrn_session::operator()(audio_data && data)
|
||||
audio_handle->process_mic_data(std::move(data));
|
||||
}
|
||||
|
||||
void wivrn_session::operator()(to_monado::stop &&)
|
||||
{
|
||||
assert(mnd_ipc_server);
|
||||
ipc_server_stop(mnd_ipc_server);
|
||||
}
|
||||
|
||||
void wivrn_session::operator()(to_monado::disconnect &&)
|
||||
{
|
||||
connection->shutdown();
|
||||
@@ -1007,6 +1013,7 @@ static bool quit_if_no_client(u_system & xrt_system)
|
||||
|
||||
void wivrn_session::reconnect()
|
||||
{
|
||||
assert(mnd_ipc_server);
|
||||
// Notify clients about disconnected status
|
||||
xrt_session_event event{
|
||||
.state = {
|
||||
@@ -1022,7 +1029,7 @@ void wivrn_session::reconnect()
|
||||
}
|
||||
|
||||
U_LOG_I("Waiting for new connection");
|
||||
auto tcp = accept_connection(0 /*stdin*/, [this]() { return quit_if_no_client(xrt_system); });
|
||||
auto tcp = accept_connection(mnd_ipc_server, 0 /*stdin*/, [this]() { return quit_if_no_client(xrt_system); });
|
||||
if (not tcp)
|
||||
exit(0);
|
||||
|
||||
|
||||
@@ -208,6 +208,7 @@ public:
|
||||
void operator()(const from_headset::stop_application &);
|
||||
void operator()(audio_data &&);
|
||||
|
||||
void operator()(to_monado::stop &&);
|
||||
void operator()(to_monado::disconnect &&);
|
||||
void operator()(to_monado::set_bitrate &&);
|
||||
|
||||
|
||||
+2
-21
@@ -178,7 +178,6 @@ static std::string steam_command()
|
||||
|
||||
namespace
|
||||
{
|
||||
int stdin_pipe_fds[2];
|
||||
int control_pipe_fds[2];
|
||||
|
||||
GMainLoop * main_loop;
|
||||
@@ -238,13 +237,7 @@ void start_server(configuration config)
|
||||
}
|
||||
else if (server_pid == 0)
|
||||
{
|
||||
if (do_fork)
|
||||
{
|
||||
// Redirect stdin
|
||||
dup2(stdin_pipe_fds[0], 0);
|
||||
close(stdin_pipe_fds[0]);
|
||||
close(stdin_pipe_fds[1]);
|
||||
}
|
||||
setenv("XRT_NO_STDIN", "1", true);
|
||||
|
||||
// foveation code does not allow oversampling
|
||||
setenv("XRT_COMPOSITOR_SCALE_PERCENTAGE", "100", true);
|
||||
@@ -302,10 +295,7 @@ void start_server(configuration config)
|
||||
|
||||
void kill_server()
|
||||
{
|
||||
// Write to the server's stdin to make it quit
|
||||
char buffer[] = "\n";
|
||||
if (write(stdin_pipe_fds[1], &buffer, strlen(buffer)) < 0)
|
||||
std::cerr << "Cannot stop monado properly." << std::endl;
|
||||
wivrn_ipc_socket_main_loop->send(to_monado::stop{});
|
||||
|
||||
// Send SIGTERM after 1s if it is still running
|
||||
server_kill_watch = g_timeout_add(1000, [](void *) {
|
||||
@@ -917,15 +907,6 @@ int inner_main(int argc, char * argv[], bool show_instructions)
|
||||
AvahiGLibPoll * glib_poll = avahi_glib_poll_new(main_context, G_PRIORITY_DEFAULT);
|
||||
poll_api = avahi_glib_poll_get(glib_poll);
|
||||
|
||||
// Create a pipe to quit monado properly
|
||||
if (pipe(stdin_pipe_fds) < 0)
|
||||
{
|
||||
perror("pipe");
|
||||
return wivrn_exit_code::cannot_create_pipe;
|
||||
}
|
||||
fcntl(stdin_pipe_fds[0], F_SETFD, FD_CLOEXEC);
|
||||
fcntl(stdin_pipe_fds[1], F_SETFD, FD_CLOEXEC);
|
||||
|
||||
// Create a socket to report monado status to the main loop
|
||||
if (socketpair(AF_UNIX, SOCK_DGRAM, 0, control_pipe_fds) < 0)
|
||||
{
|
||||
|
||||
+4
-1
@@ -64,6 +64,9 @@ using packets = std::variant<
|
||||
|
||||
namespace to_monado
|
||||
{
|
||||
struct stop
|
||||
{};
|
||||
|
||||
struct disconnect
|
||||
{};
|
||||
|
||||
@@ -72,7 +75,7 @@ struct set_bitrate
|
||||
uint32_t bitrate_bps;
|
||||
};
|
||||
|
||||
using packets = std::variant<disconnect, set_bitrate>;
|
||||
using packets = std::variant<stop, disconnect, set_bitrate>;
|
||||
} // namespace to_monado
|
||||
|
||||
extern std::optional<wivrn::typed_socket<wivrn::UnixDatagram, to_monado::packets, from_monado::packets>> wivrn_ipc_socket_monado;
|
||||
|
||||
Reference in New Issue
Block a user