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_ADAPTER_LISTENER_H 16 #define WAKEUP_ADAPTER_LISTENER_H 17 18 #include <functional> 19 #include <memory> 20 #include <mutex> 21 #include "intell_voice_adapter_listener.h" 22 #include "i_intell_voice_engine_callback.h" 23 24 namespace OHOS { 25 namespace IntellVoiceEngine { 26 using OnWakeupEventCb = std::function<void( 27 const OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent &)>; 28 29 class WakeupAdapterListener : public IntellVoiceAdapterListener { 30 public: 31 explicit WakeupAdapterListener(OnWakeupEventCb wakeupEventCb); 32 ~WakeupAdapterListener(); 33 34 void SetCallback(const sptr<IIntelligentVoiceEngineCallback> &cb); 35 std::string GetCallbackStatus(); 36 void OnIntellVoiceHdiEvent( 37 const OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent &event) override; 38 void Notify(const OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent &event); 39 40 private: 41 void BackupCallBackEvent(const OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent &event); 42 43 private: 44 std::mutex mutex_; 45 std::shared_ptr<OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent> historyEvent_ = nullptr; 46 sptr<IIntelligentVoiceEngineCallback> cb_ = nullptr; 47 OnWakeupEventCb wakeupEventCb_ = nullptr; 48 }; 49 } // namespace IntellVoice 50 } // namespace OHOS 51 #endif