move stuff in common, clang-format, update copyright
This commit is contained in:
@@ -1,6 +1,21 @@
|
||||
// Copyright 2022, Guillaume Meunier
|
||||
// Copyright 2022, Patrick Nicolas
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -17,24 +32,18 @@ class wivrn_connection
|
||||
typed_socket<UDP, from_headset::stream_packets, to_headset::stream_packets> stream;
|
||||
|
||||
public:
|
||||
wivrn_connection(TCP &&tcp, in6_addr address);
|
||||
wivrn_connection(TCP && tcp, in6_addr address);
|
||||
wivrn_connection(const wivrn_connection &) = delete;
|
||||
wivrn_connection &
|
||||
operator=(const wivrn_connection &) = delete;
|
||||
wivrn_connection & operator=(const wivrn_connection &) = delete;
|
||||
|
||||
void
|
||||
send_control(const to_headset::control_packets &packet);
|
||||
void
|
||||
send_stream(const to_headset::stream_packets &packet);
|
||||
void send_control(const to_headset::control_packets & packet);
|
||||
void send_stream(const to_headset::stream_packets & packet);
|
||||
|
||||
std::optional<from_headset::stream_packets>
|
||||
poll_stream(int timeout);
|
||||
std::optional<from_headset::control_packets>
|
||||
poll_control(int timeout);
|
||||
std::optional<from_headset::stream_packets> poll_stream(int timeout);
|
||||
std::optional<from_headset::control_packets> poll_control(int timeout);
|
||||
|
||||
template <typename T>
|
||||
int
|
||||
poll(T &&visitor, int timeout)
|
||||
int poll(T && visitor, int timeout)
|
||||
{
|
||||
pollfd fds[2] = {};
|
||||
fds[0].events = POLLIN;
|
||||
@@ -52,13 +61,15 @@ public:
|
||||
if (fds[1].revents & (POLLHUP | POLLERR))
|
||||
throw std::runtime_error("Error on control socket");
|
||||
|
||||
if (fds[0].revents & POLLIN) {
|
||||
if (fds[0].revents & POLLIN)
|
||||
{
|
||||
auto packet = stream.receive();
|
||||
if (packet)
|
||||
std::visit(std::forward<T>(visitor), std::move(*packet));
|
||||
}
|
||||
|
||||
if (fds[1].revents & POLLIN) {
|
||||
if (fds[1].revents & POLLIN)
|
||||
{
|
||||
auto packet = control.receive();
|
||||
if (packet)
|
||||
std::visit(std::forward<T>(visitor), std::move(*packet));
|
||||
|
||||
Reference in New Issue
Block a user