Hector Dearman | 916c761 | 2018-07-09 15:42:22 +0100 | [diff] [blame] | 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 | |
Deepanjan Roy | 75b46a9 | 2018-07-24 09:11:29 -0400 | [diff] [blame] | 15 | /** |
| 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 | */ |
| 20 | export interface ObjectById<Class extends{id: string}> { [id: string]: Class; } |
| 21 | |
Deepanjan Roy | 75b46a9 | 2018-07-24 09:11:29 -0400 | [diff] [blame] | 22 | export interface TrackState { |
| 23 | id: string; |
Hector Dearman | a38bd90 | 2018-08-02 10:38:41 +0100 | [diff] [blame] | 24 | engineId: string; |
Deepanjan Roy | 75b46a9 | 2018-07-24 09:11:29 -0400 | [diff] [blame] | 25 | height: number; |
Hector Dearman | c62a5e3 | 2018-07-27 12:54:44 +0100 | [diff] [blame] | 26 | kind: string; |
Hector Dearman | a38bd90 | 2018-08-02 10:38:41 +0100 | [diff] [blame] | 27 | name: string; |
| 28 | // TODO(hjd): This needs to be nested into track kind spesific state. |
| 29 | cpu: number; |
| 30 | } |
| 31 | |
| 32 | export interface EngineConfig { |
| 33 | id: string; |
Primiano Tucci | 8afc06d | 2018-08-06 19:11:42 +0100 | [diff] [blame^] | 34 | ready: boolean; |
Hector Dearman | f9f2db0 | 2018-08-03 13:09:32 +0100 | [diff] [blame] | 35 | source: string|File; |
Hector Dearman | a38bd90 | 2018-08-02 10:38:41 +0100 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | export interface QueryConfig { |
| 39 | id: string; |
| 40 | engineId: string; |
| 41 | query: string; |
| 42 | } |
| 43 | |
| 44 | export interface State { |
| 45 | route: string|null; |
| 46 | nextId: number; |
| 47 | |
| 48 | /** |
| 49 | * Open traces. |
| 50 | */ |
| 51 | engines: ObjectById<EngineConfig>; |
| 52 | tracks: ObjectById<TrackState>; |
Michail Schwab | 1cc1aa0 | 2018-08-02 14:45:35 -0400 | [diff] [blame] | 53 | displayedTrackIds: string[]; |
Hector Dearman | a38bd90 | 2018-08-02 10:38:41 +0100 | [diff] [blame] | 54 | queries: ObjectById<QueryConfig>; |
Deepanjan Roy | 75b46a9 | 2018-07-24 09:11:29 -0400 | [diff] [blame] | 55 | } |
Hector Dearman | 916c761 | 2018-07-09 15:42:22 +0100 | [diff] [blame] | 56 | |
| 57 | export function createEmptyState(): State { |
| 58 | return { |
Hector Dearman | a38bd90 | 2018-08-02 10:38:41 +0100 | [diff] [blame] | 59 | route: null, |
| 60 | nextId: 0, |
Deepanjan Roy | 75b46a9 | 2018-07-24 09:11:29 -0400 | [diff] [blame] | 61 | tracks: {}, |
Michail Schwab | 1cc1aa0 | 2018-08-02 14:45:35 -0400 | [diff] [blame] | 62 | displayedTrackIds: [], |
Hector Dearman | a38bd90 | 2018-08-02 10:38:41 +0100 | [diff] [blame] | 63 | engines: {}, |
| 64 | queries: {}, |
Hector Dearman | 916c761 | 2018-07-09 15:42:22 +0100 | [diff] [blame] | 65 | }; |
| 66 | } |