1/* 2 * Copyright (C) 2022 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 ApiMessage from '../common/apiMessage.js' 18import TestBundleManager from './testBundleManager.js' 19 20var CODE_INVOKE = 1; 21var logTag = "RpcServer"; 22 23export default class Stub extends rpc.RemoteObject { 24 constructor(descriptor) { 25 console.log(logTag +" Stub Create") 26 super(descriptor); 27 } 28 29 onRemoteRequest(code, data, reply, option) { 30 try { 31 console.log(logTag +" ============onRemoteRequest: code is" + code) 32 switch (code) { 33 case CODE_INVOKE: 34 { 35 console.info(logTag +" case CODE_INVOKE start") 36 let testBundle = new ApiMessage(null, null, null, null, null, null, null); 37 var tmp = data.readSequenceable(testBundle); 38 console.log( logTag +" read result is " + tmp + JSON.stringify(testBundle)); 39 let testBundleManager = new TestBundleManager(); 40 let testBundleResult = testBundleManager.invoke(testBundle); 41 console.log( logTag +" invoke result is " + JSON.stringify(testBundleResult)); 42 43 testBundle._apiResult=JSON.stringify(testBundleResult); 44 console.log(logTag +" The testBundle is " + JSON.stringify(testBundle)); 45 let result = reply.writeSequenceable(testBundle); 46 console.log(logTag +" writeSequenceable result is " + result); 47 return true 48 } 49 default: 50 console.error(logTag +" default case " + code) 51 return super.onRemoteRequest(code, data, reply, option) 52 } 53 } catch (error) { 54 console.log(logTag +" onRemoteRequest: " + error); 55 } 56 return false 57 } 58} 59