Support stopping application
This commit is contained in:
@@ -815,6 +815,22 @@ void wivrn_session::operator()(const from_headset::set_active_application & req)
|
||||
(*this)(from_headset::get_running_applications{});
|
||||
}
|
||||
|
||||
void wivrn_session::operator()(const from_headset::stop_application & req)
|
||||
{
|
||||
scoped_lock lock(inst.server->global_state.lock);
|
||||
for (auto & t: inst.server->threads)
|
||||
{
|
||||
if (t.ics.client_state.id == req.id)
|
||||
{
|
||||
U_LOG_I("Notify session loss pending for %s", t.ics.client_state.info.application_name);
|
||||
auto when = os_monotonic_get_ns() + 200 * U_TIME_1MS_IN_NS;
|
||||
xrt_syscomp_notify_loss_pending(system_compositor, t.ics.xc, when);
|
||||
session_loss.lock()->emplace(when, req.id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wivrn_session::operator()(audio_data && data)
|
||||
{
|
||||
if (audio_handle)
|
||||
@@ -899,6 +915,7 @@ void wivrn_session::run(std::stop_token stop)
|
||||
refresh.adjust(*connection);
|
||||
}
|
||||
}
|
||||
poll_session_loss();
|
||||
connection->poll(*this, 20);
|
||||
}
|
||||
catch (const std::exception & e)
|
||||
@@ -1002,6 +1019,29 @@ void wivrn_session::reconnect()
|
||||
}
|
||||
}
|
||||
|
||||
void wivrn_session::poll_session_loss()
|
||||
{
|
||||
auto locked = session_loss.lock();
|
||||
auto now = os_monotonic_get_ns();
|
||||
if (locked->empty())
|
||||
return;
|
||||
auto it = locked->begin();
|
||||
scoped_lock lock(inst.server->global_state.lock);
|
||||
while (it != locked->end() and it->first <= now)
|
||||
{
|
||||
for (auto & t: inst.server->threads)
|
||||
{
|
||||
if (t.ics.client_state.id == it->second)
|
||||
{
|
||||
U_LOG_I("Terminating %s", t.ics.client_state.info.application_name);
|
||||
xrt_syscomp_notify_lost(system_compositor, t.ics.xc);
|
||||
break;
|
||||
}
|
||||
}
|
||||
it = locked->erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
xrt_result_t wivrn_session::get_roles(xrt_system_roles * out_roles)
|
||||
{
|
||||
std::lock_guard lock(roles_mutex);
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "clock_offset.h"
|
||||
#include "driver/app_pacer.h"
|
||||
#include "utils/thread_safe.h"
|
||||
#include "wivrn_connection.h"
|
||||
#include "wivrn_controller.h"
|
||||
#include "wivrn_hand_interaction.h"
|
||||
@@ -31,6 +32,7 @@
|
||||
#include "xrt/xrt_system.h"
|
||||
#include <atomic>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
@@ -134,6 +136,9 @@ class wivrn_session : public xrt_system_devices
|
||||
|
||||
std::shared_ptr<audio_device> audio_handle;
|
||||
|
||||
// when sessions shall be destroyed, key is timestap, value is client id
|
||||
thread_safe<std::map<int64_t, int32_t>> session_loss;
|
||||
|
||||
std::jthread thread;
|
||||
|
||||
wivrn_session(std::unique_ptr<wivrn_connection> connection, instance &, u_system &);
|
||||
@@ -194,6 +199,7 @@ public:
|
||||
void operator()(const from_headset::start_app &);
|
||||
void operator()(const from_headset::get_running_applications &);
|
||||
void operator()(const from_headset::set_active_application &);
|
||||
void operator()(const from_headset::stop_application &);
|
||||
void operator()(audio_data &&);
|
||||
|
||||
void operator()(to_monado::disconnect &&);
|
||||
@@ -225,6 +231,8 @@ private:
|
||||
void run(std::stop_token stop);
|
||||
void reconnect();
|
||||
|
||||
void poll_session_loss();
|
||||
|
||||
// xrt_system implementation
|
||||
xrt_result_t get_roles(xrt_system_roles * out_roles);
|
||||
xrt_result_t feature_inc(xrt_device_feature_type type);
|
||||
|
||||
Reference in New Issue
Block a user