• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
17import {Traces} from 'trace/traces';
18import {TracePosition} from 'trace/trace_position';
19import {TraceType} from 'trace/trace_type';
20import {View, Viewer, ViewType} from 'viewers/viewer';
21import {Events} from './events';
22import {Presenter} from './presenter';
23import {UiData} from './ui_data';
24
25class ViewerProtoLog implements Viewer {
26  constructor(traces: Traces) {
27    this.htmlElement = document.createElement('viewer-protolog');
28
29    this.presenter = new Presenter(traces, (data: UiData) => {
30      (this.htmlElement as any).inputData = data;
31    });
32
33    this.htmlElement.addEventListener(Events.LogLevelsFilterChanged, (event) => {
34      this.presenter.onLogLevelsFilterChanged((event as CustomEvent).detail);
35    });
36    this.htmlElement.addEventListener(Events.TagsFilterChanged, (event) => {
37      this.presenter.onTagsFilterChanged((event as CustomEvent).detail);
38    });
39    this.htmlElement.addEventListener(Events.SourceFilesFilterChanged, (event) => {
40      this.presenter.onSourceFilesFilterChanged((event as CustomEvent).detail);
41    });
42    this.htmlElement.addEventListener(Events.SearchStringFilterChanged, (event) => {
43      this.presenter.onSearchStringFilterChanged((event as CustomEvent).detail);
44    });
45  }
46
47  async onTracePositionUpdate(position: TracePosition) {
48    await this.presenter.onTracePositionUpdate(position);
49  }
50
51  getViews(): View[] {
52    return [
53      new View(
54        ViewType.TAB,
55        this.getDependencies(),
56        this.htmlElement,
57        'ProtoLog',
58        TraceType.PROTO_LOG
59      ),
60    ];
61  }
62
63  getDependencies(): TraceType[] {
64    return ViewerProtoLog.DEPENDENCIES;
65  }
66
67  static readonly DEPENDENCIES: TraceType[] = [TraceType.PROTO_LOG];
68  private htmlElement: HTMLElement;
69  private presenter: Presenter;
70}
71
72export {ViewerProtoLog};
73