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 #include "engine_callback_inner.h" 16 #include <thread> 17 #include "intell_voice_log.h" 18 19 #define LOG_TAG "EngineCallbackInner" 20 21 using namespace OHOS::HDI::IntelligentVoice::Engine::V1_0; 22 23 namespace OHOS { 24 namespace IntellVoiceEngine { EngineCallbackInner(std::shared_ptr<IIntellVoiceEngineEventCallback> cb)25EngineCallbackInner::EngineCallbackInner(std::shared_ptr<IIntellVoiceEngineEventCallback> cb) : cb_(cb) 26 { 27 } 28 OnIntellVoiceEngineEvent(const IntellVoiceEngineCallBackEvent & event)29void EngineCallbackInner::OnIntellVoiceEngineEvent(const IntellVoiceEngineCallBackEvent &event) 30 { 31 INTELL_VOICE_LOG_INFO("receive event"); 32 if (cb_ == nullptr) { 33 INTELL_VOICE_LOG_INFO("cb is null"); 34 return; 35 } 36 auto msgId = event.msgId; 37 auto result = event.result; 38 auto info = event.info; 39 std::thread([this, msgId, result, info]() { 40 IntellVoiceEngineCallBackEvent tmpEvent; 41 tmpEvent.msgId = msgId; 42 tmpEvent.result = result; 43 tmpEvent.info = info; 44 cb_->OnEvent(tmpEvent); 45 }).detach(); 46 } 47 } 48 } 49