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