1/* 2 * Copyright (c) 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 {processDataCallback} from "./i_idl_service_ext"; 17import {insertDataToMapCallback} from "./i_idl_service_ext"; 18import IIdlServiceExt from "./i_idl_service_ext"; 19import rpc from "@ohos.rpc"; 20 21export default class IdlServiceExtProxy implements IIdlServiceExt { 22 constructor(proxy) { 23 this.proxy = proxy; 24 } 25 26 processData(data: number, callback: processDataCallback): void 27 { 28 let _option = new rpc.MessageOption(); 29 let _data = new rpc.MessageParcel(); 30 let _reply = new rpc.MessageParcel(); 31 _data.writeInt(data); 32 this.proxy.sendMessageRequest(IdlServiceExtProxy.COMMAND_PROCESS_DATA, _data, _reply, _option).then(function(result) { 33 if (result.errCode === 0) { 34 let _errCode = result.reply.readInt(); 35 if (_errCode != 0) { 36 let _returnValue = undefined; 37 callback(_errCode, _returnValue); 38 return; 39 } 40 let _returnValue = result.reply.readInt(); 41 callback(_errCode, _returnValue); 42 } else { 43 console.log("sendMessageRequest failed, errCode: " + result.errCode); 44 } 45 }) 46 } 47 48 insertDataToMap(key: string, val: number, callback: insertDataToMapCallback): void 49 { 50 let _option = new rpc.MessageOption(); 51 let _data = new rpc.MessageParcel(); 52 let _reply = new rpc.MessageParcel(); 53 _data.writeString(key); 54 _data.writeInt(val); 55 this.proxy.sendMessageRequest(IdlServiceExtProxy.COMMAND_INSERT_DATA_TO_MAP, _data, _reply, _option).then(function(result) { 56 if (result.errCode === 0) { 57 let _errCode = result.reply.readInt(); 58 callback(_errCode); 59 } else { 60 console.log("sendMessageRequest failed, errCode: " + result.errCode); 61 } 62 }) 63 } 64 65 static readonly COMMAND_PROCESS_DATA = 1; 66 static readonly COMMAND_INSERT_DATA_TO_MAP = 2; 67 private proxy 68} 69