1 /* 2 * Copyright (C) 2022 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.libraries.pcc.chronicle.analysis 18 19 import com.android.libraries.pcc.chronicle.api.Connection 20 import com.android.libraries.pcc.chronicle.api.ConnectionProvider 21 import com.android.libraries.pcc.chronicle.api.DataTypeDescriptor 22 import com.android.libraries.pcc.chronicle.api.DataTypeDescriptorSet 23 import com.android.libraries.pcc.chronicle.api.ProcessorNode 24 import com.android.libraries.pcc.chronicle.util.TypedMap 25 26 /** 27 * Immutable data structure which maintains the universe of [ProcessorNodes][ProcessorNode] and 28 * [ConnectionProviders][ConnectionProvider] known by Chronicle. 29 * 30 * Note: 31 * 32 * [connectionProviders] and [processorNodes] are not necessarily mutually exclusive sets. It's 33 * possible that a single class could implement both interfaces. 34 */ 35 interface ChronicleContext { 36 /** All [ConnectionProvider]s known to Chronicle. */ 37 val connectionProviders: Set<ConnectionProvider> 38 39 /** All [ProcessorNode]s known to Chronicle. */ 40 val processorNodes: Set<ProcessorNode> 41 42 /** Collection of all known [Policies][Policy]. */ 43 val policySet: PolicySet 44 45 /** All [DataTypeDescriptor]s known to Chronicle. */ 46 val dataTypeDescriptorSet: DataTypeDescriptorSet 47 48 /** Contextual variables used in Policy evaluations */ 49 val connectionContext: TypedMap 50 51 /** 52 * Returns a [ConnectionProvider] capable of providing [Connection]s of the specified 53 * [connectionType]. 54 */ findConnectionProvidernull55 fun <T : Connection> findConnectionProvider(connectionType: Class<T>): ConnectionProvider? 56 57 /** Returns the [DataTypeDescriptor] associated with the provided [connectionType], if found. */ 58 fun <T : Connection> findDataType(connectionType: Class<T>): DataTypeDescriptor? 59 60 /** Returns a new [ChronicleContext] containing the provided [ProcessorNode]. */ 61 fun withNode(node: ProcessorNode): ChronicleContext 62 63 /** Returns a new [ChronicleContext] containing the provided [connectionContext]. */ 64 fun withConnectionContext(connectionContext: TypedMap): ChronicleContext 65 } 66