1 /*
2  * Copyright (C) 2019 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 <media/AudioDeviceTypeAddr.h>
18 
19 namespace android {
20 
getAddress() const21 const char* AudioDeviceTypeAddr::getAddress() const {
22     return mAddress.c_str();
23 }
24 
equals(const AudioDeviceTypeAddr & other) const25 bool AudioDeviceTypeAddr::equals(const AudioDeviceTypeAddr& other) const {
26     return mType == other.mType && mAddress == other.mAddress;
27 }
28 
operator <(const AudioDeviceTypeAddr & other) const29 bool AudioDeviceTypeAddr::operator<(const AudioDeviceTypeAddr& other) const {
30     if (mType < other.mType)  return true;
31     if (mType > other.mType)  return false;
32 
33     if (mAddress < other.mAddress)  return true;
34     // if (mAddress > other.mAddress)  return false;
35 
36     return false;
37 }
38 
reset()39 void AudioDeviceTypeAddr::reset() {
40     mType = AUDIO_DEVICE_NONE;
41     mAddress = "";
42 }
43 
readFromParcel(const Parcel * parcel)44 status_t AudioDeviceTypeAddr::readFromParcel(const Parcel *parcel) {
45     status_t status;
46     if ((status = parcel->readUint32(&mType)) != NO_ERROR) return status;
47     status = parcel->readUtf8FromUtf16(&mAddress);
48     return status;
49 }
50 
writeToParcel(Parcel * parcel) const51 status_t AudioDeviceTypeAddr::writeToParcel(Parcel *parcel) const {
52     status_t status;
53     if ((status = parcel->writeUint32(mType)) != NO_ERROR) return status;
54     status = parcel->writeUtf8AsUtf16(mAddress);
55     return status;
56 }
57 
58 
getAudioDeviceTypes(const AudioDeviceTypeAddrVector & deviceTypeAddrs)59 DeviceTypeSet getAudioDeviceTypes(const AudioDeviceTypeAddrVector& deviceTypeAddrs) {
60     DeviceTypeSet deviceTypes;
61     for (const auto& deviceTypeAddr : deviceTypeAddrs) {
62         deviceTypes.insert(deviceTypeAddr.mType);
63     }
64     return deviceTypes;
65 }
66 
67 }