blob: 6c4c94d4156f007b6fc91d11c7957e2353069db0 [file] [log] [blame]
Mikhail Naganov95e4fe62020-10-29 12:37:00 -07001/*
2 * Copyright (C) 2020 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#include "UuidUtils.h"
18
19#include <common/all-versions/VersionUtils.h>
20#include <string.h>
21
22namespace android {
23namespace hardware {
24namespace audio {
25namespace common {
26namespace CPP_VERSION {
27namespace implementation {
28
29void UuidUtils::uuidFromHal(const audio_uuid_t& halUuid, Uuid* uuid) {
30 uuid->timeLow = halUuid.timeLow;
31 uuid->timeMid = halUuid.timeMid;
32 uuid->versionAndTimeHigh = halUuid.timeHiAndVersion;
33 uuid->variantAndClockSeqHigh = halUuid.clockSeq;
34 memcpy(uuid->node.data(), halUuid.node, uuid->node.size());
35}
36
37void UuidUtils::uuidToHal(const Uuid& uuid, audio_uuid_t* halUuid) {
38 halUuid->timeLow = uuid.timeLow;
39 halUuid->timeMid = uuid.timeMid;
40 halUuid->timeHiAndVersion = uuid.versionAndTimeHigh;
41 halUuid->clockSeq = uuid.variantAndClockSeqHigh;
42 memcpy(halUuid->node, uuid.node.data(), uuid.node.size());
43}
44
Mikhail Naganov5ec48c22021-01-15 19:05:04 +000045std::string UuidUtils::uuidToString(const audio_uuid_t& halUuid) {
46 char str[64];
47 snprintf(str, sizeof(str), "%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x", halUuid.timeLow,
48 halUuid.timeMid, halUuid.timeHiAndVersion, halUuid.clockSeq, halUuid.node[0],
49 halUuid.node[1], halUuid.node[2], halUuid.node[3], halUuid.node[4], halUuid.node[5]);
50 return str;
51}
52
Mikhail Naganov95e4fe62020-10-29 12:37:00 -070053} // namespace implementation
54} // namespace CPP_VERSION
55} // namespace common
56} // namespace audio
57} // namespace hardware
58} // namespace android