1 /*
2  * Copyright (c) 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 
16 #ifndef INTELL_VOICE_ENGINE_ARBITRATION_H
17 #define INTELL_VOICE_ENGINE_ARBITRATION_H
18 
19 #include <map>
20 #include "engine_base.h"
21 
22 namespace OHOS {
23 namespace IntellVoiceEngine {
24 enum EngineRelationType {
25     CONCURRENCY_TYPE = 0,
26     REJECTION_TYPE,
27     PREEMPTION_TYPE,
28     REPLACEMENT_TYPE,
29 };
30 
31 enum ArbitrationResult {
32     ARBITRATION_OK = 0,
33     ARBITRATION_REJECT,
34 };
35 
36 class IntellVoiceEngineArbitration {
37 public:
38     IntellVoiceEngineArbitration();
39     ~IntellVoiceEngineArbitration();
40 
41     ArbitrationResult ApplyArbitration(IntellVoiceEngineType type,
42         std::map<IntellVoiceEngineType, sptr<EngineBase>> &engines);
43     sptr<EngineBase> GetEngine(IntellVoiceEngineType type,
44         const std::map<IntellVoiceEngineType, sptr<EngineBase>> &engines);
45 
46 private:
47     bool JudgeRejection(IntellVoiceEngineType type, const std::map<IntellVoiceEngineType, sptr<EngineBase>> &engines);
48     void HandlePreemption(IntellVoiceEngineType type,
49         const std::map<IntellVoiceEngineType, sptr<EngineBase>> &engines);
50     void HandleReplace(IntellVoiceEngineType type, std::map<IntellVoiceEngineType, sptr<EngineBase>> &engines);
51 
52 private:
53     std::map<IntellVoiceEngineType, std::map<IntellVoiceEngineType, EngineRelationType>> engineRelationTbl_;
54 };
55 }
56 }
57 #endif
58 
59