1/// @brief Abstract base class for task requirements
3/// @defgroup taskrequires Task Requirements
7/// TaskRequires is the abstract base for all types of requirements that a ComplexTask can
8/// depend on before execution. Requirements encompass:
9/// - Task dependencies (wait for other tasks to complete)
10/// - Resource acquisition (exclusive access to shared resources)
11/// - Gate conditions (wait for external events)
13/// Requirements can have timeouts (expires field). When a requirement times out, it transitions
14/// to TASK_Requires_Fail_Permanent unless the task has TASK_Soft_Requires flag set.
16/// **Concrete implementations:**
17/// - TaskRequiresTask - Depend on another task completing
18/// - TaskRequiresResource - Acquire exclusive resource access
19/// - TaskRequiresGate - Wait for a gate to open
23// forward declare task
26/// @addtogroup taskrequires
29/// Possible states of a requirement
30enum TaskRequiresStateEnum {
31 TASK_Requires_Wait = 0, ///< Not satisfied yet, but may be in the future (task should wait)
32 TASK_Requires_Ok, ///< Currently satisfied, but may change (check again later)
33 TASK_Requires_Ok_Permanent, ///< Permanently satisfied, can be removed from checks
34 TASK_Requires_Fail_Permanent, ///< Cannot be satisfied, task should fail
35 TASK_Requires_Acquire, ///< Will be satisfied only if tryAcquire() succeeds
38/// Abstract base class for task requirements (dependencies, resources, gates).
39abstract class TaskRequires {
40 int64 expires; ///< Time after which requirement times out and fails (0 = no timeout)
42 /// Calculate current state of the requirement.
43 /// @param task Task checking this requirement
44 /// @return State code (TASK_Requires_Wait, TASK_Requires_Ok, etc.)
45 [abstract] uint32 state(ComplexTask *task);
47 /// Get progress timestamp if applicable.
48 /// @return Last progress timestamp, or -1 if not applicable
49 [abstract] int64 progress();
51 /// Try to acquire resource for requirements that need acquisition.
52 /// Only called if state() returns TASK_Requires_Acquire. MUST NOT block.
53 /// If successful, release() must be called when task finishes.
54 /// @param task Task acquiring the resource
55 /// @return true if resource was acquired
56 [abstract] bool tryAcquire(ComplexTask *task);
58 /// Release previously acquired resource.
59 /// Must be paired with tryAcquire() and use the same task.
60 /// @param task Task releasing the resource
61 /// @return true if resource was released
62 [abstract] bool release(ComplexTask *task);
64 /// Cascade cancellation to dependencies.
65 /// Called when task is cancelled and has TASK_Cancel_Cascade flag.
66 [abstract] void cancel();
68 /// Register task for notification when requirement state changes.
69 /// The requirement should advance the task out of defer queue when state changes.
70 /// Also registers task with resources for one-shot acquisition.
71 /// @param task Task to notify
72 /// @return true if registration was successful
73 [abstract] bool registerTask([in] ComplexTask *task);