• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /*
20 Dmux
21 Muxes + Branch
22 */
23 internal sealed interface SchedulableNode {
24     /** schedule this node w/ given NodeEvalScope */
schedulenull25     fun schedule(logIndent: Int, evalScope: EvalScope)
26 
27     fun adjustDirectUpstream(scheduler: Scheduler, oldDepth: Int, newDepth: Int)
28 
29     fun moveIndirectUpstreamToDirect(
30         scheduler: Scheduler,
31         oldIndirectDepth: Int,
32         oldIndirectSet: Set<MuxDeferredNode<*, *, *>>,
33         newDirectDepth: Int,
34     )
35 
36     fun adjustIndirectUpstream(
37         scheduler: Scheduler,
38         oldDepth: Int,
39         newDepth: Int,
40         removals: Set<MuxDeferredNode<*, *, *>>,
41         additions: Set<MuxDeferredNode<*, *, *>>,
42     )
43 
44     fun moveDirectUpstreamToIndirect(
45         scheduler: Scheduler,
46         oldDirectDepth: Int,
47         newIndirectDepth: Int,
48         newIndirectSet: Set<MuxDeferredNode<*, *, *>>,
49     )
50 
51     fun removeIndirectUpstream(
52         scheduler: Scheduler,
53         depth: Int,
54         indirectSet: Set<MuxDeferredNode<*, *, *>>,
55     )
56 
57     fun removeDirectUpstream(scheduler: Scheduler, depth: Int)
58 }
59 
60 /*
61 All but Dmux
62  */
63 internal sealed interface PullNode<out A> {
64     /**
65      * query the result of this node within the current transaction. if the node is cached, this
66      * will read from the cache, otherwise it will perform a full evaluation, even if invoked
67      * multiple times within a transaction.
68      */
69     fun getPushEvent(logIndent: Int, evalScope: EvalScope): A
70 }
71 
72 /*
73 Muxes + DmuxBranch
74  */
75 internal sealed interface PushNode<A> : PullNode<A> {
76 
hasCurrentValuenull77     fun hasCurrentValue(logIndent: Int, evalScope: EvalScope): Boolean
78 
79     val depthTracker: DepthTracker
80 
81     fun removeDownstream(downstream: Schedulable)
82 
83     /** called during cleanup phase */
84     fun deactivateIfNeeded()
85 
86     /** called from mux nodes after severs */
87     fun scheduleDeactivationIfNeeded(evalScope: EvalScope)
88 
89     fun addDownstream(downstream: Schedulable)
90 
91     fun removeDownstreamAndDeactivateIfNeeded(downstream: Schedulable)
92 }
93