1/* 2 * Copyright (C) 2024 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 16//@ts-nocheck 17import testApi from './testApi.ets'; 18 19var logTag = "[RpcServer_Call: ]"; 20 21export default class ReflectCallApi { 22 getModuleObj() { 23 console.log(logTag + 'getModuleObj ' ); 24 return require("./testApi.ets"); 25 } 26 27 call(request) { 28 console.log(logTag + 'call begin ' ); 29 let rtn = String(-1); 30 31 console.info(logTag + ' _methodName: [%s].', request._methodName); 32 console.info(logTag + ' _parameters: [%s].', request._parameters); 33 34 if( typeof request._methodName !== 'undefined' ) { 35 try { 36 const obj = this.getModuleObj(); 37 const myObj = obj.default.prototype; 38 const funcList = Reflect.ownKeys(myObj).toString(); 39 console.info(logTag + 'funcList: [%s].', funcList); 40 if(funcList.indexOf(request._methodName) === -1) { 41 console.info(logTag + ' ERROR: function: [%s] does not exist.', request._methodName); 42 return -1; 43 } 44 rtn = myObj[request._methodName].apply(null, request._parameters); 45 console.info(logTag + ' reflect call %s, return: %s.', request._methodName, rtn); 46 } catch (error) { 47 console.log(logTag + 'ERROR: catch error= ' + error); 48 return -1; 49 } 50 }else { 51 console.log(logTag + 'ERROR: request._methodName = undefined '); 52 return -1; 53 } 54 console.log(logTag + 'call end ' ); 55 return 1; 56 } 57 58 59}