1/*
2 * Copyright (c) 2021-2022 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 Log from '../../default/Log';
17import { ItemComponentData, LoaderConfigInfo } from '../common/Constants';
18import { AbilityInfoWithId } from '../common/BundleParseUtil';
19
20const TAG = 'SourceLoader';
21
22export type LoaderChannel = {
23  add: (item: ItemComponentData) => void;
24  remove: (item: ItemComponentData) => void;
25  onLoadPluginComponentData: (item: ItemComponentData) => void;
26};
27
28export default abstract class SourceLoader {
29  mChannel: LoaderChannel | undefined;
30
31  constructor(config: LoaderConfigInfo) {
32    Log.showDebug(TAG, 'constructor');
33  }
34
35  setChannel(channel: LoaderChannel): void {
36    this.mChannel = channel;
37  }
38
39  protected getChannel(): LoaderChannel | undefined {
40    return this.mChannel;
41  }
42
43  protected addItem(itemData: ItemComponentData): void {
44    this.mChannel?.add(itemData);
45  }
46
47  protected removeItem(itemData: ItemComponentData): void {
48    this.mChannel?.remove(itemData);
49  }
50
51  abstract clearData(): void;
52
53  abstract onBundleRemove(bundleName: string): void;
54
55  abstract reloadData(userId: number): void;
56
57  abstract onAbilityAdd(abilityInfo: AbilityInfoWithId): void;
58}