• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_FACTORY_HAL_HIDL_H
18 #define ANDROID_HARDWARE_FACTORY_HAL_HIDL_H
19 
20 #include <string>
21 #include <utility>
22 
23 #include <utils/StrongPointer.h>
24 
25 namespace android {
26 
27 // The pair of the interface's package name and the interface name,
28 // e.g. <"android.hardware.audio", "IDevicesFactory">.
29 // Splitting is used for easier construction of versioned names (FQNs).
30 using InterfaceName = std::pair<std::string, std::string>;
31 
32 namespace detail {
33 
34 void* createPreferredImpl(const InterfaceName& iface, const InterfaceName& siblingIface);
35 
36 }  // namespace detail
37 
38 /**
39  * Create a client for the "preferred" (most recent) implementation of an interface.
40  * by loading the appropriate version of the shared library containing the implementation.
41  *
42  * In the audio HAL, there are two families of interfaces: core and effects. Both are
43  * packed into the same shared library for memory efficiency. Since the core and the effects
44  * interface can have different minor versions on the device, in order to avoid loading multiple
45  * shared libraries the loader function considers which interface among two has the most
46  * recent version. Thus, a pair of interface names must be passed in.
47  *
48  * @param iface the interface that needs to be created.
49  * @param siblingIface the interface which occupies the same shared library.
50  * @return the preferred available implementation or nullptr if none are available.
51  */
52 template <class Interface>
createPreferredImpl(const InterfaceName & iface,const InterfaceName & siblingIface)53 static sp<Interface> createPreferredImpl(
54         const InterfaceName& iface, const InterfaceName& siblingIface) {
55     return sp<Interface>{
56         static_cast<Interface*>(detail::createPreferredImpl(iface, siblingIface))};
57 }
58 
59 } // namespace android
60 
61 #endif // ANDROID_HARDWARE_FACTORY_HAL_HIDL_H
62