1 /*
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 #pragma once
18 
19 #include <string>
20 #include <utility>
21 #include <utils/StrongPointer.h>
22 
23 #include "AudioHalVersionInfo.h"
24 
25 namespace android {
26 
27 namespace detail {
28 
29 void* createPreferredImpl(bool isCore);
30 
31 }  // namespace detail
32 
33 /**
34  * Create a client for the "preferred" (most recent) implementation of an interface.
35  * by loading the appropriate version of the shared library containing the implementation.
36  *
37  * In the audio HAL, there are two families of interfaces: core and effects. Both are
38  * packed into the same shared library for memory efficiency. Since the core and the effects
39  * interface can have different minor versions on the device, in order to avoid loading multiple
40  * shared libraries the loader function considers which interface among two has the most
41  * recent version. Thus, a pair of interface names must be passed in.
42  *
43  * @param isCore Indicating if this is audio Core HAL service interface.
44  * @return the preferred available implementation or nullptr if none are available.
45  */
46 
47 template <class Interface>
createPreferredImpl(bool isCore)48 static sp<Interface> createPreferredImpl(bool isCore) {
49     return sp<Interface>{static_cast<Interface*>(detail::createPreferredImpl(isCore))};
50 }
51 } // namespace android
52