1/* 2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 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 */ 15 16import rpc from '@ohos.rpc' 17import { Logger } from '../common/Logger' 18import { PRICE_LIST } from '../muck/MyData' 19 20const TAG = '[eTSRPC.ReceivedData]' 21let resultList: Array<number> = Array.from({ length: 4 }, () => 0) 22 23class ReceivedData extends rpc.RemoteObject { 24 onRemoteRequest(code: number, data: rpc.MessageParcel, reply: rpc.MessageParcel, option: rpc.MessageOption): boolean { 25 Logger.info(TAG, `called`) 26 if (code === 1) { 27 let result = 0 28 let readIntArr 29 try { 30 readIntArr = data.readStringArray() 31 } catch (err) { 32 Logger.error(`readStringArray failed, code is ${err.code}, message is ${err.message}`) 33 } 34 Logger.info(TAG, `readIntArr= ${readIntArr}`) 35 for (let i = 0; i < 4; i++) { 36 if (readIntArr[i] === '0') { 37 resultList[i] = 0 38 } else { 39 resultList[i] = PRICE_LIST.get(readIntArr[i]) * Number(readIntArr[i+4]) 40 } 41 Logger.info(TAG, `this.resultList= ${resultList}`) 42 result += resultList[i] 43 } 44 try { 45 reply.writeInt(result) 46 } catch (err) { 47 Logger.error(TAG, `writeInt failed, code is ${err.code}, message is ${err.message}`) 48 } 49 Logger.info(TAG, `result= ${result}`) 50 } else { 51 Logger.info(TAG, `unknown request code`) 52 } 53 return true 54 } 55} 56 57export default new ReceivedData('send')