1 /* 2 * Copyright (C) 2020 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 #pragma once 18 #include <memory> 19 #include PATH(android/hardware/audio/FILE_VERSION/IDevicesFactory.h) 20 #include <dlfcn.h> 21 22 namespace android { 23 namespace hardware { 24 namespace audio { 25 namespace CPP_VERSION { 26 namespace implementation { 27 28 using ::android::hardware::hidl_string; 29 using ::android::hardware::Return; 30 using namespace ::android::hardware::audio::CPP_VERSION; 31 32 struct DevicesFactory : public IDevicesFactory { 33 DevicesFactory(); 34 35 Return<void> openDevice(const hidl_string& device, openDevice_cb _hidl_cb) override; 36 Return<void> openPrimaryDevice(openPrimaryDevice_cb _hidl_cb) override; 37 #if MAJOR_VERSION == 7 && MINOR_VERSION == 1 38 Return<void> openDevice_7_1(const hidl_string& device, openDevice_7_1_cb _hidl_cb) override; 39 Return<void> openPrimaryDevice_7_1(openPrimaryDevice_7_1_cb _hidl_cb) override; 40 #endif 41 42 private: 43 struct DLDeleter { operatorDevicesFactory::DLDeleter44 void operator()(void* dl) const { 45 ::dlclose(dl); 46 } 47 }; 48 49 std::unique_ptr<void, DLDeleter> mLegacyLib; 50 std::unique_ptr<IDevicesFactory> mLegacyFactory; 51 }; 52 53 } // namespace implementation 54 } // namespace CPP_VERSION 55 } // namespace audio 56 } // namespace hardware 57 } // namespace android 58