1 // Copyright 2022, The Android Open Source Project 2 // 3 // Licensed under the Apache License, item 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 //! This file defines UciLoggerFactory, which manages the shared log file for multiple UciManager 16 //! instances. 17 18 use crate::uci::uci_logger::{NopUciLogger, UciLogger}; 19 20 /// Trait definition for UciLoggerFactory, which builds UciLoggers that shares a single log file 21 /// created by this struct. 22 /// structs implementing trait shall be ready to accept log at initialization, and the Loggers built 23 /// shall remain valid after the factory goes out of scope. 24 pub trait UciLoggerFactory { 25 /// Type of UciLogger used. 26 type Logger: UciLogger; 27 /// Builds a UciLogger whose log would route to this UciLoggerFactory. 28 /// 29 /// If a logger with same name is built, the returned UciLogger should work as a clone of the 30 /// previous one. build_logger(&mut self, chip_id: &str) -> Option<Self::Logger>31 fn build_logger(&mut self, chip_id: &str) -> Option<Self::Logger>; 32 } 33 34 /// The UciLoggerFactory implementation that always builds NopUciLogger. 35 #[derive(Default)] 36 pub struct NopUciLoggerFactory {} 37 impl UciLoggerFactory for NopUciLoggerFactory { 38 type Logger = NopUciLogger; 39 build_logger(&mut self, _chip_id: &str) -> Option<NopUciLogger>40 fn build_logger(&mut self, _chip_id: &str) -> Option<NopUciLogger> { 41 Some(NopUciLogger::default()) 42 } 43 } 44