1 /*
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 
22 namespace android {
23 namespace hardware {
24 namespace audio {
25 namespace common {
26 namespace CPP_VERSION {
27 namespace implementation {
28 
uuidFromHal(const audio_uuid_t & halUuid,Uuid * uuid)29 void 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 
uuidToHal(const Uuid & uuid,audio_uuid_t * halUuid)37 void 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 
uuidToString(const audio_uuid_t & halUuid)45 std::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 
53 }  // namespace implementation
54 }  // namespace CPP_VERSION
55 }  // namespace common
56 }  // namespace audio
57 }  // namespace hardware
58 }  // namespace android
59