aboutsummaryrefslogtreecommitdiff
path: root/ui/src/controller/record_controller_interfaces.ts
blob: 2dd2c91c3bf149073fd97e057c5d7caab66dce22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (C) 2019 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import {TRACE_SUFFIX} from '../common/constants';
import {ConsumerPortResponse} from './consumer_port_types';

export type ConsumerPortCallback = (_: ConsumerPortResponse) => void;
export type ErrorCallback = (_: string) => void;
export type StatusCallback = (_: string) => void;

export abstract class RpcConsumerPort {
  // The responses of the call invocations should be sent through this listener.
  // This is done by the 3 "send" methods in this abstract class.
  private consumerPortListener: Consumer;

  constructor(consumerPortListener: Consumer) {
    this.consumerPortListener = consumerPortListener;
  }

  // RequestData is the proto representing the arguments of the function call.
  abstract handleCommand(methodName: string, requestData: Uint8Array): void;

  sendMessage(data: ConsumerPortResponse) {
    this.consumerPortListener.onConsumerPortResponse(data);
  }

  sendErrorMessage(message: string) {
    this.consumerPortListener.onError(message);
  }

  sendStatus(status: string) {
    this.consumerPortListener.onStatus(status);
  }

  // Allows the recording controller to customise the suffix added to recorded
  // traces when they are downloaded. In the general case this will be
  // .perfetto-trace however if the trace is recorded compressed if could be
  // .perfetto-trace.gz etc.
  getRecordedTraceSuffix(): string {
    return TRACE_SUFFIX;
  }
}

export interface Consumer {
  onConsumerPortResponse(data: ConsumerPortResponse): void;
  onError: ErrorCallback;
  onStatus: StatusCallback;
}