1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.kairos.internal 18 19 import com.android.systemui.kairos.util.Maybe 20 21 /* 22 Dmux 23 Muxes + Branch 24 */ 25 internal sealed interface SchedulableNode { 26 /** schedule this node w/ given NodeEvalScope */ schedulenull27 suspend fun schedule(evalScope: EvalScope) 28 29 suspend fun adjustDirectUpstream(scheduler: Scheduler, oldDepth: Int, newDepth: Int) 30 31 suspend fun moveIndirectUpstreamToDirect( 32 scheduler: Scheduler, 33 oldIndirectDepth: Int, 34 oldIndirectSet: Set<MuxDeferredNode<*, *>>, 35 newDirectDepth: Int, 36 ) 37 38 suspend fun adjustIndirectUpstream( 39 scheduler: Scheduler, 40 oldDepth: Int, 41 newDepth: Int, 42 removals: Set<MuxDeferredNode<*, *>>, 43 additions: Set<MuxDeferredNode<*, *>>, 44 ) 45 46 suspend fun moveDirectUpstreamToIndirect( 47 scheduler: Scheduler, 48 oldDirectDepth: Int, 49 newIndirectDepth: Int, 50 newIndirectSet: Set<MuxDeferredNode<*, *>>, 51 ) 52 53 suspend fun removeIndirectUpstream( 54 scheduler: Scheduler, 55 depth: Int, 56 indirectSet: Set<MuxDeferredNode<*, *>>, 57 ) 58 59 suspend fun removeDirectUpstream(scheduler: Scheduler, depth: Int) 60 } 61 62 /* 63 All but Dmux 64 */ 65 internal sealed interface PullNode<out A> { 66 /** 67 * query the result of this node within the current transaction. if the node is cached, this 68 * will read from the cache, otherwise it will perform a full evaluation, even if invoked 69 * multiple times within a transaction. 70 */ 71 suspend fun getPushEvent(evalScope: EvalScope): Maybe<A> 72 } 73 74 /* 75 Muxes + DmuxBranch 76 */ 77 internal sealed interface PushNode<A> : PullNode<A> { 78 hasCurrentValuenull79 suspend fun hasCurrentValue(transactionStore: TransactionStore): Boolean 80 81 val depthTracker: DepthTracker 82 83 suspend fun removeDownstream(downstream: Schedulable) 84 85 /** called during cleanup phase */ 86 suspend fun deactivateIfNeeded() 87 88 /** called from mux nodes after severs */ 89 suspend fun scheduleDeactivationIfNeeded(evalScope: EvalScope) 90 91 suspend fun addDownstream(downstream: Schedulable) 92 93 suspend fun removeDownstreamAndDeactivateIfNeeded(downstream: Schedulable) 94 } 95