// Copyright 2022, Guillaume Meunier // Copyright 2022, Patrick Nicolas // SPDX-License-Identifier: BSL-1.0 #pragma once #include "wivrn_packets.h" #include "wivrn_connection.h" #include "xrt/xrt_system.h" #include #include #include #include #include class wivrn_hmd; class wivrn_controller; namespace xrt::drivers::wivrn { struct clock_offset { std::chrono::nanoseconds epoch_offset{}; uint64_t from_headset(uint64_t) const; std::chrono::nanoseconds to_headset(uint64_t timestamp_ns) const; }; class wivrn_session : public std::enable_shared_from_this { wivrn_connection connection; std::atomic quit = false; std::thread thread; std::mutex mutex; std::unique_ptr hmd; std::unique_ptr left_hand; std::unique_ptr right_hand; clock_offset offset; std::chrono::steady_clock::time_point offset_age{}; std::ofstream feedback_csv; wivrn_session(TCP&& tcp, in6_addr &address); public: static xrt_system_devices * create_session(TCP&& tcp); clock_offset get_offset(); void operator()(from_headset::headset_info_packet &&); void operator()(from_headset::tracking &&); void operator()(from_headset::inputs &&); void operator()(from_headset::timesync_response &&); void operator()(from_headset::feedback &&); template void send_stream(const T &packet) { connection.send_stream(packet); } template void send_control(const T &packet) { connection.send_control(packet); } private: static void run(std::weak_ptr); }; } // namespace xrt::drivers::wivrn