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 IdlServiceExtStub extends rpc.RemoteObject implements IIdlServiceExt {
22    constructor(des: string) {
23        super(des);
24    }
25
26    async onRemoteMessageRequest(code: number, data, reply, option): Promise<boolean> {
27        console.log("onRemoteMessageRequest called, code = " + code);
28        switch(code) {
29            case IdlServiceExtStub.COMMAND_PROCESS_DATA: {
30                let _data = data.readInt();
31                this.processData(_data, (errCode, returnValue) => {
32                    reply.writeInt(errCode);
33                    if (errCode == 0) {
34                        reply.writeInt(returnValue);
35                    }
36                });
37                return true;
38            }
39            case IdlServiceExtStub.COMMAND_INSERT_DATA_TO_MAP: {
40                let _key = data.readString();
41                let _val = data.readInt();
42                this.insertDataToMap(_key, _val, (errCode) => {
43                    reply.writeInt(errCode);
44                });
45                return true;
46            }
47            default: {
48                console.log("invalid request code" + code);
49                break;
50            }
51        }
52        return false;
53    }
54
55    processData(data: number, callback: processDataCallback): void{}
56    insertDataToMap(key: string, val: number, callback: insertDataToMapCallback): void{}
57
58    static readonly COMMAND_PROCESS_DATA = 1;
59    static readonly COMMAND_INSERT_DATA_TO_MAP = 2;
60}
61