sdp_logging_helper.h 4.2 KB

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