• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef INTELL_VOICE_TRIGGER_MANAGER_H
16 #define INTELL_VOICE_TRIGGER_MANAGER_H
17 
18 #include <map>
19 #include <memory>
20 #include <mutex>
21 #include "trigger_base_type.h"
22 
23 namespace OHOS {
24 namespace IntellVoiceTrigger {
25 class TriggerService;
26 class TriggerDetector;
27 
28 class TriggerManager {
29 public:
30     TriggerManager();
31     ~TriggerManager();
32 
33     void UpdateModel(std::vector<uint8_t> buffer, int32_t uuid, TriggerModelType type);
34     void DeleteModel(int32_t uuid);
35     bool IsModelExist(int32_t uuid);
36     std::shared_ptr<GenericTriggerModel> GetModel(int32_t uuid);
37     void CreateDetector(int32_t uuid, std::function<void()> onDetected);
38     void ReleaseTriggerDetector(int32_t uuid);
39     int32_t StartDetection(int32_t uuid);
40     void StopDetection(int32_t uuid);
41     int32_t SetParameter(const std::string &key, const std::string &value);
42     std::string GetParameter(const std::string &key);
43     void OnServiceStart();
44     void OnServiceStop();
45     void OnTelephonyStateRegistryServiceChange(bool isAdded);
46     void OnAudioDistributedServiceChange(bool isAdded);
47     void OnAudioPolicyServiceChange(bool isAdded);
48 #ifdef POWER_MANAGER_ENABLE
49     void OnPowerManagerServiceChange(bool isAdded);
50 #endif
51     void OnDisplayManagerServiceChange(bool isAdded);
52 
53 private:
54     void AttachTelephonyObserver();
55     void DetachTelephonyObserver();
56     void AttachAudioCaptureListener();
57     void DetachAudioCaptureListener();
58     void AttachAudioRendererEventListener();
59     void DetachAudioRendererEventListener();
60 #ifdef POWER_MANAGER_ENABLE
61     void AttachHibernateObserver();
62     void DetachHibernateObserver();
63 #endif
64     void AttachFoldStatusListener();
65     void DetachFoldStatusListener();
66     void AttachAudioSceneEventListener();
67     void DetachAudioSceneEventListener();
68 
69 private:
70     std::mutex detectorMutex_; //这个锁回头看看有没有必要删掉
71     std::map<int32_t, std::shared_ptr<TriggerDetector>> detectors_;
72     std::shared_ptr<TriggerService> service_ = nullptr;
73 };
74 }  // namespace IntellVoiceTrigger
75 }  // namespace OHOS
76 #endif