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
This commit is contained in:
Mikhail Naganov
2020-10-29 12:37:00 -07:00
parent ba59ee15d6
commit 95e4fe64de
7 changed files with 109 additions and 26 deletions

View File

@@ -46,6 +46,7 @@ cc_defaults {
vendor_available: true,
srcs: [
"HidlUtils.cpp",
"UuidUtils.cpp",
],
export_include_dirs: ["."],

View File

@@ -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

View File

@@ -66,8 +66,6 @@ class HidlUtils {
const hidl_vec<AudioPortConfig>& 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

View File

@@ -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 <common/all-versions/VersionUtils.h>
#include <string.h>
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

View File

@@ -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 <system/audio.h>
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_

View File

@@ -15,7 +15,7 @@
*/
#include "Conversions.h"
#include "HidlUtils.h"
#include "UuidUtils.h"
#include <memory.h>
#include <stdio.h>
@@ -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<EffectFlags>(halDescriptor.flags);
descriptor->cpuLoad = halDescriptor.cpuLoad;
descriptor->memoryUsage = halDescriptor.memoryUsage;

View File

@@ -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<IEffect> EffectsFactory::dispatchEffectInstanceCreation(const effect_descriptor_t& halDescriptor,
@@ -135,7 +135,7 @@ exit:
Return<void> 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<void> EffectsFactory::createEffect(const Uuid& uuid, int32_t session, int
Return<void> 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;