Skip to content

Editor → Commands and Undo → command_dispatcher.h

command_dispatcher

Syntax

class CONJURE_API command_dispatcher

Constructors

AccessSignatureDescription
publiccommand_dispatcher( editor_context &context, command_registry &registry, undo_stack &undo);

Important

Copy constructor and assignment has been deleted.

Destructors

AccessSignatureDescription
public~command_dispatcher();

Variables

AccessNameTypeDefaultDescription
publicDEFAULT_ASYNC_TIMEOUT_SECONDSstatic constexpr f64120.0
publicDEFAULT_MAX_PENDING_PER_CLIENTstatic constexpr u328
privatemAsyncTimeoutSecondsf64DEFAULT_ASYNC_TIMEOUT_SECONDS
privatemBatchbatch_state *nullptr
privatemClockconst core::clock *nullptr
privatemCompletedstd::vector<protocol_response>{}
privatemContexteditor_context *nullptr
privatemDispatchingTicketu640
privatemMaxPendingPerClientu32DEFAULT_MAX_PENDING_PER_CLIENT
privatemNextTicketu641
privatemOnLocalResponsecore::event<const protocol_response &>{}
privatemPendingstd::vector<pending_request>{}
privatemRegistrycommand_registry *nullptr
privatemSuppressRecordingu320
privatemSuppressRevisionu320
privatemSynchronousResponsestd::optional<protocol_response>std::nullopt
privatemUndoundo_stack *nullptr

Functions

Public

async_timeout_seconds

[[nodiscard]] f64 async_timeout_seconds() const noexcept;

cancel_all

void cancel_all(
    protocol_error_code code,
    std::string_view message);

Completes every pending request with the given error (CANCELLED when the engine restarts or shuts down); the responses are delivered by the next resolve_completed().

cancel_client

void cancel_client(
    u32 clientId);

Drops the pending requests of a disconnected client (CANCELLED, logged) and commits its open transaction.

complete

void complete(
    u64 ticket,
    protocol_response response);

Completes a parked request (called by async_reply). A failure of client 0 (the UI, which does not wait for its answers) is logged as a WARN naming the command.

complete_mutation

void complete_mutation(
    u64 ticket,
    command_outcome outcome);

Completes the parked request of an ASYNC | MUTATES command with its outcome (called by async_reply::succeed_mutation): records it the way a synchronous mutation is recorded at dispatch, with the request's args, client and coalesce key (the undo stack, the client's transaction, the running batch, or the play controller while frozen), marks the scene dirty unless NO_UNDO and, outside an undo or redo step, bumps the revision, sets result.revision and emits scene.changed. A completion inside the handler (a batch child, a replay) is recorded under the state it runs in. Asserted: the ticket is pending and its command is MUTATES.

dispatch

[[nodiscard]] std::optional<protocol_response> dispatch(
    const protocol_request &request);

Validates and executes one request. Returns the response, or nullopt when the command is asynchronous and will answer through resolve_completed() later. A known command the client's token does not open (required_access(flags) above what protocol_server::access_of_client reports) answers UNAUTHORISED with details {required, granted} before its arguments are validated; the client stays connected. Every request of a transport client, refused ones and unknown commands included, is handed to protocol_server::record_command once it was dispatched; so is every child of an editor.batch.

dispatch_inverses

[[nodiscard]] core::result<void> dispatch_inverses(
    std::span<const command_inverse> inverses,
    u32 clientId);

Dispatches recorded inverses or replays with undo recording suppressed (history.undo/redo). The commands neither bump the revision nor emit scene.changed: the history command does both once per step.

dispatch_replays

[[nodiscard]] core::result<void> dispatch_replays(
    std::span<const command_request> replays,
    u32 clientId);

exceeds_pending_limit

[[nodiscard]] bool exceeds_pending_limit(
    u32 clientId) const noexcept;

True when the client has more parked requests than max_pending_per_client(). Inside an ASYNC handler the request being dispatched is parked already and counts.

execute

[[nodiscard]] core::result<core::json::document> execute(
    const command_request &request);

