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 WAKEUP_ENGINE_H
16 #define WAKEUP_ENGINE_H
17 
18 #include <string>
19 #include "base_macros.h"
20 #include "engine_base.h"
21 #include "wakeup_engine_impl.h"
22 #include "headset_wakeup_engine_impl.h"
23 
24 namespace OHOS {
25 namespace IntellVoiceEngine {
26 class WakeupEngine : public EngineBase {
27 public:
28     WakeupEngine();
29     ~WakeupEngine();
30     bool Init(const std::string &param) override;
31     void SetCallback(sptr<IRemoteObject> object) override;
32     int32_t Attach(const IntellVoiceEngineInfo &info) override;
33     int32_t Detach(void) override;
34     int32_t Start(bool isLast) override;
35     int32_t SetParameter(const std::string &keyValueList) override;
36     std::string GetParameter(const std::string &key) override;
37     int32_t Stop() override;
38     int32_t GetWakeupPcm(std::vector<uint8_t> &data) override;
39 
40     void OnDetected(int32_t uuid) override;
41     bool ResetAdapter() override;
42     void ReleaseAdapter() override;
43 
44     int32_t StartCapturer(int32_t channels) override;
45     int32_t Read(std::vector<uint8_t> &data) override;
46     int32_t StopCapturer() override;
47     int32_t NotifyHeadsetWakeEvent() override;
48     int32_t NotifyHeadsetHostEvent(HeadsetHostEventType event) override;
49 
50 private:
51     static void StartAbility(const std::string &event);
52     static std::string GetEventValue(int32_t uuid);
53     int32_t HandleHeadsetOff();
54     int32_t HandleHeadsetOn();
55     USE_ROLE(WakeupEngineImpl);
56 
57 private:
58     OHOS::IntellVoiceUtils::UniqueProductType<HeadsetWakeupEngineImpl> headsetImpl_ =
59         OHOS::IntellVoiceUtils::UniqueProductType<HeadsetWakeupEngineImpl>(nullptr, nullptr);
60     std::mutex headsetMutex_;
61 };
62 }
63 }
64 #endif