blob: 276c2b451bbf7bc5a1a05925794d320f70ba9301 [file] [log] [blame]
Hector Dearman916c7612018-07-09 15:42:22 +01001// 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
Deepanjan Roy75b46a92018-07-24 09:11:29 -040015/**
16 * A plain js object, holding objects of type |Class| keyed by string id.
17 * We use this instead of using |Map| object since it is simpler and faster to
18 * serialize for use in postMessage.
19 */
20export interface ObjectById<Class extends{id: string}> { [id: string]: Class; }
21
Deepanjan Roy75b46a92018-07-24 09:11:29 -040022export interface TrackState {
23 id: string;
Hector Dearmana38bd902018-08-02 10:38:41 +010024 engineId: string;
Deepanjan Roy75b46a92018-07-24 09:11:29 -040025 height: number;
Hector Dearmanc62a5e32018-07-27 12:54:44 +010026 kind: string;
Hector Dearmana38bd902018-08-02 10:38:41 +010027 name: string;
28 // TODO(hjd): This needs to be nested into track kind spesific state.
29 cpu: number;
30}
31
32export interface EngineConfig {
33 id: string;
34 url: string;
35}
36
37export interface QueryConfig {
38 id: string;
39 engineId: string;
40 query: string;
41}
42
43export interface State {
44 route: string|null;
45 nextId: number;
46
47 /**
48 * Open traces.
49 */
50 engines: ObjectById<EngineConfig>;
51 tracks: ObjectById<TrackState>;
52 queries: ObjectById<QueryConfig>;
Deepanjan Roy75b46a92018-07-24 09:11:29 -040053}
Hector Dearman916c7612018-07-09 15:42:22 +010054
55export function createEmptyState(): State {
56 return {
Hector Dearmana38bd902018-08-02 10:38:41 +010057 route: null,
58 nextId: 0,
Deepanjan Roy75b46a92018-07-24 09:11:29 -040059 tracks: {},
Hector Dearmana38bd902018-08-02 10:38:41 +010060 engines: {},
61 queries: {},
Hector Dearman916c7612018-07-09 15:42:22 +010062 };
63}