1/* 2 * Copyright (c) 2023-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 { PrinterDiscController } from '../../Controller/PrinterDiscController'; 17import { PrintExtensionController } from '../../Controller/PrintExtensionController'; 18import { Log } from '@ohos/common'; 19import { GlobalThisHelper, GlobalThisStorageKey} from '@ohos/common'; 20 21const TAG: string = '[PrintAdapter]:'; 22 23export default class PrintAdapter { 24 private mPrinterDiscController?: PrinterDiscController; 25 private mPrintExtensionController?: PrintExtensionController; 26 27 constructor() { 28 this.init(); 29 } 30 31 public static getInstance(): PrintAdapter { 32 if (GlobalThisHelper.getValue<PrintAdapter>(GlobalThisStorageKey.KEY_PRINT_ADAPTER) !== undefined) { 33 return GlobalThisHelper.getValue<PrintAdapter>(GlobalThisStorageKey.KEY_PRINT_ADAPTER); 34 } 35 return GlobalThisHelper.createValue<PrintAdapter>(new PrintAdapter(), GlobalThisStorageKey.KEY_PRINT_ADAPTER); 36 } 37 38 init(): void { 39 Log.info(TAG, 'PrintAdapter init'); 40 this.mPrinterDiscController = new PrinterDiscController(); 41 this.mPrinterDiscController.init(); 42 this.mPrintExtensionController = new PrintExtensionController(); 43 this.mPrintExtensionController.init(); 44 } 45 46 public destroy(): void { 47 Log.info(TAG, 'onDestroy'); 48 if (this.mPrinterDiscController !== undefined) { 49 this.mPrinterDiscController.destroy(); 50 } 51 } 52 53 /** 54 * get device discovery controller 55 * 56 * @return DeviceDiscController 57 */ 58 public getPrinterDiscCtl(): PrinterDiscController | undefined { 59 return this.mPrinterDiscController; 60 } 61 62 /** 63 * get PrintExtension controller 64 * 65 * @return PrintExtensionController 66 */ 67 public getPrintExtensionCtl(): PrintExtensionController | undefined { 68 return this.mPrintExtensionController; 69 } 70}