blob: 50796d0ce05ab90a648056769194a0beed1e1b10 [file] [log] [blame]
Vlad Popaf4fe41c2022-12-14 11:57:26 +01001/*
2 * Copyright (C) 2022 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#define LOG_TAG "AHAL_SoundDoseFactory"
18
19#include "SoundDoseFactory.h"
20
21#include <android-base/logging.h>
22#include <core-impl/SoundDose.h>
23
24namespace aidl::android::hardware::audio::sounddose {
25
26using ::aidl::android::hardware::audio::core::SoundDose;
27
28ndk::ScopedAStatus SoundDoseFactory::getSoundDose(const std::string& in_module,
29 std::shared_ptr<ISoundDose>* _aidl_return) {
30 auto soundDoseIt = mSoundDoseBinderMap.find(in_module);
31 if (soundDoseIt != mSoundDoseBinderMap.end()) {
32 *_aidl_return = ISoundDose::fromBinder(soundDoseIt->second);
33
34 LOG(DEBUG) << __func__
35 << ": returning cached instance of ISoundDose: " << _aidl_return->get()
36 << " for module " << in_module;
37 return ndk::ScopedAStatus::ok();
38 }
39
40 auto soundDose = ndk::SharedRefBase::make<SoundDose>();
41 mSoundDoseBinderMap[in_module] = soundDose->asBinder();
42 *_aidl_return = soundDose;
43
44 LOG(DEBUG) << __func__ << ": returning new instance of ISoundDose: " << _aidl_return->get()
45 << " for module " << in_module;
46 return ndk::ScopedAStatus::ok();
47}
48
49} // namespace aidl::android::hardware::audio::sounddose