• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2
3/*
4 * Copyright (c) 2023 Huawei Device Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18import { Log } from '../utils/Log'
19import { Constants } from '../utils/Constants'
20import { EventBus } from './eventbus/EventBus'
21import { EventBusManager } from './eventbus/EventBusManager'
22import { WorkerManager } from './WorkerManager'
23import { IModeMap } from '../featureservice/IModeMap';
24export class CameraWorker {
25  private static TAG = '[CameraWorker]:'
26  private appEventBus: EventBus = EventBusManager.getWorkerInstance().getEventBus()
27  private workerManager: WorkerManager
28
29  constructor(modeMap: IModeMap) {
30    this.workerManager = new WorkerManager()
31    // 接收UI线程的消息,并继续发送
32    this.appEventBus.on('MAIN_TO_WORKER', (msg) => {
33      console.info(`[CameraWorker]:  action from main thread: ${JSON.stringify(msg)}`)
34      this.workerManager.onMessage(msg)
35    })
36  }
37
38  public static getInstance(modeMap: IModeMap): CameraWorker {
39    if (!AppStorage.Has(Constants.APP_KEY_CAMERA_WORKER)) {
40      AppStorage.SetOrCreate(Constants.APP_KEY_CAMERA_WORKER, new CameraWorker(modeMap))
41      Log.info(`${this.TAG} build new CameraWorker.`)
42    }
43    return AppStorage.Get(Constants.APP_KEY_CAMERA_WORKER);
44  }
45}