1// Copyright (C) 2018 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 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 15import {globals} from '../controller/globals'; 16 17import {Child, Controller, ControllerInitializerAny} from './controller'; 18import {PermalinkController} from './permalink_controller'; 19import {RecordController} from './record_controller'; 20import {TraceController} from './trace_controller'; 21 22// The root controller for the entire app. It handles the lifetime of all 23// the other controllers (e.g., track and query controllers) according to the 24// global state. 25export class AppController extends Controller<'main'> { 26 constructor() { 27 super('main'); 28 } 29 30 // This is the root method that is called every time the controller tree is 31 // re-triggered. This can happen due to: 32 // - An action received from the frontend. 33 // - An internal promise of a nested controller being resolved and manually 34 // re-triggering the controllers. 35 run() { 36 const childControllers: ControllerInitializerAny[] = [ 37 Child('permalink', PermalinkController, {}), 38 Child('record', RecordController, {app: globals}), 39 ]; 40 for (const engineCfg of Object.values(globals.state.engines)) { 41 childControllers.push(Child(engineCfg.id, TraceController, engineCfg.id)); 42 } 43 return childControllers; 44 } 45} 46