1094332d3Sopenharmony_ci/*
2094332d3Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License.
5094332d3Sopenharmony_ci * You may obtain a copy of the License at
6094332d3Sopenharmony_ci *
7094332d3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8094332d3Sopenharmony_ci *
9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and
13094332d3Sopenharmony_ci * limitations under the License.
14094332d3Sopenharmony_ci */
15094332d3Sopenharmony_ci#include "enroll_engine.h"
16094332d3Sopenharmony_ci
17094332d3Sopenharmony_ci#include <thread>
18094332d3Sopenharmony_ci#include "hdf_base.h"
19094332d3Sopenharmony_ci#include "intell_voice_log.h"
20094332d3Sopenharmony_ci
21094332d3Sopenharmony_ci#undef HDF_LOG_TAG
22094332d3Sopenharmony_ci#define HDF_LOG_TAG "IntellVoiceEnrollEngine"
23094332d3Sopenharmony_ci
24094332d3Sopenharmony_ciusing namespace OHOS::HDI::IntelligentVoice::Engine::V1_0;
25094332d3Sopenharmony_ci
26094332d3Sopenharmony_cinamespace OHOS {
27094332d3Sopenharmony_cinamespace IntelligentVoice {
28094332d3Sopenharmony_cinamespace Engine {
29094332d3Sopenharmony_ciIntellVoiceStatus EnrollEngine::Init(const IntellVoiceEngineAdapterInfo & /* adapterInfo */)
30094332d3Sopenharmony_ci{
31094332d3Sopenharmony_ci    INTELLIGENT_VOICE_LOGI("enter");
32094332d3Sopenharmony_ci    if (callback_ == nullptr) {
33094332d3Sopenharmony_ci        INTELLIGENT_VOICE_LOGE("callback is nullptr");
34094332d3Sopenharmony_ci        return HDF_ERR_INVALID_OBJECT;
35094332d3Sopenharmony_ci    }
36094332d3Sopenharmony_ci
37094332d3Sopenharmony_ci    IntellVoiceEngineCallBackEvent initEvent = {
38094332d3Sopenharmony_ci        .msgId = INTELL_VOICE_ENGINE_MSG_INIT_DONE,
39094332d3Sopenharmony_ci        .result = INTELL_VOICE_ENGINE_OK,
40094332d3Sopenharmony_ci        .info = "",
41094332d3Sopenharmony_ci    };
42094332d3Sopenharmony_ci
43094332d3Sopenharmony_ci    std::thread([&, initEvent]() { callback_->OnIntellVoiceEvent(initEvent); }).detach();
44094332d3Sopenharmony_ci    return HDF_SUCCESS;
45094332d3Sopenharmony_ci}
46094332d3Sopenharmony_ci
47094332d3Sopenharmony_ciIntellVoiceStatus EnrollEngine::SetParameter(const std::string &keyValueList)
48094332d3Sopenharmony_ci{
49094332d3Sopenharmony_ci    INTELLIGENT_VOICE_LOGI("enter, keyValueList:%{public}s", keyValueList.c_str());
50094332d3Sopenharmony_ci    if (callback_ == nullptr) {
51094332d3Sopenharmony_ci        INTELLIGENT_VOICE_LOGE("callback is nullptr");
52094332d3Sopenharmony_ci        return HDF_ERR_INVALID_OBJECT;
53094332d3Sopenharmony_ci    }
54094332d3Sopenharmony_ci
55094332d3Sopenharmony_ci    if (keyValueList.find("CommitEnrollment") != std::string::npos) {
56094332d3Sopenharmony_ci        IntellVoiceEngineCallBackEvent commitEvent = {
57094332d3Sopenharmony_ci            .msgId = INTELL_VOICE_ENGINE_MSG_COMMIT_ENROLL_COMPLETE,
58094332d3Sopenharmony_ci            .result = INTELL_VOICE_ENGINE_OK,
59094332d3Sopenharmony_ci            .info = "",
60094332d3Sopenharmony_ci        };
61094332d3Sopenharmony_ci        std::thread([&, commitEvent]() { callback_->OnIntellVoiceEvent(commitEvent); }).detach();
62094332d3Sopenharmony_ci    }
63094332d3Sopenharmony_ci    return HDF_SUCCESS;
64094332d3Sopenharmony_ci}
65094332d3Sopenharmony_ci
66094332d3Sopenharmony_ciIntellVoiceStatus EnrollEngine::Start(const StartInfo & /*info */)
67094332d3Sopenharmony_ci{
68094332d3Sopenharmony_ci    INTELLIGENT_VOICE_LOGI("enter");
69094332d3Sopenharmony_ci    if (callback_ == nullptr) {
70094332d3Sopenharmony_ci        INTELLIGENT_VOICE_LOGE("callback is nullptr");
71094332d3Sopenharmony_ci        return HDF_ERR_INVALID_OBJECT;
72094332d3Sopenharmony_ci    }
73094332d3Sopenharmony_ci
74094332d3Sopenharmony_ci    IntellVoiceEngineCallBackEvent startEvent = {
75094332d3Sopenharmony_ci        .msgId = INTELL_VOICE_ENGINE_MSG_ENROLL_COMPLETE,
76094332d3Sopenharmony_ci        .result = INTELL_VOICE_ENGINE_OK,
77094332d3Sopenharmony_ci        .info = "",
78094332d3Sopenharmony_ci    };
79094332d3Sopenharmony_ci    std::thread([&, startEvent]() { callback_->OnIntellVoiceEvent(startEvent); }).detach();
80094332d3Sopenharmony_ci    return HDF_SUCCESS;
81094332d3Sopenharmony_ci}
82094332d3Sopenharmony_ci}
83094332d3Sopenharmony_ci}
84094332d3Sopenharmony_ci}
85