1 /* 2 * Copyright 2018 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 #pragma once 18 19 #include <iomanip> 20 #include <iostream> 21 #include <sstream> 22 #include <string> 23 #include <type_traits> 24 25 #include "bt_trace.h" 26 #include "sdp_common.h" 27 28 namespace bluetooth { 29 namespace sdp { 30 31 #ifndef CASE_RETURN_TEXT 32 #define CASE_RETURN_TEXT(code) \ 33 case code: \ 34 return #code 35 #endif 36 PduIdText(const PduId & id)37inline std::string PduIdText(const PduId& id) { 38 switch (id) { 39 CASE_RETURN_TEXT(PduId::RESERVED); 40 CASE_RETURN_TEXT(PduId::ERROR); 41 CASE_RETURN_TEXT(PduId::SERVICE_SEARCH_REQUEST); 42 CASE_RETURN_TEXT(PduId::SERVICE_SEARCH_RESPONSE); 43 CASE_RETURN_TEXT(PduId::SERVICE_ATTRIBUTE_REQUEST); 44 CASE_RETURN_TEXT(PduId::SERVICE_ATTRIBUTE_RESPONSE); 45 CASE_RETURN_TEXT(PduId::SERVICE_SEARCH_ATTRIBUTE_REQUEST); 46 CASE_RETURN_TEXT(PduId::SERVICE_SEARCH_ATTRIBUTE_RESPONSE); 47 default: 48 return "Unknown PduId: " + loghex((uint8_t)id); 49 } 50 } 51 52 inline std::ostream& operator<<(std::ostream& os, const PduId& id) { 53 return os << PduIdText(id); 54 } 55 AttributeIdText(const AttributeId & id)56inline std::string AttributeIdText(const AttributeId& id) { 57 switch (id) { 58 CASE_RETURN_TEXT(AttributeId::SERVICE_RECORD_HANDLE); 59 CASE_RETURN_TEXT(AttributeId::SERVICE_CLASS_ID_LIST); 60 CASE_RETURN_TEXT(AttributeId::SERVICE_RECORD_STATE); 61 CASE_RETURN_TEXT(AttributeId::SERVICE_ID); 62 CASE_RETURN_TEXT(AttributeId::PROTOCOL_DESCRIPTOR_LIST); 63 CASE_RETURN_TEXT(AttributeId::BROWSE_GROUP_LIST); 64 CASE_RETURN_TEXT(AttributeId::LANGUAGE_BASE_ATTRIBUTE_ID_LIST); 65 CASE_RETURN_TEXT(AttributeId::SERVICE_INFO_TIME_TO_LIVE); 66 CASE_RETURN_TEXT(AttributeId::SERVICE_AVAILABILITY); 67 CASE_RETURN_TEXT(AttributeId::PROFILE_DESCRIPTOR_LIST); 68 CASE_RETURN_TEXT(AttributeId::DOCUMENTATION_URL); 69 CASE_RETURN_TEXT(AttributeId::CLIENT_EXECUTABLE_URL); 70 CASE_RETURN_TEXT(AttributeId::ICON_URL); 71 CASE_RETURN_TEXT(AttributeId::ADDITIONAL_PROTOCOL_DESCRIPTOR_LIST); 72 CASE_RETURN_TEXT(AttributeId::VERSION_NUMBER_LIST); 73 CASE_RETURN_TEXT(AttributeId::SERVICE_DATABASE_STATE); 74 default: 75 return "Unknown AttributeId: " + loghex((uint16_t)id); 76 } 77 } 78 79 inline std::ostream& operator<<(std::ostream& os, const AttributeId& id) { 80 return os << AttributeIdText(id); 81 } 82 DataElementTypeText(const DataElementType & type)83inline std::string DataElementTypeText(const DataElementType& type) { 84 switch (type) { 85 CASE_RETURN_TEXT(DataElementType::NIL); 86 CASE_RETURN_TEXT(DataElementType::UNSIGNED_INT); 87 CASE_RETURN_TEXT(DataElementType::SIGNED_INT); 88 CASE_RETURN_TEXT(DataElementType::UUID); 89 CASE_RETURN_TEXT(DataElementType::STRING); 90 CASE_RETURN_TEXT(DataElementType::BOOLEAN); 91 CASE_RETURN_TEXT(DataElementType::DATA_ELEMENT_SEQUENCE); 92 CASE_RETURN_TEXT(DataElementType::DATA_ELEMENT_ALTERNATIVE); 93 CASE_RETURN_TEXT(DataElementType::URL); 94 default: 95 return "Unknown DataElementType: " + loghex((uint8_t)type); 96 } 97 } 98 99 inline std::ostream& operator<<(std::ostream& os, const DataElementType& type) { 100 return os << DataElementTypeText(type); 101 } 102 DataElementSizeText(const DataElementSize & size)103inline std::string DataElementSizeText(const DataElementSize& size) { 104 switch (size) { 105 CASE_RETURN_TEXT(DataElementSize::BYTE1); 106 CASE_RETURN_TEXT(DataElementSize::BYTE2); 107 CASE_RETURN_TEXT(DataElementSize::BYTE4); 108 CASE_RETURN_TEXT(DataElementSize::BYTE8); 109 CASE_RETURN_TEXT(DataElementSize::BYTE16); 110 CASE_RETURN_TEXT(DataElementSize::ADDITIONAL_8BIT); 111 CASE_RETURN_TEXT(DataElementSize::ADDITIONAL_16BIT); 112 CASE_RETURN_TEXT(DataElementSize::ADDITIONAL_32BIT); 113 default: 114 return "Unknown DataElementSize: " + loghex((uint8_t)size); 115 } 116 } 117 118 inline std::ostream& operator<<(std::ostream& os, const DataElementSize& size) { 119 return os << DataElementSizeText(size); 120 } 121 122 } // namespace sdp 123 } // namespace bluetooth 124