Add support for authentication and encryption
This commit is contained in:
committed by
Patrick Nicolas
parent
447b77c35c
commit
c6e773fd22
@@ -32,7 +32,7 @@ static void handle_event_from_main_loop(to_monado::disconnect)
|
||||
|
||||
std::unique_ptr<wivrn::TCP> wivrn::accept_connection(int watch_fd, std::function<bool()> quit)
|
||||
{
|
||||
wivrn_ipc_socket_monado->send(from_monado::headsdet_disconnected{});
|
||||
wivrn_ipc_socket_monado->send(from_monado::headset_disconnected{});
|
||||
|
||||
wivrn::TCPListener listener(wivrn::default_port);
|
||||
|
||||
@@ -55,7 +55,7 @@ std::unique_ptr<wivrn::TCP> wivrn::accept_connection(int watch_fd, std::function
|
||||
|
||||
if (fds[1].revents & POLLIN)
|
||||
{
|
||||
wivrn_ipc_socket_monado->send(from_monado::headsdet_connected{});
|
||||
wivrn_ipc_socket_monado->send(from_monado::headset_connected{});
|
||||
return std::make_unique<wivrn::TCP>(listener.accept().first);
|
||||
}
|
||||
|
||||
|
||||
@@ -305,15 +305,14 @@ void pipewire_device::speaker_process(void * self_v)
|
||||
if (not data.data)
|
||||
return;
|
||||
|
||||
audio_data packet{
|
||||
.timestamp = self->session.get_offset().to_headset(os_monotonic_get_ns()),
|
||||
.payload = std::span(
|
||||
(uint8_t *)data.data + data.chunk->offset,
|
||||
data.chunk->size),
|
||||
};
|
||||
try
|
||||
{
|
||||
self->session.send_control(packet);
|
||||
self->session.send_control(audio_data{
|
||||
.timestamp = self->session.get_offset().to_headset(os_monotonic_get_ns()),
|
||||
.payload = std::span(
|
||||
(uint8_t *)data.data + data.chunk->offset,
|
||||
data.chunk->size),
|
||||
});
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
|
||||
@@ -301,7 +301,6 @@ struct pulse_device : public audio_device
|
||||
// use buffers of up to 2ms
|
||||
// read buffers must be smaller than buffer size on client or we will discard chunks often
|
||||
const size_t buffer_size = (desc.speaker->sample_rate * sample_size * 2) / 1000;
|
||||
wivrn::audio_data packet;
|
||||
std::vector<uint8_t> buffer(buffer_size, 0);
|
||||
size_t remainder = 0;
|
||||
|
||||
@@ -338,12 +337,13 @@ struct pulse_device : public audio_device
|
||||
size += remainder; // full size of available data
|
||||
remainder = size % sample_size; // data to keep for next iteration
|
||||
size -= remainder; // size of data to send
|
||||
packet.payload = std::span<uint8_t>(buffer.begin(), size);
|
||||
packet.timestamp = session.get_offset().to_headset(os_monotonic_get_ns());
|
||||
|
||||
try
|
||||
{
|
||||
session.send_control(packet);
|
||||
session.send_control(wivrn::audio_data{
|
||||
.timestamp = session.get_offset().to_headset(os_monotonic_get_ns()),
|
||||
.payload = std::span<uint8_t>(buffer.begin(), size),
|
||||
});
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
|
||||
@@ -17,16 +17,18 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#define JSON_DISABLE_ENUM_SERIALIZATION 1
|
||||
#ifdef JSON_DIAGNOSTICS
|
||||
#undef JSON_DIAGNOSTICS
|
||||
#endif
|
||||
#define JSON_DIAGNOSTICS 1
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <random>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
|
||||
#include "util/u_logging.h"
|
||||
|
||||
@@ -34,6 +36,7 @@
|
||||
#include "utils/xdg_base_directory.h"
|
||||
|
||||
static std::filesystem::path config_file = xdg_config_home() / "wivrn" / "config.json";
|
||||
static std::filesystem::path known_keys_file = xdg_config_home() / "wivrn" / "known_keys.json";
|
||||
static std::filesystem::path cookie_file = xdg_config_home() / "wivrn" / "cookie";
|
||||
|
||||
namespace wivrn
|
||||
@@ -181,4 +184,96 @@ std::string server_cookie()
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<headset_key> known_keys()
|
||||
{
|
||||
if (not std::filesystem::exists(known_keys_file))
|
||||
return {};
|
||||
|
||||
try
|
||||
{
|
||||
std::ifstream file(known_keys_file);
|
||||
std::vector<headset_key> keys;
|
||||
auto json = nlohmann::json::parse(file);
|
||||
|
||||
for (const auto & key: json)
|
||||
{
|
||||
keys.emplace_back(key["key"], key["name"]);
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
||||
catch (const std::exception & e)
|
||||
{
|
||||
U_LOG_E("Invalid key file: %s", e.what());
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
static void save_keys(const std::vector<headset_key> & keys)
|
||||
{
|
||||
nlohmann::json json;
|
||||
|
||||
for (const auto & key: keys)
|
||||
{
|
||||
json.push_back(nlohmann::json{
|
||||
{"key", key.public_key},
|
||||
{"name", key.name},
|
||||
});
|
||||
}
|
||||
|
||||
std::string json_str = json.dump();
|
||||
|
||||
std::filesystem::path known_keys_file_new = known_keys_file;
|
||||
known_keys_file_new += ".new";
|
||||
|
||||
std::ofstream file(known_keys_file_new);
|
||||
file.write(json_str.data(), json_str.size());
|
||||
|
||||
std::error_code ec;
|
||||
std::filesystem::rename(known_keys_file_new, known_keys_file, ec);
|
||||
|
||||
if (ec)
|
||||
U_LOG_E("Failed to save keys: %s", ec.message().c_str());
|
||||
}
|
||||
|
||||
void add_known_key(headset_key key)
|
||||
{
|
||||
std::vector<headset_key> keys = known_keys();
|
||||
|
||||
if (key.name == "")
|
||||
key.name = "Unknown headset";
|
||||
|
||||
int n = 1;
|
||||
std::string original_name = key.name;
|
||||
while (std::ranges::any_of(keys, [&](const headset_key & k) { return k.name == key.name; }))
|
||||
{
|
||||
key.name = original_name + " (" + std::to_string(++n) + ")";
|
||||
}
|
||||
|
||||
keys.push_back(key);
|
||||
|
||||
save_keys(keys);
|
||||
}
|
||||
|
||||
void remove_known_key(const std::string & key)
|
||||
{
|
||||
std::vector<headset_key> keys = known_keys();
|
||||
std::erase_if(keys, [&](const headset_key & k) { return k.public_key == key; });
|
||||
|
||||
save_keys(keys);
|
||||
}
|
||||
|
||||
void rename_known_key(headset_key key)
|
||||
{
|
||||
std::vector<headset_key> keys = known_keys();
|
||||
for (headset_key & k: keys)
|
||||
{
|
||||
if (k.public_key == key.public_key)
|
||||
k.name = key.name;
|
||||
}
|
||||
|
||||
save_keys(keys);
|
||||
}
|
||||
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
|
||||
struct configuration
|
||||
{
|
||||
struct encoder
|
||||
@@ -58,4 +57,16 @@ struct configuration
|
||||
};
|
||||
|
||||
std::string server_cookie();
|
||||
|
||||
struct headset_key
|
||||
{
|
||||
std::string public_key;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
std::vector<headset_key> known_keys();
|
||||
void add_known_key(headset_key key);
|
||||
void remove_known_key(const std::string & key);
|
||||
void rename_known_key(headset_key key);
|
||||
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -124,7 +124,7 @@ static void create_encoders(wivrn_comp_target * cn)
|
||||
assert(cn->wivrn_bundle);
|
||||
cn->psc.status = 0;
|
||||
|
||||
auto & desc = cn->desc;
|
||||
to_headset::video_stream_description & desc = cn->desc;
|
||||
desc.width = cn->width;
|
||||
desc.height = cn->height;
|
||||
desc.foveation = cn->cnx.set_foveated_size(desc.width, desc.height);
|
||||
@@ -148,7 +148,7 @@ static void create_encoders(wivrn_comp_target * cn)
|
||||
std::string name = "encoder " + std::to_string(group);
|
||||
pthread_setname_np(thread.native_handle(), name.c_str());
|
||||
}
|
||||
cn->cnx.send_control(desc);
|
||||
cn->cnx.send_control(to_headset::video_stream_description{desc});
|
||||
}
|
||||
|
||||
static VkResult create_images(struct wivrn_comp_target * cn, vk::ImageUsageFlags flags)
|
||||
@@ -746,7 +746,7 @@ void wivrn_comp_target::reset_encoders()
|
||||
pacer.reset();
|
||||
for (auto & encoder: encoders)
|
||||
encoder->reset();
|
||||
cnx.send_control(desc);
|
||||
cnx.send_control(to_headset::video_stream_description{desc});
|
||||
}
|
||||
|
||||
void wivrn_comp_target::render_dynamic_foveation(std::array<to_headset::foveation_parameter, 2> foveation)
|
||||
|
||||
@@ -19,11 +19,16 @@
|
||||
|
||||
#include "wivrn_connection.h"
|
||||
#include "configuration.h"
|
||||
#include "util/u_logging.h"
|
||||
#include "secrets.h"
|
||||
#include "wivrn_ipc.h"
|
||||
#include "wivrn_packets.h"
|
||||
#include <algorithm>
|
||||
#include <arpa/inet.h>
|
||||
#include <chrono>
|
||||
#include <poll.h>
|
||||
#include <regex>
|
||||
#include <sys/socket.h>
|
||||
#include <variant>
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
@@ -32,16 +37,30 @@ static void handle_event_from_main_loop(to_monado::disconnect)
|
||||
// Ignore disconnect request when no headset is connected
|
||||
}
|
||||
|
||||
wivrn::wivrn_connection::wivrn_connection(TCP && tcp) :
|
||||
control(std::move(tcp)), stream(-1)
|
||||
static std::string clean_key(std::string key)
|
||||
{
|
||||
init();
|
||||
static const std::regex header{"^-+BEGIN .*-+$", std::regex_constants::multiline};
|
||||
static const std::regex footer{"^-+END .*-+$", std::regex_constants::multiline};
|
||||
static const std::regex whitespace{"[[:space:]]"};
|
||||
|
||||
key = std::regex_replace(key, header, "");
|
||||
key = std::regex_replace(key, footer, "");
|
||||
key = std::regex_replace(key, whitespace, "");
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
void wivrn::wivrn_connection::init()
|
||||
wivrn::wivrn_connection::wivrn_connection(std::stop_token stop_token, const std::string & pin, TCP && tcp) :
|
||||
control(std::move(tcp)),
|
||||
stream(-1),
|
||||
pin(pin)
|
||||
{
|
||||
init(stop_token);
|
||||
}
|
||||
|
||||
void wivrn::wivrn_connection::init(std::stop_token stop_token, std::function<void()> tick)
|
||||
{
|
||||
active = false;
|
||||
stream = -1;
|
||||
|
||||
sockaddr_in6 server_address;
|
||||
socklen_t len = sizeof(server_address);
|
||||
@@ -58,9 +77,6 @@ void wivrn::wivrn_connection::init()
|
||||
throw std::system_error(errno, std::system_category(), "Cannot get client address");
|
||||
}
|
||||
|
||||
// Wait for client to send handshake
|
||||
auto timeout = std::chrono::steady_clock::now() + std::chrono::seconds(10);
|
||||
|
||||
if (configuration::read_user_configuration().tcp_only)
|
||||
{
|
||||
port = -1;
|
||||
@@ -71,84 +87,141 @@ void wivrn::wivrn_connection::init()
|
||||
stream.bind(port);
|
||||
}
|
||||
|
||||
auto receive = [&](std::optional<std::chrono::seconds> timeout = std::nullopt, bool allow_stream_socket = false) {
|
||||
// Returns the packet and the port (on the stream socket) or -1 (on the control socket)
|
||||
|
||||
std::chrono::steady_clock::time_point timeout_abs{};
|
||||
if (timeout)
|
||||
timeout_abs = std::chrono::steady_clock::now() + *timeout;
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (stop_token.stop_requested())
|
||||
throw std::runtime_error("Connection cancelled");
|
||||
|
||||
tick();
|
||||
|
||||
pollfd fds[3] = {};
|
||||
if (allow_stream_socket)
|
||||
{
|
||||
fds[0].events = POLLIN;
|
||||
fds[0].fd = stream.get_fd();
|
||||
}
|
||||
fds[1].events = POLLIN;
|
||||
fds[1].fd = control.get_fd();
|
||||
fds[2].events = POLLIN;
|
||||
fds[2].fd = wivrn_ipc_socket_monado->get_fd();
|
||||
|
||||
// Make sure tick() is called at least every 100ms
|
||||
int r = ::poll(fds, std::size(fds), 100);
|
||||
if (r < 0)
|
||||
throw std::system_error(errno, std::system_category());
|
||||
|
||||
if (allow_stream_socket and (fds[0].revents & (POLLHUP | POLLERR)))
|
||||
throw std::runtime_error("Error on stream socket");
|
||||
|
||||
if (fds[1].revents & (POLLHUP | POLLERR))
|
||||
throw std::runtime_error("Error on control socket");
|
||||
|
||||
if (fds[2].revents & (POLLHUP | POLLERR))
|
||||
throw std::runtime_error("Error on IPC socket");
|
||||
|
||||
if (allow_stream_socket and (fds[0].revents & POLLIN))
|
||||
{
|
||||
auto [raw_packet, peer_addr] = stream.receive_from_raw();
|
||||
|
||||
// Ignore packets sent from the wrong address
|
||||
if (memcmp(&peer_addr.sin6_addr, &client_address.sin6_addr, sizeof(peer_addr.sin6_addr)) == 0)
|
||||
return std::make_pair(raw_packet.deserialize<from_headset::packets>(), (int)htons(peer_addr.sin6_port));
|
||||
}
|
||||
|
||||
if (fds[1].revents & POLLIN)
|
||||
{
|
||||
std::optional<from_headset::packets> packet = control.receive();
|
||||
if (packet)
|
||||
return std::make_pair(std::move(*packet), -1);
|
||||
}
|
||||
|
||||
if (fds[2].revents & POLLIN)
|
||||
{
|
||||
auto packet = receive_from_main();
|
||||
if (packet)
|
||||
std::visit([](auto && x) { handle_event_from_main_loop(x); }, *packet);
|
||||
}
|
||||
|
||||
if (timeout and std::chrono::steady_clock::now() > timeout_abs)
|
||||
{
|
||||
throw std::runtime_error("No handshake received from client");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Wait for client to send handshake packet
|
||||
auto crypto_handshake = std::get<from_headset::crypto_handshake>(receive(10s).first);
|
||||
crypto::key headset_key = crypto::key::from_public_key(crypto_handshake.public_key);
|
||||
|
||||
bool is_public_key_known = std::ranges::any_of(
|
||||
wivrn::known_keys(),
|
||||
[key = clean_key(crypto_handshake.public_key)](const wivrn::headset_key & k) {
|
||||
return k.public_key == key;
|
||||
});
|
||||
|
||||
// Generate an ephemeral key pair just for exchanging the AES key
|
||||
crypto::key server_key = crypto::key::generate_x448_keypair();
|
||||
|
||||
control.send(to_headset::crypto_handshake{
|
||||
.public_key = server_key.public_key(),
|
||||
.pin_required = not is_public_key_known,
|
||||
});
|
||||
|
||||
secrets s{server_key, headset_key, is_public_key_known ? "000000" : pin};
|
||||
control.set_aes_key_and_ivs(s.control_key, s.control_iv_from_headset, s.control_iv_to_headset);
|
||||
stream.set_aes_key_and_ivs(s.stream_key, s.stream_iv_header_from_headset, s.stream_iv_header_to_headset);
|
||||
|
||||
// Wait for confirmation that the client has set up encryption
|
||||
if (not std::holds_alternative<from_headset::crypto_handshake>(receive().first))
|
||||
throw std::runtime_error("No handshake received from client");
|
||||
|
||||
control.send(to_headset::handshake{.stream_port = port});
|
||||
|
||||
while (true)
|
||||
auto [stream_handshake, client_port] = receive(10s, true);
|
||||
|
||||
// Check the packet type
|
||||
if (not std::holds_alternative<from_headset::handshake>(stream_handshake))
|
||||
{
|
||||
pollfd fds[3] = {};
|
||||
fds[0].events = POLLIN;
|
||||
fds[0].fd = stream.get_fd();
|
||||
fds[1].events = POLLIN;
|
||||
fds[1].fd = control.get_fd();
|
||||
fds[2].fd = wivrn_ipc_socket_monado->get_fd();
|
||||
fds[2].events = POLLIN;
|
||||
|
||||
int r = ::poll(fds, std::size(fds), 1000);
|
||||
if (r < 0)
|
||||
throw std::system_error(errno, std::system_category());
|
||||
|
||||
if (fds[0].revents & (POLLHUP | POLLERR))
|
||||
throw std::runtime_error("Error on stream socket");
|
||||
|
||||
if (fds[1].revents & (POLLHUP | POLLERR))
|
||||
throw std::runtime_error("Error on control socket");
|
||||
|
||||
if (fds[2].revents & (POLLHUP | POLLERR))
|
||||
throw std::runtime_error("Error on IPC socket");
|
||||
|
||||
if (fds[0].revents & POLLIN)
|
||||
{
|
||||
auto [packet, peer_addr] = stream.receive_from_raw();
|
||||
if (memcmp(&peer_addr.sin6_addr, &client_address.sin6_addr, sizeof(peer_addr.sin6_addr)) == 0)
|
||||
{
|
||||
int client_port = htons(peer_addr.sin6_port);
|
||||
stream.connect(peer_addr.sin6_addr, client_port);
|
||||
U_LOG_D("Stream socket connected, client port %d", client_port);
|
||||
stream.set_send_buffer_size(1024 * 1024 * 5);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (fds[1].revents & POLLIN)
|
||||
{
|
||||
auto packet = control.receive();
|
||||
if (packet)
|
||||
{
|
||||
if (std::holds_alternative<from_headset::handshake>(*packet))
|
||||
{
|
||||
stream = decltype(stream)(-1);
|
||||
port = -1;
|
||||
U_LOG_I("Using TCP only");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("Invalid handshake received from client");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fds[2].revents & POLLIN)
|
||||
{
|
||||
auto packet = receive_from_main();
|
||||
if (packet)
|
||||
std::visit([](auto && x) { handle_event_from_main_loop(x); }, *packet);
|
||||
}
|
||||
|
||||
if (std::chrono::steady_clock::now() > timeout)
|
||||
{
|
||||
throw std::runtime_error("No handshake received from client");
|
||||
}
|
||||
throw std::runtime_error("No handshake received from client");
|
||||
}
|
||||
|
||||
if (client_port >= 0)
|
||||
{
|
||||
stream.connect(client_address.sin6_addr, client_port);
|
||||
stream.set_send_buffer_size(1024 * 1024 * 5);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No stream socket
|
||||
}
|
||||
|
||||
control.send(to_headset::handshake{.stream_port = port});
|
||||
|
||||
info_packet = std::get<from_headset::headset_info_packet>(receive(10s).first);
|
||||
|
||||
active = true;
|
||||
|
||||
if (not is_public_key_known)
|
||||
wivrn::add_known_key({
|
||||
.public_key = clean_key(headset_key.public_key()),
|
||||
.name = crypto_handshake.name,
|
||||
});
|
||||
}
|
||||
|
||||
void wivrn::wivrn_connection::reset(TCP && tcp)
|
||||
void wivrn::wivrn_connection::reset(TCP && tcp, std::function<void()> tick)
|
||||
{
|
||||
if (stream)
|
||||
stream = decltype(stream)();
|
||||
|
||||
control = std::move(tcp);
|
||||
init();
|
||||
init({}, tick);
|
||||
}
|
||||
|
||||
void wivrn::wivrn_connection::shutdown()
|
||||
|
||||
@@ -27,21 +27,24 @@
|
||||
#include <optional>
|
||||
#include <poll.h>
|
||||
#include <stdexcept>
|
||||
#include <stop_token>
|
||||
#include <system_error>
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
|
||||
class wivrn_connection
|
||||
{
|
||||
typed_socket<TCP, from_headset::packets, to_headset::packets> control;
|
||||
typed_socket<UDP, from_headset::packets, to_headset::packets> stream;
|
||||
std::atomic<bool> active = false;
|
||||
std::string pin;
|
||||
|
||||
void init();
|
||||
wivrn::from_headset::headset_info_packet info_packet;
|
||||
|
||||
void init(std::stop_token stop_token, std::function<void()> tick = []() {});
|
||||
|
||||
public:
|
||||
wivrn_connection(TCP && tcp);
|
||||
wivrn_connection(std::stop_token stop_token, const std::string & pin, TCP && tcp);
|
||||
wivrn_connection(const wivrn_connection &) = delete;
|
||||
wivrn_connection & operator=(const wivrn_connection &) = delete;
|
||||
|
||||
@@ -49,7 +52,7 @@ public:
|
||||
{
|
||||
return active;
|
||||
}
|
||||
void reset(TCP && tcp);
|
||||
void reset(TCP && tcp, std::function<void()> tick = []() {});
|
||||
void shutdown();
|
||||
|
||||
template <typename T>
|
||||
@@ -66,15 +69,19 @@ public:
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void send_stream(T && packet)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (active and stream)
|
||||
stream.send(std::forward<T>(packet));
|
||||
else
|
||||
control.send(std::forward<T>(packet));
|
||||
if (active)
|
||||
{
|
||||
if (stream)
|
||||
stream.send(std::forward<T>(packet));
|
||||
else
|
||||
control.send(std::forward<T>(packet));
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@@ -85,6 +92,11 @@ public:
|
||||
|
||||
std::optional<from_headset::packets> poll_control(int timeout);
|
||||
|
||||
const wivrn::from_headset::headset_info_packet & info() const
|
||||
{
|
||||
return info_packet;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int poll(T && visitor, int timeout)
|
||||
{
|
||||
|
||||
@@ -122,24 +122,16 @@ bool wivrn::tracking_control_t::set_enabled(to_headset::tracking_control::id id,
|
||||
return changed;
|
||||
}
|
||||
|
||||
wivrn::wivrn_session::wivrn_session(wivrn::TCP && tcp, u_system & system) :
|
||||
wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection, u_system & system) :
|
||||
xrt_system_devices{
|
||||
.get_roles = [](xrt_system_devices * self, xrt_system_roles * out_roles) { return ((wivrn_session *)self)->get_roles(out_roles); },
|
||||
.feature_inc = [](xrt_system_devices * self, xrt_device_feature_type f) { return ((wivrn_session *)self)->feature_inc(f); },
|
||||
.feature_dec = [](xrt_system_devices * self, xrt_device_feature_type f) { return ((wivrn_session *)self)->feature_dec(f); },
|
||||
.destroy = [](xrt_system_devices * self) { delete ((wivrn_session *)self); },
|
||||
},
|
||||
connection(std::move(tcp)),
|
||||
info([](wivrn_connection & connection) {
|
||||
std::optional<wivrn::from_headset::packets> control;
|
||||
while (not(control = connection.poll_control(-1)))
|
||||
{
|
||||
// FIXME: timeout
|
||||
}
|
||||
return std::get<from_headset::headset_info_packet>(*control);
|
||||
}(connection)),
|
||||
connection(std::move(connection)),
|
||||
xrt_system(system),
|
||||
hmd(this, info),
|
||||
hmd(this, get_info()),
|
||||
left_hand(0, &hmd, this),
|
||||
right_hand(1, &hmd, this)
|
||||
{
|
||||
@@ -150,7 +142,7 @@ wivrn::wivrn_session::wivrn_session(wivrn::TCP && tcp, u_system & system) :
|
||||
"WiVRn(microphone)",
|
||||
"wivrn.sink",
|
||||
"WiVRn",
|
||||
info,
|
||||
get_info(),
|
||||
*this);
|
||||
if (audio_handle)
|
||||
send_control(audio_handle->description());
|
||||
@@ -198,14 +190,14 @@ wivrn::wivrn_session::wivrn_session(wivrn::TCP && tcp, u_system & system) :
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (info.eye_gaze || is_forced_extension("EXT_eye_gaze_interaction"))
|
||||
if (get_info().eye_gaze || is_forced_extension("EXT_eye_gaze_interaction"))
|
||||
{
|
||||
eye_tracker = std::make_unique<wivrn_eye_tracker>(&hmd);
|
||||
foveation = std::make_unique<wivrn_foveation>();
|
||||
static_roles.eyes = eye_tracker.get();
|
||||
xdevs[xdev_count++] = eye_tracker.get();
|
||||
}
|
||||
if (info.face_tracking2_fb || is_forced_extension("FB_face_tracking2"))
|
||||
if (get_info().face_tracking2_fb || is_forced_extension("FB_face_tracking2"))
|
||||
{
|
||||
fb_face2_tracker = std::make_unique<wivrn_fb_face2_tracker>(&hmd, *this);
|
||||
static_roles.face = fb_face2_tracker.get();
|
||||
@@ -234,10 +226,10 @@ wivrn::wivrn_session::wivrn_session(wivrn::TCP && tcp, u_system & system) :
|
||||
|
||||
wivrn_session::~wivrn_session()
|
||||
{
|
||||
connection.shutdown();
|
||||
connection->shutdown();
|
||||
}
|
||||
|
||||
xrt_result_t wivrn::wivrn_session::create_session(wivrn::TCP && tcp,
|
||||
xrt_result_t wivrn::wivrn_session::create_session(std::unique_ptr<wivrn_connection> connection,
|
||||
u_system & system,
|
||||
xrt_system_devices ** out_xsysd,
|
||||
xrt_space_overseer ** out_xspovrs,
|
||||
@@ -246,7 +238,7 @@ xrt_result_t wivrn::wivrn_session::create_session(wivrn::TCP && tcp,
|
||||
std::unique_ptr<wivrn_session> self;
|
||||
try
|
||||
{
|
||||
self.reset(new wivrn_session(std::move(tcp), system));
|
||||
self.reset(new wivrn_session(std::move(connection), system));
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
@@ -254,9 +246,9 @@ xrt_result_t wivrn::wivrn_session::create_session(wivrn::TCP && tcp,
|
||||
return XRT_ERROR_DEVICE_CREATION_FAILED;
|
||||
}
|
||||
|
||||
send_to_main(self->info);
|
||||
send_to_main(self->get_info());
|
||||
|
||||
wivrn_comp_target_factory ctf(*self, self->info.preferred_refresh_rate);
|
||||
wivrn_comp_target_factory ctf(*self, self->get_info().preferred_refresh_rate);
|
||||
auto xret = comp_main_create_system_compositor(&self->hmd, &ctf, out_xsysc);
|
||||
if (xret != XRT_SUCCESS)
|
||||
{
|
||||
@@ -294,7 +286,7 @@ clock_offset wivrn_session::get_offset()
|
||||
|
||||
bool wivrn_session::connected()
|
||||
{
|
||||
return connection.is_active();
|
||||
return connection->is_active();
|
||||
}
|
||||
|
||||
void wivrn_session::operator()(from_headset::headset_info_packet &&)
|
||||
@@ -379,7 +371,7 @@ void wivrn_session::set_enabled(to_headset::tracking_control::id id, bool enable
|
||||
void wivrn_session::set_enabled(device_id id, bool enabled)
|
||||
{
|
||||
if (tracking_control.set_enabled(to_tracking_control(id), enabled) and enabled)
|
||||
tracking_control.send(connection, true);
|
||||
tracking_control.send(*connection, true);
|
||||
}
|
||||
|
||||
void wivrn_session::operator()(from_headset::feedback && feedback)
|
||||
@@ -426,9 +418,9 @@ void wivrn_session::run(std::stop_token stop)
|
||||
{
|
||||
try
|
||||
{
|
||||
offset_est.request_sample(connection);
|
||||
tracking_control.send(connection);
|
||||
connection.poll(*this, 20);
|
||||
offset_est.request_sample(*connection);
|
||||
tracking_control.send(*connection);
|
||||
connection->poll(*this, 20);
|
||||
}
|
||||
catch (const std::exception & e)
|
||||
{
|
||||
@@ -504,17 +496,18 @@ void wivrn_session::reconnect()
|
||||
if (not tcp)
|
||||
exit(0);
|
||||
|
||||
struct no_client_connected
|
||||
{};
|
||||
|
||||
try
|
||||
{
|
||||
offset_est.reset();
|
||||
connection.reset(std::move(*tcp));
|
||||
std::optional<wivrn::from_headset::packets> control;
|
||||
while (not(control = connection.poll_control(100)))
|
||||
{
|
||||
// FIXME: timeout
|
||||
quit_if_no_client(xrt_system);
|
||||
}
|
||||
const auto & info = std::get<from_headset::headset_info_packet>(*control);
|
||||
connection->reset(std::move(*tcp), [this]() {
|
||||
if (quit_if_no_client(xrt_system))
|
||||
throw no_client_connected{};
|
||||
});
|
||||
|
||||
// const auto & info = connection->info();
|
||||
// FIXME: ensure new client is compatible
|
||||
|
||||
comp_target->reset_encoders();
|
||||
@@ -529,6 +522,11 @@ void wivrn_session::reconnect()
|
||||
U_LOG_W("Failed to notify session state change");
|
||||
}
|
||||
}
|
||||
catch (no_client_connected)
|
||||
{
|
||||
U_LOG_I("No OpenXR application connected");
|
||||
exit(0);
|
||||
}
|
||||
catch (const std::exception & e)
|
||||
{
|
||||
U_LOG_E("Reconnection failed: %s", e.what());
|
||||
|
||||
@@ -77,8 +77,7 @@ public:
|
||||
class wivrn_session : public xrt_system_devices
|
||||
{
|
||||
friend wivrn_comp_target_factory;
|
||||
wivrn_connection connection;
|
||||
from_headset::headset_info_packet info{};
|
||||
std::unique_ptr<wivrn_connection> connection;
|
||||
|
||||
u_system & xrt_system;
|
||||
xrt_space_overseer * space_overseer;
|
||||
@@ -113,12 +112,12 @@ class wivrn_session : public xrt_system_devices
|
||||
|
||||
std::jthread thread;
|
||||
|
||||
wivrn_session(TCP && tcp, u_system &);
|
||||
wivrn_session(std::unique_ptr<wivrn_connection> connection, u_system &);
|
||||
|
||||
public:
|
||||
~wivrn_session();
|
||||
|
||||
static xrt_result_t create_session(TCP && tcp,
|
||||
static xrt_result_t create_session(std::unique_ptr<wivrn_connection> connection,
|
||||
u_system & system,
|
||||
xrt_system_devices ** out_xsysd,
|
||||
xrt_space_overseer ** out_xspovrs,
|
||||
@@ -128,7 +127,7 @@ public:
|
||||
bool connected();
|
||||
const from_headset::headset_info_packet & get_info()
|
||||
{
|
||||
return info;
|
||||
return connection->info();
|
||||
};
|
||||
|
||||
void add_predict_offset(std::chrono::nanoseconds off)
|
||||
@@ -139,8 +138,9 @@ public:
|
||||
void set_enabled(to_headset::tracking_control::id id, bool enabled);
|
||||
void set_enabled(device_id id, bool enabled);
|
||||
|
||||
void operator()(from_headset::handshake &&) {}
|
||||
void operator()(from_headset::crypto_handshake &&) {}
|
||||
void operator()(from_headset::headset_info_packet &&);
|
||||
void operator()(from_headset::handshake &&) {}
|
||||
void operator()(from_headset::trackings &&);
|
||||
void operator()(const from_headset::tracking &);
|
||||
void operator()(from_headset::hand_tracking &&);
|
||||
@@ -155,13 +155,13 @@ public:
|
||||
template <typename T>
|
||||
void send_stream(T && packet)
|
||||
{
|
||||
connection.send_stream(std::forward<T>(packet));
|
||||
connection->send_stream(std::forward<T>(packet));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void send_control(T && packet)
|
||||
{
|
||||
connection.send_control(std::forward<T>(packet));
|
||||
connection->send_control(std::forward<T>(packet));
|
||||
}
|
||||
|
||||
std::array<to_headset::foveation_parameter, 2> set_foveated_size(uint32_t width, uint32_t height);
|
||||
|
||||
@@ -340,7 +340,7 @@ void video_encoder::SendData(std::span<uint8_t> data, bool end_of_frame)
|
||||
shard.payload = {begin, next};
|
||||
try
|
||||
{
|
||||
cnx->send_stream(shard);
|
||||
cnx->send_stream(to_headset::video_stream_data_shard{shard});
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
|
||||
+154
-40
@@ -12,11 +12,13 @@
|
||||
#include "active_runtime.h"
|
||||
#include "avahi_publisher.h"
|
||||
#include "driver/configuration.h"
|
||||
#include "driver/wivrn_connection.h"
|
||||
#include "exit_codes.h"
|
||||
#include "hostname.h"
|
||||
#include "protocol_version.h"
|
||||
#include "start_application.h"
|
||||
#include "utils/flatpak.h"
|
||||
#include "utils/overloaded.h"
|
||||
#include "version.h"
|
||||
#include "wivrn_config.h"
|
||||
#include "wivrn_ipc.h"
|
||||
@@ -32,9 +34,11 @@
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <poll.h>
|
||||
#include <random>
|
||||
#include <sys/signalfd.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/wait.h>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <gio/gio.h>
|
||||
@@ -78,7 +82,8 @@ int create_listen_socket()
|
||||
addr.sun_family = AF_UNIX;
|
||||
strcpy(addr.sun_path, sock_file.c_str());
|
||||
|
||||
int fd = socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
|
||||
int fd = socket(PF_UNIX, SOCK_STREAM, 0);
|
||||
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||
int ret = bind(fd, (struct sockaddr *)&addr, sizeof(addr));
|
||||
|
||||
// no other instance is running, or we would have never arrived here
|
||||
@@ -187,6 +192,7 @@ bool use_systemd;
|
||||
guint server_watch;
|
||||
guint server_kill_watch;
|
||||
pid_t server_pid;
|
||||
std::optional<std::jthread> connection_thread;
|
||||
|
||||
guint app_watch;
|
||||
guint app_kill_watch;
|
||||
@@ -198,6 +204,8 @@ bool avahi_publish;
|
||||
|
||||
guint listener_watch;
|
||||
|
||||
std::string pin;
|
||||
|
||||
WivrnServer * dbus_server;
|
||||
|
||||
/* TODO: Document FSM
|
||||
@@ -209,6 +217,8 @@ std::optional<sleep_inhibitor> inhibitor;
|
||||
gboolean headset_connected(gint fd, GIOCondition condition, gpointer user_data);
|
||||
void stop_listening();
|
||||
void on_headset_info_packet(const wivrn::from_headset::headset_info_packet & info);
|
||||
void expose_known_keys_on_dbus();
|
||||
void choose_pin();
|
||||
|
||||
void start_publishing();
|
||||
void stop_publishing();
|
||||
@@ -246,8 +256,6 @@ void start_app()
|
||||
|
||||
void start_server()
|
||||
{
|
||||
stop_listening();
|
||||
stop_publishing();
|
||||
server_pid = do_fork ? fork() : 0;
|
||||
|
||||
if (server_pid < 0)
|
||||
@@ -385,11 +393,13 @@ void stop_publishing()
|
||||
|
||||
void update_fsm()
|
||||
{
|
||||
bool server_running = server_watch != 0;
|
||||
bool server_running = server_watch != 0 or connection_thread;
|
||||
bool app_running = app_watch != 0;
|
||||
|
||||
if (quitting_main_loop)
|
||||
{
|
||||
connection_thread.reset();
|
||||
|
||||
if (server_running)
|
||||
kill_server();
|
||||
|
||||
@@ -426,22 +436,59 @@ int sigint(void * sig_nr)
|
||||
return G_SOURCE_CONTINUE;
|
||||
}
|
||||
|
||||
gboolean headset_connected(gint fd, GIOCondition condition, gpointer user_data)
|
||||
gboolean headset_connected_success(void *)
|
||||
{
|
||||
assert(server_watch == 0);
|
||||
assert(app_watch == 0);
|
||||
assert(connection_thread);
|
||||
connection_thread.reset();
|
||||
|
||||
assert(listener);
|
||||
|
||||
tcp = std::make_unique<wivrn::TCP>(listener->accept().first);
|
||||
init_cleanup_functions();
|
||||
|
||||
std::cout << "Client connected" << std::endl;
|
||||
|
||||
expose_known_keys_on_dbus();
|
||||
|
||||
start_server();
|
||||
start_app();
|
||||
|
||||
return true;
|
||||
connection.reset();
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
gboolean headset_connected_failed(void *)
|
||||
{
|
||||
assert(connection_thread);
|
||||
connection_thread.reset();
|
||||
|
||||
update_fsm();
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
gboolean headset_connected(gint fd, GIOCondition condition, gpointer user_data)
|
||||
{
|
||||
assert(server_watch == 0);
|
||||
assert(app_watch == 0);
|
||||
assert(not connection_thread);
|
||||
assert(listener);
|
||||
|
||||
wivrn::TCP tcp = listener->accept().first;
|
||||
stop_listening();
|
||||
stop_publishing();
|
||||
|
||||
connection_thread.emplace([](std::stop_token stop_token, wivrn::TCP && tcp) {
|
||||
try
|
||||
{
|
||||
connection = std::make_unique<wivrn::wivrn_connection>(stop_token, pin, std::move(tcp));
|
||||
g_main_context_invoke(nullptr, &headset_connected_success, nullptr);
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
std::cerr << "Client connection failed: " << e.what() << std::endl;
|
||||
g_main_context_invoke(nullptr, &headset_connected_failed, nullptr);
|
||||
}
|
||||
},
|
||||
std::move(tcp));
|
||||
|
||||
return G_SOURCE_CONTINUE;
|
||||
}
|
||||
|
||||
gboolean control_received(gint fd, GIOCondition condition, gpointer user_data)
|
||||
@@ -449,48 +496,91 @@ gboolean control_received(gint fd, GIOCondition condition, gpointer user_data)
|
||||
auto packet = wivrn_ipc_socket_main_loop->receive();
|
||||
if (packet)
|
||||
{
|
||||
if (std::holds_alternative<wivrn::from_headset::headset_info_packet>(*packet))
|
||||
{
|
||||
on_headset_info_packet(std::get<wivrn::from_headset::headset_info_packet>(*packet));
|
||||
inhibitor.emplace();
|
||||
wivrn_server_set_headset_connected(dbus_server, true);
|
||||
}
|
||||
else if (std::holds_alternative<from_monado::headsdet_connected>(*packet))
|
||||
{
|
||||
stop_publishing();
|
||||
inhibitor.emplace();
|
||||
wivrn_server_set_headset_connected(dbus_server, true);
|
||||
}
|
||||
else if (std::holds_alternative<from_monado::headsdet_disconnected>(*packet))
|
||||
{
|
||||
start_publishing();
|
||||
inhibitor.reset();
|
||||
wivrn_server_set_headset_connected(dbus_server, false);
|
||||
}
|
||||
std::visit(utils::overloaded{
|
||||
[&](const wivrn::from_headset::headset_info_packet & info) {
|
||||
on_headset_info_packet(std::get<wivrn::from_headset::headset_info_packet>(*packet));
|
||||
inhibitor.emplace();
|
||||
wivrn_server_set_headset_connected(dbus_server, true);
|
||||
},
|
||||
[&](const from_monado::headset_connected &) {
|
||||
stop_publishing();
|
||||
inhibitor.emplace();
|
||||
wivrn_server_set_headset_connected(dbus_server, true);
|
||||
},
|
||||
[&](const from_monado::headset_disconnected &) {
|
||||
start_publishing();
|
||||
inhibitor.reset();
|
||||
wivrn_server_set_headset_connected(dbus_server, false);
|
||||
},
|
||||
},
|
||||
*packet);
|
||||
}
|
||||
|
||||
return true;
|
||||
return G_SOURCE_CONTINUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
on_handle_disconnect(WivrnServer * skeleton,
|
||||
GDBusMethodInvocation * invocation,
|
||||
gpointer user_data)
|
||||
void choose_pin()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::uniform_int_distribution<> distrib(0, 999999);
|
||||
|
||||
char buffer[7];
|
||||
snprintf(buffer, 7, "%06d", distrib(gen));
|
||||
pin = buffer;
|
||||
std::cerr << "PIN code: " << pin << std::endl;
|
||||
|
||||
wivrn_server_set_pin(dbus_server, buffer);
|
||||
}
|
||||
|
||||
gboolean on_handle_disconnect(WivrnServer * skeleton,
|
||||
GDBusMethodInvocation * invocation,
|
||||
gpointer user_data)
|
||||
{
|
||||
wivrn_ipc_socket_main_loop->send(to_monado::disconnect{});
|
||||
|
||||
return true;
|
||||
return G_SOURCE_CONTINUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
on_handle_quit(WivrnServer * skeleton,
|
||||
GDBusMethodInvocation * invocation,
|
||||
gpointer user_data)
|
||||
gboolean on_handle_quit(WivrnServer * skeleton, GDBusMethodInvocation * invocation, gpointer user_data)
|
||||
{
|
||||
quitting_main_loop = true;
|
||||
update_fsm();
|
||||
|
||||
return true;
|
||||
return G_SOURCE_CONTINUE;
|
||||
}
|
||||
|
||||
gboolean on_handle_revoke_key(WivrnServer * skeleton, GDBusMethodInvocation * invocation, gpointer user_data)
|
||||
{
|
||||
GVariant * args = g_dbus_method_invocation_get_parameters(invocation);
|
||||
|
||||
char * publickey;
|
||||
g_variant_get_child(args, 0, "s", &publickey);
|
||||
|
||||
wivrn::remove_known_key(publickey);
|
||||
|
||||
g_free(publickey);
|
||||
|
||||
expose_known_keys_on_dbus();
|
||||
return G_SOURCE_CONTINUE;
|
||||
}
|
||||
|
||||
gboolean on_handle_rename_key(WivrnServer * skeleton, GDBusMethodInvocation * invocation, gpointer user_data)
|
||||
{
|
||||
GVariant * args = g_dbus_method_invocation_get_parameters(invocation);
|
||||
|
||||
char * publickey;
|
||||
char * name;
|
||||
g_variant_get_child(args, 0, "s", &publickey);
|
||||
g_variant_get_child(args, 1, "s", &name);
|
||||
|
||||
wivrn::rename_known_key({.public_key = publickey, .name = name});
|
||||
|
||||
g_free(publickey);
|
||||
g_free(name);
|
||||
|
||||
expose_known_keys_on_dbus();
|
||||
return G_SOURCE_CONTINUE;
|
||||
}
|
||||
|
||||
void on_json_configuration(WivrnServer * server, const GParamSpec * pspec, gpointer data)
|
||||
@@ -511,6 +601,18 @@ void on_json_configuration(WivrnServer * server, const GParamSpec * pspec, gpoin
|
||||
std::cerr << "Failed to save configuration: " << ec.message() << std::endl;
|
||||
}
|
||||
|
||||
void expose_known_keys_on_dbus()
|
||||
{
|
||||
GVariantBuilder * builder = g_variant_builder_new(G_VARIANT_TYPE("a(ss)"));
|
||||
for (const auto & i: known_keys())
|
||||
{
|
||||
g_variant_builder_add(builder, "(ss)", i.name.c_str(), i.public_key.c_str());
|
||||
}
|
||||
GVariant * value = g_variant_new("a(ss)", builder);
|
||||
g_variant_builder_unref(builder);
|
||||
wivrn_server_set_known_keys(dbus_server, value);
|
||||
}
|
||||
|
||||
void on_headset_info_packet(const wivrn::from_headset::headset_info_packet & info)
|
||||
{
|
||||
GVariantBuilder * builder;
|
||||
@@ -579,6 +681,16 @@ void on_name_acquired(GDBusConnection * connection, const gchar * name, gpointer
|
||||
G_CALLBACK(on_handle_quit),
|
||||
NULL);
|
||||
|
||||
g_signal_connect(dbus_server,
|
||||
"handle-revoke-key",
|
||||
G_CALLBACK(on_handle_revoke_key),
|
||||
NULL);
|
||||
|
||||
g_signal_connect(dbus_server,
|
||||
"handle-rename-key",
|
||||
G_CALLBACK(on_handle_rename_key),
|
||||
NULL);
|
||||
|
||||
wivrn_server_set_steam_command(dbus_server, steam_command().c_str());
|
||||
|
||||
on_headset_info_packet({});
|
||||
@@ -587,6 +699,8 @@ void on_name_acquired(GDBusConnection * connection, const gchar * name, gpointer
|
||||
std::string config{std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()};
|
||||
|
||||
wivrn_server_set_json_configuration(dbus_server, config.c_str());
|
||||
choose_pin();
|
||||
expose_known_keys_on_dbus();
|
||||
|
||||
g_signal_connect(dbus_server, "notify::json-configuration", G_CALLBACK(on_json_configuration), NULL);
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <assert.h>
|
||||
|
||||
#include "driver/wivrn_session.h"
|
||||
#include "wivrn_ipc.h"
|
||||
|
||||
/*
|
||||
*
|
||||
@@ -24,8 +25,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
extern std::unique_ptr<wivrn::TCP> tcp;
|
||||
|
||||
static xrt_result_t
|
||||
wivrn_instance_create_system(struct xrt_instance * xinst,
|
||||
struct xrt_system ** out_xsys,
|
||||
@@ -41,13 +40,12 @@ wivrn_instance_create_system(struct xrt_instance * xinst,
|
||||
|
||||
struct xrt_system_compositor * xsysc = NULL;
|
||||
auto res = wivrn::wivrn_session::create_session(
|
||||
std::move(*tcp),
|
||||
std::move(connection),
|
||||
*u_sys,
|
||||
out_xsysd,
|
||||
out_xspovrs,
|
||||
out_xsysc);
|
||||
u_system_set_system_compositor(u_sys, *out_xsysc);
|
||||
tcp.reset();
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,12 +18,13 @@
|
||||
*/
|
||||
|
||||
#include "wivrn_ipc.h"
|
||||
#include "driver/wivrn_connection.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
std::unique_ptr<wivrn::TCP> tcp;
|
||||
std::unique_ptr<wivrn::wivrn_connection> connection;
|
||||
|
||||
struct cleanup_function
|
||||
{
|
||||
|
||||
+13
-7
@@ -27,16 +27,22 @@
|
||||
#include <stdint.h>
|
||||
#include <variant>
|
||||
|
||||
extern std::unique_ptr<wivrn::TCP> tcp;
|
||||
namespace wivrn
|
||||
{
|
||||
class wivrn_connection;
|
||||
}
|
||||
|
||||
extern std::unique_ptr<wivrn::wivrn_connection> connection;
|
||||
|
||||
namespace from_monado
|
||||
{
|
||||
struct headsdet_connected
|
||||
{};
|
||||
struct headsdet_disconnected
|
||||
struct headset_connected
|
||||
{};
|
||||
|
||||
using packets = std::variant<wivrn::from_headset::headset_info_packet, headsdet_connected, headsdet_disconnected>;
|
||||
struct headset_disconnected
|
||||
{};
|
||||
|
||||
using packets = std::variant<wivrn::from_headset::headset_info_packet, headset_connected, headset_disconnected>;
|
||||
} // namespace from_monado
|
||||
|
||||
namespace to_monado
|
||||
@@ -51,9 +57,9 @@ extern std::optional<wivrn::typed_socket<wivrn::UnixDatagram, to_monado::packets
|
||||
|
||||
std::optional<to_monado::packets> receive_from_main();
|
||||
template <typename T>
|
||||
void send_to_main(T && packet)
|
||||
void send_to_main(T packet)
|
||||
{
|
||||
wivrn_ipc_socket_monado->send(std::forward<T>(packet));
|
||||
wivrn_ipc_socket_monado->send(std::move(packet));
|
||||
}
|
||||
|
||||
void init_cleanup_functions();
|
||||
|
||||
Reference in New Issue
Block a user