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 featureAbility from '@ohos.ability.featureAbility'; 18 19export default { 20 onStart() { 21 console.info('DmsServer: onStart') 22 setTimeout(()=>{ 23 featureAbility.terminateSelf() 24 },2000) 25 }, 26 onStop() { 27 console.info('DmsServer: onStop') 28 }, 29 onCommand(want, startId) { 30 console.info('DmsServer: onCommand, want: ' + JSON.stringify(want) +', startId: ' + startId) 31 }, 32 onConnect(want) { 33 console.info('DmsServer: service onConnect called.') 34 return new Stub("rpcTestAbility") 35 }, 36 onDisconnect(want) { 37 console.info('DmsServer: service onDisConnect called.') 38 }, 39 onReconnect(want) { 40 console.info('DmsServer: service onReConnect called.') 41 } 42} 43 44class Stub extends rpc.RemoteObject { 45 constructor(descriptor) { 46 super(descriptor); 47 } 48 49 onRemoteRequest(code, data, reply, option) { 50 try{ 51 console.info("onRemoteRequest: " + code) 52 console.info("-----------------syhsyhsysh:" + code) 53 switch(code) { 54 case 1: 55 { 56 console.info("case 1 start") 57 let tmp1 = data.readInt() 58 console.info("The server's readInt result is " + tmp1); 59 let tmp2 = data.readInt() 60 console.info("The server's readInt result is " + tmp2); 61 let tmp3 = tmp1 + tmp2; 62 console.info("The server's tmp3 result is " + tmp3); 63 let result = reply.writeInt(tmp3) 64 console.info("The server's writeInt result is " + result); 65 return true 66 } 67 default: 68 console.error("default case " + code) 69 return super.onRemoteRequest(code, data, reply, option) 70 } 71 } catch (error) { 72 console.info("onRemoteRequest: " + error); 73 } 74 return false 75 } 76}