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 "wakeup_engine.h"
16
17#include <thread>
18#include "hdf_base.h"
19#include "intell_voice_log.h"
20
21#undef HDF_LOG_TAG
22#define HDF_LOG_TAG "IntellVoiceWakeupEngine"
23
24using namespace std;
25using namespace OHOS::HDI::IntelligentVoice::Engine::V1_0;
26
27namespace OHOS {
28namespace IntelligentVoice {
29namespace Engine {
30IntellVoiceStatus WakeupEngine::Init(const IntellVoiceEngineAdapterInfo & /* adapterInfo */)
31{
32    if (callback_ == nullptr) {
33        INTELLIGENT_VOICE_LOGE("callback is nullptr");
34        return HDF_ERR_INVALID_OBJECT;
35    }
36
37    IntellVoiceEngineCallBackEvent initEvent = {
38        .msgId = INTELL_VOICE_ENGINE_MSG_INIT_DONE,
39        .result = INTELL_VOICE_ENGINE_OK,
40        .info = "",
41    };
42    callback_->OnIntellVoiceEvent(initEvent);
43    return HDF_SUCCESS;
44}
45
46IntellVoiceStatus WakeupEngine::Start(const StartInfo & /*info */)
47{
48    if (callback_ == nullptr) {
49        INTELLIGENT_VOICE_LOGE("callback is nullptr");
50        return HDF_ERR_INVALID_OBJECT;
51    }
52
53    IntellVoiceEngineCallBackEvent startEvent = {
54        .msgId = INTELL_VOICE_ENGINE_MSG_RECOGNIZE_COMPLETE,
55        .result = INTELL_VOICE_ENGINE_OK,
56        .info = "",
57    };
58    std::thread([&, startEvent]() { callback_->OnIntellVoiceEvent(startEvent); }).detach();
59    return HDF_SUCCESS;
60}
61}
62}
63}
64