• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 '../gen/all_tracks';
16import '../common/recordingV2/target_factories';
17
18import {assertExists, assertTrue} from '../base/logging';
19
20import {AppController} from './app_controller';
21import {ControllerAny} from './controller';
22
23let rootController: ControllerAny;
24let runningControllers = false;
25
26export function initController(extensionPort: MessagePort) {
27  assertTrue(rootController === undefined);
28  rootController = new AppController(extensionPort);
29}
30
31export function runControllers() {
32  if (runningControllers) throw new Error('Re-entrant call detected');
33
34  // Run controllers locally until all state machines reach quiescence.
35  let runAgain = true;
36  for (let iter = 0; runAgain; iter++) {
37    if (iter > 100) throw new Error('Controllers are stuck in a livelock');
38    runningControllers = true;
39    try {
40      runAgain = assertExists(rootController).invoke();
41    } finally {
42      runningControllers = false;
43    }
44  }
45}
46