UI convenience: dispatches from client 0 and returns the result object or the error (the error's code is the protocol code). An asynchronous command answers through on_local_response; when such a reply of client 0 fails, complete() also logs a WARN "ui: <command> failed: <message>".

in_batch

[[nodiscard]] bool in_batch() const noexcept;

True while a batch runs (nested batches are refused).

is_pending

[[nodiscard]] bool is_pending(
    u64 ticket) const noexcept;

True while the ticket is parked and not completed.

max_pending_per_client

[[nodiscard]] u32 max_pending_per_client() const noexcept;

on_local_response

[[nodiscard]] core::event<const protocol_response &> &on_local_response() noexcept;

Responses of asynchronous commands issued by client 0 (the UI).

pending_count

[[nodiscard]] usize pending_count(
    u32 clientId) const noexcept;
[[nodiscard]] usize pending_count() const noexcept;

replaying

[[nodiscard]] bool replaying() const noexcept;

True while history.undo / redo or a batch rollback dispatch recorded inverses and replays. Handlers use it to accept values a client may not send but an earlier state legitimately held (a legacy entity name restored by undo).

requires_synchronous_completion

[[nodiscard]] bool requires_synchronous_completion() const noexcept;

True while a request dispatched now must answer before its handler returns: inside a batch (its children are recorded into one entry and rolled back together), an undo or redo step and a batch rollback (replaying()). A SYNC_IN_BATCH handler checks it and completes its reply synchronously; an ASYNC handler that does not is answered with INTERNAL and its reply is dropped.

resolve_completed

void resolve_completed(
    std::vector<protocol_response> &outResponses);

Moves the responses of completed and timed-out asynchronous requests into outResponses.

rollback_steps

void rollback_steps(
    undo_entry &entry,
    usize first);

Takes back the steps of entry from index first on, newest first: their inverses run without being recorded (a failure is logged), and the pairs leave the entry. The rollback of a run_step() sequence.

run_batch

[[nodiscard]] core::result<std::vector<protocol_response>> run_batch(
    const core::json::value &commands,
    std::string_view label,
    bool atomic,
    u32 clientId,
    core::json::document &outDetails);

Runs the children of editor.batch (docs 3.4): one undo entry, atomic rollback through the recorded inverses on a failure. Returns the children's responses; the error of the failing child with details.failedIndex when atomic.

run_step

[[nodiscard]] core::result<core::json::document> run_step(
    const command_request &request,
    undo_entry &entry);

Runs one request as a step of an undo entry the caller assembles (play-mode persist at play.stop): it runs like an editor.batch child (validation, preconditions, revision and scene.changed), and its undo pair is appended to entry instead of reaching the undo stack or a transaction. Returns the result, or the request's error with nothing appended. INVALID_ARGS inside a running batch and for a command that may not run inside one (NOT_IN_BATCH, ASYNC).

set_async_timeout_seconds

void set_async_timeout_seconds(
    f64 seconds) noexcept;

set_clock

void set_clock(
    const core::clock *clock) noexcept;

The clock deadlines are measured with (the engine's clock by default).

set_max_pending_per_client

void set_max_pending_per_client(
    u32 count) noexcept;

The most requests one client may leave parked. An ASYNC request beyond it answers BUSY, except one that must complete inside its handler (requires_synchronous_completion()), which cannot stay parked and is never refused. A SYNC_IN_BATCH request may also finish inside its handler elsewhere (a prefab that is already loaded), so it is counted only when its handler leaves it parked: the dispatcher answers BUSY then and drops its reply, and the handler checks exceeds_pending_limit() before it starts waiting, so it can refuse with nothing changed.

Private

access_of_client

[[nodiscard]] access_level access_of_client(
    u32 clientId) const noexcept;

audit

void audit(
    const protocol_request &request,
    const std::optional<protocol_response> &response,
    bool batchChild) const;

check_preconditions

[[nodiscard]] std::optional<protocol_error_code> check_preconditions(
    const command_descriptor &descriptor,
    core::json::document &details) const;

conclude_mutation

[[nodiscard]] protocol_response conclude_mutation(
    command_flags flags,
    const protocol_request &request,
    command_outcome &outcome);

dispatch_internal

[[nodiscard]] std::optional<protocol_response> dispatch_internal(
    const protocol_request &request);

keep_play_edits

void keep_play_edits(
    batch_state &batch);

note_touched

void note_touched(
    const command_outcome &outcome,
    std::vector<core::uuid> &outTouched) const;

now_seconds

[[nodiscard]] f64 now_seconds() const noexcept;

record_outcome

void record_outcome(
    command_flags flags,
    const protocol_request &request,
    command_outcome &outcome);