From 5261dce877f7f20d5235fdb7b4763b35c9906392 Mon Sep 17 00:00:00 2001 From: Kevin Rocard Date: Tue, 18 Jun 2019 12:40:48 -0700 Subject: [PATCH] Audio service: Refactor register interface Remove all per interface version boilerplate. Adding a new version now requires only including the file and adding the version name to the list. Bug: 134940862 Test: adb shell lshal Change-Id: Ib6b99d7a2c2079d914970fbe804aaf3c78c143ce Signed-off-by: Kevin Rocard --- .../all-versions/default/service/service.cpp | 47 +++++++++++-------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/audio/common/all-versions/default/service/service.cpp b/audio/common/all-versions/default/service/service.cpp index 8a7b2ea09d..2a6571b9e3 100644 --- a/audio/common/all-versions/default/service/service.cpp +++ b/audio/common/all-versions/default/service/service.cpp @@ -36,6 +36,15 @@ using namespace android::hardware; using android::OK; +/** Try to register the provided factories in the provided order. + * If any registers successfully, do not register any other and return true. + * If all fail, return false. + */ +template +bool registerPassthroughServiceImplementations() { + return ((registerPassthroughServiceImplementation() != OK) && ...); +} + int main(int /* argc */, char* /* argv */ []) { ::android::ProcessState::initWithDriver("/dev/vndbinder"); // start a threadpool for vndbinder interactions @@ -50,30 +59,30 @@ int main(int /* argc */, char* /* argv */ []) { } configureRpcThreadpool(16, true /*callerWillJoin*/); - bool fail = registerPassthroughServiceImplementation() != OK && - registerPassthroughServiceImplementation() != OK && - registerPassthroughServiceImplementation() != OK; - LOG_ALWAYS_FATAL_IF(fail, "Could not register audio core API 2, 4 nor 5"); + LOG_ALWAYS_FATAL_IF((registerPassthroughServiceImplementations()), + "Could not register audio core API"); - fail = registerPassthroughServiceImplementation() != OK && - registerPassthroughServiceImplementation() != OK && - registerPassthroughServiceImplementation() != OK, - LOG_ALWAYS_FATAL_IF(fail, "Could not register audio effect API 2, 4 nor 5"); + LOG_ALWAYS_FATAL_IF( + (registerPassthroughServiceImplementations()), + "Could not register audio effect API"); - fail = registerPassthroughServiceImplementation() != OK && - registerPassthroughServiceImplementation() != OK && - registerPassthroughServiceImplementation() != OK, - ALOGW_IF(fail, "Could not register soundtrigger API 2.0, 2.1 nor 2.2"); + ALOGW_IF((registerPassthroughServiceImplementations()), + "Could not register soundtrigger API"); - fail = registerPassthroughServiceImplementation< - bluetooth::audio::V2_0::IBluetoothAudioProvidersFactory>() != OK; - ALOGW_IF(fail, "Could not register Bluetooth Audio API 2.0"); + ALOGW_IF(registerPassthroughServiceImplementations< + bluetooth::audio::V2_0::IBluetoothAudioProvidersFactory>(), + "Could not register Bluetooth audio API"); // remove the old HIDL when Bluetooth Audio Hal V2 has offloading supported - fail = - registerPassthroughServiceImplementation() != - OK; - ALOGW_IF(fail, "Could not register Bluetooth audio offload 1.0"); + ALOGW_IF(registerPassthroughServiceImplementations< + bluetooth::a2dp::V1_0::IBluetoothAudioOffload>(), + "Could not register Bluetooth audio offload API"); joinRpcThreadpool(); }