1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_HARDWARE_SOUNDTRIGGER_V2_1_SOUNDTRIGGERHW_H
18 #define ANDROID_HARDWARE_SOUNDTRIGGER_V2_1_SOUNDTRIGGERHW_H
19 
20 #include <SoundTriggerHalImpl.h>
21 #include <android/hardware/soundtrigger/2.1/ISoundTriggerHw.h>
22 #include <hidl/Status.h>
23 
24 namespace android {
25 namespace hardware {
26 namespace soundtrigger {
27 namespace V2_1 {
28 namespace implementation {
29 
30 using ::android::sp;
31 using ::android::hardware::hidl_string;
32 using ::android::hardware::hidl_vec;
33 using ::android::hardware::Return;
34 using ::android::hardware::Void;
35 
36 struct SoundTriggerHw : public V2_0::implementation::SoundTriggerHalImpl {
37     SoundTriggerHw() = default;
getInterfaceSoundTriggerHw38     ISoundTriggerHw* getInterface() { return new TrampolineSoundTriggerHw_2_1(this); }
39 
40    protected:
41     virtual ~SoundTriggerHw() = default;
42 
43     Return<void> loadSoundModel_2_1(const V2_1::ISoundTriggerHw::SoundModel& soundModel,
44                                     const sp<V2_1::ISoundTriggerHwCallback>& callback,
45                                     int32_t cookie,
46                                     V2_1::ISoundTriggerHw::loadSoundModel_2_1_cb _hidl_cb);
47     Return<void> loadPhraseSoundModel_2_1(
48         const V2_1::ISoundTriggerHw::PhraseSoundModel& soundModel,
49         const sp<V2_1::ISoundTriggerHwCallback>& callback, int32_t cookie,
50         V2_1::ISoundTriggerHw::loadPhraseSoundModel_2_1_cb _hidl_cb);
51     Return<int32_t> startRecognition_2_1(int32_t modelHandle,
52                                          const V2_1::ISoundTriggerHw::RecognitionConfig& config);
53 
54    private:
55     struct TrampolineSoundTriggerHw_2_1 : public ISoundTriggerHw {
TrampolineSoundTriggerHw_2_1SoundTriggerHw::TrampolineSoundTriggerHw_2_156         explicit TrampolineSoundTriggerHw_2_1(sp<SoundTriggerHw> impl) : mImpl(impl) {}
57 
58         // Methods from ::android::hardware::soundtrigger::V2_0::ISoundTriggerHw follow.
getPropertiesSoundTriggerHw::TrampolineSoundTriggerHw_2_159         Return<void> getProperties(getProperties_cb _hidl_cb) override {
60             return mImpl->getProperties(_hidl_cb);
61         }
loadSoundModelSoundTriggerHw::TrampolineSoundTriggerHw_2_162         Return<void> loadSoundModel(const V2_0::ISoundTriggerHw::SoundModel& soundModel,
63                                     const sp<V2_0::ISoundTriggerHwCallback>& callback,
64                                     int32_t cookie, loadSoundModel_cb _hidl_cb) override {
65             return mImpl->loadSoundModel(soundModel, callback, cookie, _hidl_cb);
66         }
loadPhraseSoundModelSoundTriggerHw::TrampolineSoundTriggerHw_2_167         Return<void> loadPhraseSoundModel(const V2_0::ISoundTriggerHw::PhraseSoundModel& soundModel,
68                                           const sp<V2_0::ISoundTriggerHwCallback>& callback,
69                                           int32_t cookie,
70                                           loadPhraseSoundModel_cb _hidl_cb) override {
71             return mImpl->loadPhraseSoundModel(soundModel, callback, cookie, _hidl_cb);
72         }
unloadSoundModelSoundTriggerHw::TrampolineSoundTriggerHw_2_173         Return<int32_t> unloadSoundModel(V2_0::SoundModelHandle modelHandle) override {
74             return mImpl->unloadSoundModel(modelHandle);
75         }
startRecognitionSoundTriggerHw::TrampolineSoundTriggerHw_2_176         Return<int32_t> startRecognition(int32_t modelHandle,
77                                          const V2_0::ISoundTriggerHw::RecognitionConfig& config,
78                                          const sp<V2_0::ISoundTriggerHwCallback>& /*callback*/,
79                                          int32_t /*cookie*/) override {
80             return mImpl->startRecognition(modelHandle, config);
81         }
stopRecognitionSoundTriggerHw::TrampolineSoundTriggerHw_2_182         Return<int32_t> stopRecognition(V2_0::SoundModelHandle modelHandle) override {
83             return mImpl->stopRecognition(modelHandle);
84         }
stopAllRecognitionsSoundTriggerHw::TrampolineSoundTriggerHw_2_185         Return<int32_t> stopAllRecognitions() override { return mImpl->stopAllRecognitions(); }
86 
87         // Methods from V2_1::ISoundTriggerHw follow.
loadSoundModel_2_1SoundTriggerHw::TrampolineSoundTriggerHw_2_188         Return<void> loadSoundModel_2_1(const V2_1::ISoundTriggerHw::SoundModel& soundModel,
89                                         const sp<V2_1::ISoundTriggerHwCallback>& callback,
90                                         int32_t cookie, loadSoundModel_2_1_cb _hidl_cb) override {
91             return mImpl->loadSoundModel_2_1(soundModel, callback, cookie, _hidl_cb);
92         }
loadPhraseSoundModel_2_1SoundTriggerHw::TrampolineSoundTriggerHw_2_193         Return<void> loadPhraseSoundModel_2_1(
94             const V2_1::ISoundTriggerHw::PhraseSoundModel& soundModel,
95             const sp<V2_1::ISoundTriggerHwCallback>& callback, int32_t cookie,
96             loadPhraseSoundModel_2_1_cb _hidl_cb) override {
97             return mImpl->loadPhraseSoundModel_2_1(soundModel, callback, cookie, _hidl_cb);
98         }
startRecognition_2_1SoundTriggerHw::TrampolineSoundTriggerHw_2_199         Return<int32_t> startRecognition_2_1(int32_t modelHandle,
100                                              const V2_1::ISoundTriggerHw::RecognitionConfig& config,
101                                              const sp<V2_1::ISoundTriggerHwCallback>& /*callback*/,
102                                              int32_t /*cookie*/) override {
103             return mImpl->startRecognition_2_1(modelHandle, config);
104         }
105 
106        private:
107         sp<SoundTriggerHw> mImpl;
108     };
109 
110     class SoundModelClient_2_1 : public SoundModelClient {
111        public:
SoundModelClient_2_1SoundTriggerHw112         SoundModelClient_2_1(uint32_t id, V2_1::ISoundTriggerHwCallback::CallbackCookie cookie,
113                              sp<V2_1::ISoundTriggerHwCallback> callback)
114             : SoundModelClient(id, cookie), mCallback(callback) {}
115 
116         void recognitionCallback(struct sound_trigger_recognition_event* halEvent) override;
117         void soundModelCallback(struct sound_trigger_model_event* halEvent) override;
118 
119        private:
120         sp<V2_1::ISoundTriggerHwCallback> mCallback;
121     };
122 };
123 
124 extern "C" ISoundTriggerHw* HIDL_FETCH_ISoundTriggerHw(const char* name);
125 
126 }  // namespace implementation
127 }  // namespace V2_1
128 }  // namespace soundtrigger
129 }  // namespace hardware
130 }  // namespace android
131 
132 #endif  // ANDROID_HARDWARE_SOUNDTRIGGER_V2_1_SOUNDTRIGGERHW_H
133