1 /*
<lambda>null2 * 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 /* Initialized Events */
20 internal fun interface EventsImpl<out A> {
21 fun activate(evalScope: EvalScope, downstream: Schedulable): ActivationResult<A>?
22 }
23
24 internal data class ActivationResult<out A>(
25 val connection: NodeConnection<A>,
26 val needsEval: Boolean,
27 )
28
EventsImplCheapnull29 internal inline fun <A> EventsImplCheap(crossinline cheap: CheapNodeSubscribe<A>) =
30 EventsImpl { scope, ds ->
31 scope.cheap(ds)
32 }
33
34 internal typealias CheapNodeSubscribe<A> =
35 EvalScope.(downstream: Schedulable) -> ActivationResult<A>?
36
37 internal data class NodeConnection<out A>(
38 val directUpstream: PullNode<A>,
39 val schedulerUpstream: PushNode<*>,
40 )
41
hasCurrentValuenull42 internal fun <A> NodeConnection<A>.hasCurrentValue(logIndent: Int, evalScope: EvalScope): Boolean =
43 schedulerUpstream.hasCurrentValue(logIndent, evalScope)
44
45 internal fun <A> NodeConnection<A>.removeDownstreamAndDeactivateIfNeeded(downstream: Schedulable) =
46 schedulerUpstream.removeDownstreamAndDeactivateIfNeeded(downstream)
47
48 internal fun <A> NodeConnection<A>.scheduleDeactivationIfNeeded(evalScope: EvalScope) =
49 schedulerUpstream.scheduleDeactivationIfNeeded(evalScope)
50
51 internal fun <A> NodeConnection<A>.removeDownstream(downstream: Schedulable) =
52 schedulerUpstream.removeDownstream(downstream)
53
54 internal fun <A> NodeConnection<A>.getPushEvent(logIndent: Int, evalScope: EvalScope): A =
55 directUpstream.getPushEvent(logIndent, evalScope)
56
57 internal val <A> NodeConnection<A>.depthTracker: DepthTracker
58 get() = schedulerUpstream.depthTracker
59