1// Copyright (C) 2019 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 {ConsumerPortResponse} from './consumer_port_types'; 16 17export type ConsumerPortCallback = (_: ConsumerPortResponse) => void; 18export type ErrorCallback = (_: string) => void; 19export type StatusCallback = (_: string) => void; 20 21export abstract class RpcConsumerPort { 22 // The responses of the call invocations should be sent through this listener. 23 // This is done by the 3 "send" methods in this abstract class. 24 private consumerPortListener: Consumer; 25 26 constructor(consumerPortListener: Consumer) { 27 this.consumerPortListener = consumerPortListener; 28 } 29 30 // RequestData is the proto representing the arguments of the function call. 31 abstract handleCommand(methodName: string, requestData: Uint8Array): void; 32 33 sendMessage(data: ConsumerPortResponse) { 34 this.consumerPortListener.onConsumerPortResponse(data); 35 } 36 37 sendErrorMessage(message: string) { 38 this.consumerPortListener.onError(message); 39 } 40 41 sendStatus(status: string) { 42 this.consumerPortListener.onStatus(status); 43 } 44} 45 46export interface Consumer { 47 onConsumerPortResponse(data: ConsumerPortResponse): void; 48 onError: ErrorCallback; 49 onStatus: StatusCallback; 50}