From 4122f6328a94572d69f9d0e917a8ebe6e70d1630 Mon Sep 17 00:00:00 2001 From: Mikhail Naganov Date: Thu, 29 Oct 2020 12:37:00 -0700 Subject: [PATCH] Move UUID conversions into their own class Mechanical extraction of HidlUtils::uuidFrom/ToHal into a dedicated class UuidUtils. Bug: 142480271 Test: m Change-Id: Ic5333ba32dc293f32c5562d0ef05bde8e5f9b302 Merged-In: Ic5333ba32dc293f32c5562d0ef05bde8e5f9b302 --- audio/common/all-versions/default/Android.bp | 1 + .../common/all-versions/default/HidlUtils.cpp | 16 ------ audio/common/all-versions/default/HidlUtils.h | 2 - .../common/all-versions/default/UuidUtils.cpp | 50 +++++++++++++++++++ audio/common/all-versions/default/UuidUtils.h | 50 +++++++++++++++++++ .../all-versions/default/Conversions.cpp | 8 +-- .../all-versions/default/EffectsFactory.cpp | 8 +-- 7 files changed, 109 insertions(+), 26 deletions(-) create mode 100644 audio/common/all-versions/default/UuidUtils.cpp create mode 100644 audio/common/all-versions/default/UuidUtils.h diff --git a/audio/common/all-versions/default/Android.bp b/audio/common/all-versions/default/Android.bp index a72c8dc989..afaa7bb41a 100644 --- a/audio/common/all-versions/default/Android.bp +++ b/audio/common/all-versions/default/Android.bp @@ -46,6 +46,7 @@ cc_defaults { vendor_available: true, srcs: [ "HidlUtils.cpp", + "UuidUtils.cpp", ], export_include_dirs: ["."], diff --git a/audio/common/all-versions/default/HidlUtils.cpp b/audio/common/all-versions/default/HidlUtils.cpp index a470c9cb78..7530d050ff 100644 --- a/audio/common/all-versions/default/HidlUtils.cpp +++ b/audio/common/all-versions/default/HidlUtils.cpp @@ -358,22 +358,6 @@ void HidlUtils::audioPortToHal(const AudioPort& port, struct audio_port* halPort } } -void HidlUtils::uuidFromHal(const audio_uuid_t& halUuid, Uuid* uuid) { - uuid->timeLow = halUuid.timeLow; - uuid->timeMid = halUuid.timeMid; - uuid->versionAndTimeHigh = halUuid.timeHiAndVersion; - uuid->variantAndClockSeqHigh = halUuid.clockSeq; - memcpy(uuid->node.data(), halUuid.node, uuid->node.size()); -} - -void HidlUtils::uuidToHal(const Uuid& uuid, audio_uuid_t* halUuid) { - halUuid->timeLow = uuid.timeLow; - halUuid->timeMid = uuid.timeMid; - halUuid->timeHiAndVersion = uuid.versionAndTimeHigh; - halUuid->clockSeq = uuid.variantAndClockSeqHigh; - memcpy(halUuid->node, uuid.node.data(), uuid.node.size()); -} - } // namespace implementation } // namespace CPP_VERSION } // namespace common diff --git a/audio/common/all-versions/default/HidlUtils.h b/audio/common/all-versions/default/HidlUtils.h index ef6dee3706..20fddef1ab 100644 --- a/audio/common/all-versions/default/HidlUtils.h +++ b/audio/common/all-versions/default/HidlUtils.h @@ -66,8 +66,6 @@ class HidlUtils { const hidl_vec& configs); static void audioPortFromHal(const struct audio_port& halPort, AudioPort* port); static void audioPortToHal(const AudioPort& port, struct audio_port* halPort); - static void uuidFromHal(const audio_uuid_t& halUuid, Uuid* uuid); - static void uuidToHal(const Uuid& uuid, audio_uuid_t* halUuid); }; } // namespace implementation diff --git a/audio/common/all-versions/default/UuidUtils.cpp b/audio/common/all-versions/default/UuidUtils.cpp new file mode 100644 index 0000000000..85edc7b2f4 --- /dev/null +++ b/audio/common/all-versions/default/UuidUtils.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "UuidUtils.h" + +#include +#include + +namespace android { +namespace hardware { +namespace audio { +namespace common { +namespace CPP_VERSION { +namespace implementation { + +void UuidUtils::uuidFromHal(const audio_uuid_t& halUuid, Uuid* uuid) { + uuid->timeLow = halUuid.timeLow; + uuid->timeMid = halUuid.timeMid; + uuid->versionAndTimeHigh = halUuid.timeHiAndVersion; + uuid->variantAndClockSeqHigh = halUuid.clockSeq; + memcpy(uuid->node.data(), halUuid.node, uuid->node.size()); +} + +void UuidUtils::uuidToHal(const Uuid& uuid, audio_uuid_t* halUuid) { + halUuid->timeLow = uuid.timeLow; + halUuid->timeMid = uuid.timeMid; + halUuid->timeHiAndVersion = uuid.versionAndTimeHigh; + halUuid->clockSeq = uuid.variantAndClockSeqHigh; + memcpy(halUuid->node, uuid.node.data(), uuid.node.size()); +} + +} // namespace implementation +} // namespace CPP_VERSION +} // namespace common +} // namespace audio +} // namespace hardware +} // namespace android diff --git a/audio/common/all-versions/default/UuidUtils.h b/audio/common/all-versions/default/UuidUtils.h new file mode 100644 index 0000000000..38db48a730 --- /dev/null +++ b/audio/common/all-versions/default/UuidUtils.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef android_hardware_audio_Uuid_Utils_H_ +#define android_hardware_audio_Uuid_Utils_H_ + +// clang-format off +#include PATH(android/hardware/audio/common/FILE_VERSION/types.h) +// clang-format on + +#include + +using ::android::hardware::hidl_vec; + +namespace android { +namespace hardware { +namespace audio { +namespace common { +namespace CPP_VERSION { +namespace implementation { + +using namespace ::android::hardware::audio::common::CPP_VERSION; + +class UuidUtils { + public: + static void uuidFromHal(const audio_uuid_t& halUuid, Uuid* uuid); + static void uuidToHal(const Uuid& uuid, audio_uuid_t* halUuid); +}; + +} // namespace implementation +} // namespace CPP_VERSION +} // namespace common +} // namespace audio +} // namespace hardware +} // namespace android + +#endif // android_hardware_audio_Uuid_Utils_H_ diff --git a/audio/effect/all-versions/default/Conversions.cpp b/audio/effect/all-versions/default/Conversions.cpp index b1c0b0dc13..0cc8767e8d 100644 --- a/audio/effect/all-versions/default/Conversions.cpp +++ b/audio/effect/all-versions/default/Conversions.cpp @@ -15,7 +15,7 @@ */ #include "Conversions.h" -#include "HidlUtils.h" +#include "UuidUtils.h" #include #include @@ -31,12 +31,12 @@ namespace effect { namespace CPP_VERSION { namespace implementation { -using ::android::hardware::audio::common::CPP_VERSION::implementation::HidlUtils; +using ::android::hardware::audio::common::CPP_VERSION::implementation::UuidUtils; void effectDescriptorFromHal(const effect_descriptor_t& halDescriptor, EffectDescriptor* descriptor) { - HidlUtils::uuidFromHal(halDescriptor.type, &descriptor->type); - HidlUtils::uuidFromHal(halDescriptor.uuid, &descriptor->uuid); + UuidUtils::uuidFromHal(halDescriptor.type, &descriptor->type); + UuidUtils::uuidFromHal(halDescriptor.uuid, &descriptor->uuid); descriptor->flags = EnumBitfield(halDescriptor.flags); descriptor->cpuLoad = halDescriptor.cpuLoad; descriptor->memoryUsage = halDescriptor.memoryUsage; diff --git a/audio/effect/all-versions/default/EffectsFactory.cpp b/audio/effect/all-versions/default/EffectsFactory.cpp index acce7deaad..b265d3d921 100644 --- a/audio/effect/all-versions/default/EffectsFactory.cpp +++ b/audio/effect/all-versions/default/EffectsFactory.cpp @@ -24,10 +24,10 @@ #include "Effect.h" #include "EnvironmentalReverbEffect.h" #include "EqualizerEffect.h" -#include "HidlUtils.h" #include "LoudnessEnhancerEffect.h" #include "NoiseSuppressionEffect.h" #include "PresetReverbEffect.h" +#include "UuidUtils.h" #include "VirtualizerEffect.h" #include "VisualizerEffect.h" #include "common/all-versions/default/EffectMap.h" @@ -53,7 +53,7 @@ namespace effect { namespace CPP_VERSION { namespace implementation { -using ::android::hardware::audio::common::CPP_VERSION::implementation::HidlUtils; +using ::android::hardware::audio::common::CPP_VERSION::implementation::UuidUtils; // static sp EffectsFactory::dispatchEffectInstanceCreation(const effect_descriptor_t& halDescriptor, @@ -135,7 +135,7 @@ exit: Return EffectsFactory::getDescriptor(const Uuid& uuid, getDescriptor_cb _hidl_cb) { effect_uuid_t halUuid; - HidlUtils::uuidToHal(uuid, &halUuid); + UuidUtils::uuidToHal(uuid, &halUuid); effect_descriptor_t halDescriptor; status_t status = EffectGetDescriptor(&halUuid, &halDescriptor); EffectDescriptor descriptor; @@ -170,7 +170,7 @@ Return EffectsFactory::createEffect(const Uuid& uuid, int32_t session, int Return EffectsFactory::createEffectImpl(const Uuid& uuid, int32_t session, int32_t ioHandle, int32_t device, createEffect_cb _hidl_cb) { effect_uuid_t halUuid; - HidlUtils::uuidToHal(uuid, &halUuid); + UuidUtils::uuidToHal(uuid, &halUuid); effect_handle_t handle; Result retval(Result::OK); status_t status;