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