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 "enroll_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 "IntellVoiceEnrollEngine"
23
24 using namespace OHOS::HDI::IntelligentVoice::Engine::V1_0;
25
26 namespace OHOS {
27 namespace IntelligentVoice {
28 namespace Engine {
Init(const IntellVoiceEngineAdapterInfo &)29 IntellVoiceStatus EnrollEngine::Init(const IntellVoiceEngineAdapterInfo & /* adapterInfo */)
30 {
31 INTELLIGENT_VOICE_LOGI("enter");
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
43 std::thread([&, initEvent]() { callback_->OnIntellVoiceEvent(initEvent); }).detach();
44 return HDF_SUCCESS;
45 }
46
SetParameter(const std::string & keyValueList)47 IntellVoiceStatus EnrollEngine::SetParameter(const std::string &keyValueList)
48 {
49 INTELLIGENT_VOICE_LOGI("enter, keyValueList:%{public}s", keyValueList.c_str());
50 if (callback_ == nullptr) {
51 INTELLIGENT_VOICE_LOGE("callback is nullptr");
52 return HDF_ERR_INVALID_OBJECT;
53 }
54
55 if (keyValueList.find("CommitEnrollment") != std::string::npos) {
56 IntellVoiceEngineCallBackEvent commitEvent = {
57 .msgId = INTELL_VOICE_ENGINE_MSG_COMMIT_ENROLL_COMPLETE,
58 .result = INTELL_VOICE_ENGINE_OK,
59 .info = "",
60 };
61 std::thread([&, commitEvent]() { callback_->OnIntellVoiceEvent(commitEvent); }).detach();
62 }
63 return HDF_SUCCESS;
64 }
65
Start(const StartInfo &)66 IntellVoiceStatus EnrollEngine::Start(const StartInfo & /*info */)
67 {
68 INTELLIGENT_VOICE_LOGI("enter");
69 if (callback_ == nullptr) {
70 INTELLIGENT_VOICE_LOGE("callback is nullptr");
71 return HDF_ERR_INVALID_OBJECT;
72 }
73
74 IntellVoiceEngineCallBackEvent startEvent = {
75 .msgId = INTELL_VOICE_ENGINE_MSG_ENROLL_COMPLETE,
76 .result = INTELL_VOICE_ENGINE_OK,
77 .info = "",
78 };
79 std::thread([&, startEvent]() { callback_->OnIntellVoiceEvent(startEvent); }).detach();
80 return HDF_SUCCESS;
81 }
82 }
83 }
84 }
85