| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #include "activity_sdk_lifetime_runtime.h"
- #include "../../middleware/bap/activity_message/sensor_auth_update.h"
- #include "../bap/runtime.h"
- #include "host_runtime.h"
- namespace sunrise::server::activity::activity_sdk_lifetime {
- namespace {
- namespace sdk = state::activity_sdk;
- /** Preflights one lifetime change and keeps the link fields the queue call needs. */
- [[nodiscard]] Status prepare(const sdk::BoundView& view,
- std::uint8_t lifetimeState,
- server::bap::ActivityLinkView& link) noexcept {
- link = {};
- // Above the highest jump-table entry the client's spawn gate jumps out of its image.
- if (lifetimeState
- > middleware::bap::activity_message::sensor_auth_update::kMaximumLifetimeState) {
- return Status::invalidValue;
- }
- const Status live = activity_sdk_devices::live_binding_status(view, link);
- if (live != Status::ready) {
- return live;
- }
- return Status::ready;
- }
- } // namespace
- Status availability(const sdk::BoundView& view, std::uint8_t lifetimeState) noexcept {
- server::bap::ActivityLinkView link{};
- return prepare(view, lifetimeState, link);
- }
- /** Sets the lifetime state for an operator action, which owns no Mission revision. */
- Status set(const sdk::BoundView& view, std::uint8_t lifetimeState) noexcept {
- server::bap::ActivityLinkView link{};
- const Status status = prepare(view, lifetimeState, link);
- if (status != Status::ready) {
- return status;
- }
- if (server::bap::request_activity_lifetime_override(
- view.binding, lifetimeState, link.effectiveRegion, link.activityClientGeneration)) {
- return Status::queued;
- }
- host::InstanceSnapshot instance{};
- const bool busy = host::instance_snapshot(view.binding, instance) && instance.outputPending;
- return busy ? Status::outputBusy : Status::refused;
- }
- /**
- * Queues one lifetime change through an already owned Host revision.
- * @param view Pinned SDK view naming the exact activity generation.
- * @param lifetimeState Activity lifetime state to report.
- * @param reservation Unarmed Host revision the durable Mission head already owns.
- * @return queued on success, or the refusal that stopped it.
- */
- Status set_reserved(const sdk::BoundView& view,
- std::uint8_t lifetimeState,
- const host::ScriptableOutputReservation& reservation) noexcept {
- server::bap::ActivityLinkView link{};
- const Status status = prepare(view, lifetimeState, link);
- if (status != Status::ready) {
- return status;
- }
- const bool queued =
- server::bap::request_activity_lifetime_override(view.binding,
- lifetimeState,
- link.effectiveRegion,
- link.activityClientGeneration,
- &reservation);
- if (queued) {
- return Status::queued;
- }
- host::InstanceSnapshot instance{};
- const bool busy = host::instance_snapshot(view.binding, instance) && instance.outputPending;
- return busy ? Status::outputBusy : Status::refused;
- }
- } // namespace sunrise::server::activity::activity_sdk_lifetime
|