1*4d7e907cSAndroid Build Coastguard Worker /*
2*4d7e907cSAndroid Build Coastguard Worker * Copyright (C) 2020 The Android Open Source Project
3*4d7e907cSAndroid Build Coastguard Worker *
4*4d7e907cSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*4d7e907cSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*4d7e907cSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*4d7e907cSAndroid Build Coastguard Worker *
8*4d7e907cSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*4d7e907cSAndroid Build Coastguard Worker *
10*4d7e907cSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*4d7e907cSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*4d7e907cSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*4d7e907cSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*4d7e907cSAndroid Build Coastguard Worker * limitations under the License.
15*4d7e907cSAndroid Build Coastguard Worker */
16*4d7e907cSAndroid Build Coastguard Worker
17*4d7e907cSAndroid Build Coastguard Worker #include "UuidUtils.h"
18*4d7e907cSAndroid Build Coastguard Worker
19*4d7e907cSAndroid Build Coastguard Worker #include <common/all-versions/VersionUtils.h>
20*4d7e907cSAndroid Build Coastguard Worker #include <string.h>
21*4d7e907cSAndroid Build Coastguard Worker
22*4d7e907cSAndroid Build Coastguard Worker namespace android {
23*4d7e907cSAndroid Build Coastguard Worker namespace hardware {
24*4d7e907cSAndroid Build Coastguard Worker namespace audio {
25*4d7e907cSAndroid Build Coastguard Worker namespace common {
26*4d7e907cSAndroid Build Coastguard Worker namespace CPP_VERSION {
27*4d7e907cSAndroid Build Coastguard Worker namespace implementation {
28*4d7e907cSAndroid Build Coastguard Worker
uuidFromHal(const audio_uuid_t & halUuid,Uuid * uuid)29*4d7e907cSAndroid Build Coastguard Worker void UuidUtils::uuidFromHal(const audio_uuid_t& halUuid, Uuid* uuid) {
30*4d7e907cSAndroid Build Coastguard Worker uuid->timeLow = halUuid.timeLow;
31*4d7e907cSAndroid Build Coastguard Worker uuid->timeMid = halUuid.timeMid;
32*4d7e907cSAndroid Build Coastguard Worker uuid->versionAndTimeHigh = halUuid.timeHiAndVersion;
33*4d7e907cSAndroid Build Coastguard Worker uuid->variantAndClockSeqHigh = halUuid.clockSeq;
34*4d7e907cSAndroid Build Coastguard Worker memcpy(uuid->node.data(), halUuid.node, uuid->node.size());
35*4d7e907cSAndroid Build Coastguard Worker }
36*4d7e907cSAndroid Build Coastguard Worker
uuidToHal(const Uuid & uuid,audio_uuid_t * halUuid)37*4d7e907cSAndroid Build Coastguard Worker void UuidUtils::uuidToHal(const Uuid& uuid, audio_uuid_t* halUuid) {
38*4d7e907cSAndroid Build Coastguard Worker halUuid->timeLow = uuid.timeLow;
39*4d7e907cSAndroid Build Coastguard Worker halUuid->timeMid = uuid.timeMid;
40*4d7e907cSAndroid Build Coastguard Worker halUuid->timeHiAndVersion = uuid.versionAndTimeHigh;
41*4d7e907cSAndroid Build Coastguard Worker halUuid->clockSeq = uuid.variantAndClockSeqHigh;
42*4d7e907cSAndroid Build Coastguard Worker memcpy(halUuid->node, uuid.node.data(), uuid.node.size());
43*4d7e907cSAndroid Build Coastguard Worker }
44*4d7e907cSAndroid Build Coastguard Worker
uuidToString(const audio_uuid_t & halUuid)45*4d7e907cSAndroid Build Coastguard Worker std::string UuidUtils::uuidToString(const audio_uuid_t& halUuid) {
46*4d7e907cSAndroid Build Coastguard Worker char str[64];
47*4d7e907cSAndroid Build Coastguard Worker snprintf(str, sizeof(str), "%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x", halUuid.timeLow,
48*4d7e907cSAndroid Build Coastguard Worker halUuid.timeMid, halUuid.timeHiAndVersion, halUuid.clockSeq, halUuid.node[0],
49*4d7e907cSAndroid Build Coastguard Worker halUuid.node[1], halUuid.node[2], halUuid.node[3], halUuid.node[4], halUuid.node[5]);
50*4d7e907cSAndroid Build Coastguard Worker return str;
51*4d7e907cSAndroid Build Coastguard Worker }
52*4d7e907cSAndroid Build Coastguard Worker
53*4d7e907cSAndroid Build Coastguard Worker } // namespace implementation
54*4d7e907cSAndroid Build Coastguard Worker } // namespace CPP_VERSION
55*4d7e907cSAndroid Build Coastguard Worker } // namespace common
56*4d7e907cSAndroid Build Coastguard Worker } // namespace audio
57*4d7e907cSAndroid Build Coastguard Worker } // namespace hardware
58*4d7e907cSAndroid Build Coastguard Worker } // namespace android
59