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 
16 #ifndef I_TRIGGER_H
17 #define I_TRIGGER_H
18 #include <memory>
19 #include <vector>
20 #include "v1_2/intell_voice_trigger_types.h"
21 
22 namespace OHOS {
23 namespace IntelligentVoice {
24 namespace Trigger {
25 using OHOS::HDI::IntelligentVoice::Trigger::V1_0::IntellVoiceTriggerAdapterDsecriptor;
26 using OHOS::HDI::IntelligentVoice::Trigger::V1_0::IntellVoiceTriggerProperties;
27 using OHOS::HDI::IntelligentVoice::Trigger::V1_0::IntellVoiceTriggerModel;
28 using OHOS::HDI::IntelligentVoice::Trigger::V1_0::IntellVoiceRecognitionEvent;
29 
30 struct TriggerModel {
TriggerModelTriggerModel31     TriggerModel(OHOS::HDI::IntelligentVoice::Trigger::V1_2::IntellVoiceTriggerModelType typeIn, uint32_t uidIn,
32         std::vector<uint8_t> dataIn) : type(typeIn), uid(uidIn)
33     {
34         data.swap(dataIn);
35     }
36     OHOS::HDI::IntelligentVoice::Trigger::V1_2::IntellVoiceTriggerModelType type;
37     uint32_t uid;
38     std::vector<uint8_t> data;
39 };
40 
41 class ITriggerCallback {
42 public:
43     virtual ~ITriggerCallback() = default;
44     virtual void OnRecognitionHdiEvent(const IntellVoiceRecognitionEvent &event, int32_t cookie) = 0;
45 };
46 
47 class ITrigger {
48 public:
~ITrigger()49     virtual ~ITrigger() {};
50     virtual int32_t GetProperties(IntellVoiceTriggerProperties &properties) = 0;
51     virtual int32_t LoadIntellVoiceTriggerModel(const TriggerModel &model,
52         const std::shared_ptr<ITriggerCallback> &callback, int32_t cookie, int32_t &handle) = 0;
53     virtual int32_t UnloadIntellVoiceTriggerModel(int32_t handle) = 0;
54     virtual int32_t Start(int32_t handle) = 0;
55     virtual int32_t Stop(int32_t handle) = 0;
56     virtual int32_t SetParams(const std::string &key, const std::string &value) = 0;
57     virtual std::string GetParams(const std::string &key) = 0;
58 };
59 
60 class ITriggerManager {
61 public:
~ITriggerManager()62     virtual ~ITriggerManager() {};
63     virtual int32_t LoadAdapter(const IntellVoiceTriggerAdapterDsecriptor &descriptor,
64         std::unique_ptr<ITrigger> &adapter) = 0;
65     virtual int32_t UnloadAdapter(const IntellVoiceTriggerAdapterDsecriptor &descriptor) = 0;
66 };
67 }
68 }
69 }
70 #endif
71