10704ebd2Sopenharmony_ci/*
20704ebd2Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd.
30704ebd2Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
40704ebd2Sopenharmony_ci * you may not use this file except in compliance with the License.
50704ebd2Sopenharmony_ci * You may obtain a copy of the License at
60704ebd2Sopenharmony_ci *
70704ebd2Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
80704ebd2Sopenharmony_ci *
90704ebd2Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
100704ebd2Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
110704ebd2Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
120704ebd2Sopenharmony_ci * See the License for the specific language governing permissions and
130704ebd2Sopenharmony_ci * limitations under the License.
140704ebd2Sopenharmony_ci */
150704ebd2Sopenharmony_ci
160704ebd2Sopenharmony_ci//@ts-nocheck
170704ebd2Sopenharmony_ciimport testApi from './testApi.js';
180704ebd2Sopenharmony_ci
190704ebd2Sopenharmony_civar logTag = "[RpcServer_Call:  ]";
200704ebd2Sopenharmony_ci
210704ebd2Sopenharmony_ciexport default class ReflectCallApi {
220704ebd2Sopenharmony_ci  getModuleObj() {
230704ebd2Sopenharmony_ci    console.log(logTag + 'getModuleObj ' );
240704ebd2Sopenharmony_ci    return require("./testApi.js");
250704ebd2Sopenharmony_ci  }
260704ebd2Sopenharmony_ci
270704ebd2Sopenharmony_ci  call(request) {
280704ebd2Sopenharmony_ci    console.log(logTag + 'call begin   ' );
290704ebd2Sopenharmony_ci    let rtn = String(-1);
300704ebd2Sopenharmony_ci
310704ebd2Sopenharmony_ci    console.info(logTag + '  _methodName: [%s].', request._methodName);
320704ebd2Sopenharmony_ci    console.info(logTag + '  _parameters: [%s].', request._parameters);
330704ebd2Sopenharmony_ci
340704ebd2Sopenharmony_ci    if( typeof request._methodName !== 'undefined' ) {
350704ebd2Sopenharmony_ci      try {
360704ebd2Sopenharmony_ci        const obj = this.getModuleObj();
370704ebd2Sopenharmony_ci        const myObj = obj.default.prototype;
380704ebd2Sopenharmony_ci        const funcList = Reflect.ownKeys(myObj).toString();
390704ebd2Sopenharmony_ci        console.info(logTag + 'funcList: [%s].', funcList);
400704ebd2Sopenharmony_ci        if(funcList.indexOf(request._methodName) === -1) {
410704ebd2Sopenharmony_ci          console.info(logTag + ' ERROR: function: [%s] does not exist.', request._methodName);
420704ebd2Sopenharmony_ci          return -1;
430704ebd2Sopenharmony_ci        }
440704ebd2Sopenharmony_ci        rtn = myObj[request._methodName].apply(null, request._parameters);
450704ebd2Sopenharmony_ci        console.info(logTag + ' reflect call %s, return: %s.', request._methodName, rtn);
460704ebd2Sopenharmony_ci      } catch (error) {
470704ebd2Sopenharmony_ci        console.log(logTag + 'ERROR: catch error= ' + error);
480704ebd2Sopenharmony_ci        return -1;
490704ebd2Sopenharmony_ci      }
500704ebd2Sopenharmony_ci    }else {
510704ebd2Sopenharmony_ci      console.log(logTag + 'ERROR: request._methodName = undefined ');
520704ebd2Sopenharmony_ci      return -1;
530704ebd2Sopenharmony_ci    }
540704ebd2Sopenharmony_ci    console.log(logTag + 'call end   ' );
550704ebd2Sopenharmony_ci    return 1;
560704ebd2Sopenharmony_ci  }
570704ebd2Sopenharmony_ci
580704ebd2Sopenharmony_ci
590704ebd2Sopenharmony_ci}