1/* 2 * Copyright (c) 2025 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 { throwError } from './utils'; 17import { KNativePointer } from './InteropTypes'; 18import { 19 initEs2panda, 20 Es2pandaNativeModule, 21 initGeneratedEs2panda, 22 initPublicEs2panda, 23 initPublicGeneratedEs2panda 24} from './Es2pandaNativeModule'; 25import { Es2pandaNativeModule as GeneratedEs2pandaNativeModule } from './generated/Es2pandaNativeModule'; 26import { initInterop, InteropNativeModule, initPublicInterop } from './InteropNativeModule'; 27import { Context } from './types'; 28 29// CC-OFFNXT(G.NAM.01) project code style 30export class global { 31 public static filePath: string = './examples/input/main.ets'; 32 33 private static _config?: KNativePointer; 34 public static set config(config: KNativePointer) { 35 if (global._config !== undefined) { 36 throwError('Global.config already initialized'); 37 } 38 global._config = config; 39 } 40 41 public static get config(): KNativePointer { 42 return global._config ?? throwError('Global.config not initialized'); 43 } 44 45 public static destroyCfg(): void { 46 global._config = undefined; 47 } 48 49 public static configIsInitialized(): boolean { 50 return global._config !== undefined; 51 } 52 53 private static _context?: KNativePointer; 54 public static set context(context: KNativePointer) { 55 global._context = context; 56 } 57 public static get context(): KNativePointer { 58 return global._context ?? throwError('Global.context not initialized'); 59 } 60 61 private static _es2panda: Es2pandaNativeModule | undefined = undefined; 62 private static _es2pandaPublic: Es2pandaNativeModule | undefined = undefined; 63 public static get es2panda(): Es2pandaNativeModule { 64 if (this._es2panda === undefined) { 65 this._es2panda = initEs2panda(); 66 } 67 return this._es2panda; 68 } 69 70 public static get es2pandaPublic(): Es2pandaNativeModule { 71 if (this._es2pandaPublic === undefined) { 72 this._es2pandaPublic = initPublicEs2panda(); 73 } 74 return this._es2pandaPublic; 75 } 76 77 private static _generatedEs2panda: GeneratedEs2pandaNativeModule | undefined = undefined; 78 private static _generatedEs2pandaPublic: GeneratedEs2pandaNativeModule | undefined = undefined; 79 public static get generatedEs2panda(): GeneratedEs2pandaNativeModule { 80 if (this._generatedEs2panda === undefined) { 81 this._generatedEs2panda = initGeneratedEs2panda(); 82 } 83 return this._generatedEs2panda; 84 } 85 86 public static get generatedEs2pandaPublic(): GeneratedEs2pandaNativeModule { 87 if (this._generatedEs2pandaPublic === undefined) { 88 this._generatedEs2pandaPublic = initPublicGeneratedEs2panda(); 89 } 90 return this._generatedEs2pandaPublic; 91 } 92 93 private static _interop: InteropNativeModule | undefined = undefined; 94 private static _interopPublic: InteropNativeModule | undefined = undefined; 95 public static get interop(): InteropNativeModule { 96 if (this._interop === undefined) { 97 this._interop = initInterop(); 98 } 99 return this._interop; 100 } 101 102 public static get interopPublic(): InteropNativeModule { 103 if (this._interopPublic === undefined) { 104 this._interopPublic = initPublicInterop(); 105 } 106 return this._interopPublic; 107 } 108} 109