• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 I_ENGINE_H
16 #define I_ENGINE_H
17 
18 #include <functional>
19 #include <memory>
20 #include "v1_0/intell_voice_engine_types.h"
21 #include "v1_1/intell_voice_engine_types.h"
22 
23 namespace OHOS {
24 namespace IntelligentVoice {
25 namespace Engine {
26 using OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent;
27 using OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineAdapterInfo;
28 using OHOS::HDI::IntelligentVoice::Engine::V1_0::StartInfo;
29 using OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineAdapterDescriptor;
30 using OHOS::HDI::IntelligentVoice::Engine::V1_0::ContentType;
31 using OHOS::HDI::IntelligentVoice::Engine::V1_1::IntellVoiceDataOprType;
32 
33 using IntellVoiceStatus = int32_t;
34 
35 using getParameterCb = std::function<void(const std::string &retStr)>;
36 using getFileDataCb = std::function<void(std::shared_ptr<uint8_t> data, uint32_t size)>;
37 
38 class IEngineCallback {
39 public:
40     IEngineCallback() = default;
41     virtual ~IEngineCallback() = default;
42     virtual void OnIntellVoiceEvent(const IntellVoiceEngineCallBackEvent &event) = 0;
43 };
44 
45 struct OprDataInfo {
46     std::shared_ptr<char> data = nullptr;
47     uint32_t size = 0;
48 };
49 
50 class IDataOprListener {
51 public:
52     IDataOprListener() = default;
53     virtual ~IDataOprListener() = default;
54     virtual int32_t OnDataOprEvent(IntellVoiceDataOprType type, const OprDataInfo &inData, OprDataInfo &outData) = 0;
55 };
56 
57 class IEngine {
58 public:
IEngine()59     IEngine() {};
~IEngine()60     virtual ~IEngine() {};
61     virtual IntellVoiceStatus SetListener(std::shared_ptr<IEngineCallback> listener) = 0;
62     virtual IntellVoiceStatus Init(const IntellVoiceEngineAdapterInfo &adapterInfo) = 0;
63     virtual IntellVoiceStatus Release() = 0;
64     virtual IntellVoiceStatus SetParameter(const std::string &keyValueList) = 0;
65     virtual IntellVoiceStatus GetParameter(const std::string &keyList, getParameterCb cb) = 0;
66     virtual IntellVoiceStatus Write(const uint8_t *buffer, uint32_t size) = 0;
67     virtual IntellVoiceStatus Start(const StartInfo &info) = 0;
68     virtual IntellVoiceStatus Stop() = 0;
69     virtual IntellVoiceStatus Cancel() = 0;
70     virtual IntellVoiceStatus ReadFileData(ContentType type, getFileDataCb cb) = 0;
71 };
72 
73 class IEngineManager {
74 public:
75     virtual int32_t CreateAdapter(const IntellVoiceEngineAdapterDescriptor &descriptor,
76         std::unique_ptr<IEngine> &engine) = 0;
77     virtual int32_t ReleaseAdapter(const IntellVoiceEngineAdapterDescriptor &descriptor) = 0;
78     virtual int32_t SetDataOprListener(std::shared_ptr<IDataOprListener> listener) = 0;
79 };
80 }
81 }
82 }
83 #endif