mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-02-05 13:28:16 +00:00
a/math: Add a "get latest" to relation history as well.
This commit is contained in:
parent
aff7079dca
commit
ef4550c268
|
@ -84,7 +84,7 @@ m_relation_history_push(struct m_relation_history *rh, struct xrt_space_relation
|
|||
}
|
||||
|
||||
enum m_relation_history_result
|
||||
m_relation_history_get( struct m_relation_history *rh, uint64_t at_timestamp_ns, struct xrt_space_relation *out_relation)
|
||||
m_relation_history_get(struct m_relation_history *rh, uint64_t at_timestamp_ns, struct xrt_space_relation *out_relation)
|
||||
{
|
||||
XRT_TRACE_MARKER();
|
||||
os_mutex_lock(&rh->mutex);
|
||||
|
@ -228,6 +228,22 @@ end:
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool
|
||||
m_relation_history_get_latest(struct m_relation_history *rh,
|
||||
uint64_t *out_time_ns,
|
||||
struct xrt_space_relation *out_relation)
|
||||
{
|
||||
os_mutex_lock(&rh->mutex);
|
||||
if (rh->impl.length() == 0) {
|
||||
os_mutex_unlock(&rh->mutex);
|
||||
return false;
|
||||
}
|
||||
*out_relation = rh->impl[0]->relation;
|
||||
*out_time_ns = rh->impl[0]->timestamp;
|
||||
os_mutex_unlock(&rh->mutex);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
m_relation_history_get_size(const struct m_relation_history *rh)
|
||||
{
|
||||
|
|
|
@ -67,6 +67,22 @@ m_relation_history_push(struct m_relation_history *rh, struct xrt_space_relation
|
|||
enum m_relation_history_result
|
||||
m_relation_history_get(struct m_relation_history *rh, uint64_t at_time_ns, struct xrt_space_relation *out_relation);
|
||||
|
||||
/*!
|
||||
* @brief Get the latest report in the buffer, if any.
|
||||
*
|
||||
* @param rh self
|
||||
* @param[out] out_time_ns Populated with the latest report time, if any
|
||||
* @param[out] out_relation Populated with the latest relation, if any
|
||||
*
|
||||
* @return false if the history is empty.
|
||||
*
|
||||
* @public @memberof m_relation_history
|
||||
*/
|
||||
bool
|
||||
m_relation_history_get_latest(struct m_relation_history *rh,
|
||||
uint64_t *out_time_ns,
|
||||
struct xrt_space_relation *out_relation);
|
||||
|
||||
/*!
|
||||
* @brief Returns the number of items in the history.
|
||||
*
|
||||
|
|
|
@ -40,22 +40,36 @@ TEST_CASE("m_relation_history")
|
|||
// two seconds after T0
|
||||
constexpr auto T2 = T1 + (uint64_t)U_TIME_1S_IN_NS;
|
||||
|
||||
xrt_space_relation out_relation = XRT_SPACE_RELATION_ZERO;
|
||||
uint64_t out_time = 0;
|
||||
|
||||
CHECK(m_relation_history_get_size(rh) == 0);
|
||||
CHECK_FALSE(m_relation_history_get_latest(rh, &out_time, &out_relation));
|
||||
|
||||
|
||||
CHECK(m_relation_history_push(rh, &relation, T0));
|
||||
CHECK(m_relation_history_get_size(rh) == 1);
|
||||
CHECK(m_relation_history_get_latest(rh, &out_time, &out_relation));
|
||||
CHECK(out_time == T0);
|
||||
|
||||
relation.pose.position.x = 1.f;
|
||||
CHECK(m_relation_history_push(rh, &relation, T1));
|
||||
CHECK(m_relation_history_get_size(rh) == 2);
|
||||
CHECK(m_relation_history_get_latest(rh, &out_time, &out_relation));
|
||||
CHECK(out_time == T1);
|
||||
|
||||
relation.pose.position.x = 2.f;
|
||||
CHECK(m_relation_history_push(rh, &relation, T2));
|
||||
CHECK(m_relation_history_get_size(rh) == 3);
|
||||
CHECK(m_relation_history_get_latest(rh, &out_time, &out_relation));
|
||||
CHECK(out_time == T2);
|
||||
|
||||
// Try going back in time: should fail
|
||||
// Try going back in time: should fail to push, leave state the same
|
||||
CHECK_FALSE(m_relation_history_push(rh, &relation, T1));
|
||||
CHECK(m_relation_history_get_size(rh) == 3);
|
||||
CHECK(m_relation_history_get_latest(rh, &out_time, &out_relation));
|
||||
CHECK(out_time == T2);
|
||||
|
||||
xrt_space_relation out_relation = XRT_SPACE_RELATION_ZERO;
|
||||
CHECK(m_relation_history_get(rh, 0, &out_relation) == M_RELATION_HISTORY_RESULT_INVALID);
|
||||
|
||||
CHECK(m_relation_history_get(rh, T0, &out_relation) == M_RELATION_HISTORY_RESULT_EXACT);
|
||||
|
|
Loading…
Reference in a new issue