logging_helpers.cc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //
  2. // Copyright 2015 Google, Inc.
  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. #include "logging_helpers.h"
  17. #include <string.h>
  18. #include <string>
  19. #define CASE_RETURN_TEXT(code) \
  20. case code: \
  21. return #code
  22. const char* BtAvConnectionStateText(const btav_connection_state_t state) {
  23. switch (state) {
  24. CASE_RETURN_TEXT(BTAV_CONNECTION_STATE_DISCONNECTED);
  25. CASE_RETURN_TEXT(BTAV_CONNECTION_STATE_CONNECTING);
  26. CASE_RETURN_TEXT(BTAV_CONNECTION_STATE_CONNECTED);
  27. CASE_RETURN_TEXT(BTAV_CONNECTION_STATE_DISCONNECTING);
  28. default:
  29. return "Invalid AV connection state";
  30. }
  31. }
  32. const char* BtAvAudioStateText(const btav_audio_state_t state) {
  33. switch (state) {
  34. CASE_RETURN_TEXT(BTAV_AUDIO_STATE_REMOTE_SUSPEND);
  35. CASE_RETURN_TEXT(BTAV_AUDIO_STATE_STOPPED);
  36. CASE_RETURN_TEXT(BTAV_AUDIO_STATE_STARTED);
  37. default:
  38. return "Invalid audio state";
  39. }
  40. }
  41. const char* BtTransportText(const btgatt_transport_t t) {
  42. switch (t) {
  43. CASE_RETURN_TEXT(GATT_TRANSPORT_AUTO);
  44. CASE_RETURN_TEXT(GATT_TRANSPORT_BREDR);
  45. CASE_RETURN_TEXT(GATT_TRANSPORT_LE);
  46. default:
  47. return "unknown transport";
  48. }
  49. }
  50. const char* BtStateText(const bt_state_t state) {
  51. switch (state) {
  52. CASE_RETURN_TEXT(BT_STATE_OFF);
  53. CASE_RETURN_TEXT(BT_STATE_ON);
  54. default:
  55. return "unknown state code";
  56. }
  57. }
  58. const char* BtDiscoveryStateText(const bt_discovery_state_t state) {
  59. switch (state) {
  60. CASE_RETURN_TEXT(BT_DISCOVERY_STOPPED);
  61. CASE_RETURN_TEXT(BT_DISCOVERY_STARTED);
  62. default:
  63. return "unknown discovery state code";
  64. }
  65. }
  66. const char* BtScanModeText(const bt_scan_mode_t mode) {
  67. switch (mode) {
  68. CASE_RETURN_TEXT(BT_SCAN_MODE_NONE);
  69. CASE_RETURN_TEXT(BT_SCAN_MODE_CONNECTABLE);
  70. CASE_RETURN_TEXT(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
  71. default:
  72. return "unknown scan mode";
  73. }
  74. }
  75. const char* BtStatusText(const bt_status_t status) {
  76. switch (status) {
  77. CASE_RETURN_TEXT(BT_STATUS_SUCCESS);
  78. CASE_RETURN_TEXT(BT_STATUS_FAIL);
  79. CASE_RETURN_TEXT(BT_STATUS_NOT_READY);
  80. CASE_RETURN_TEXT(BT_STATUS_NOMEM);
  81. CASE_RETURN_TEXT(BT_STATUS_DONE);
  82. CASE_RETURN_TEXT(BT_STATUS_BUSY);
  83. CASE_RETURN_TEXT(BT_STATUS_UNSUPPORTED);
  84. CASE_RETURN_TEXT(BT_STATUS_PARM_INVALID);
  85. CASE_RETURN_TEXT(BT_STATUS_UNHANDLED);
  86. CASE_RETURN_TEXT(BT_STATUS_AUTH_FAILURE);
  87. CASE_RETURN_TEXT(BT_STATUS_RMT_DEV_DOWN);
  88. CASE_RETURN_TEXT(BT_STATUS_AUTH_REJECTED);
  89. default:
  90. return "unknown status code";
  91. }
  92. }
  93. const char* BtPropertyText(const bt_property_type_t prop) {
  94. switch (prop) {
  95. CASE_RETURN_TEXT(BT_PROPERTY_BDNAME);
  96. CASE_RETURN_TEXT(BT_PROPERTY_BDADDR);
  97. CASE_RETURN_TEXT(BT_PROPERTY_UUIDS);
  98. CASE_RETURN_TEXT(BT_PROPERTY_CLASS_OF_DEVICE);
  99. CASE_RETURN_TEXT(BT_PROPERTY_TYPE_OF_DEVICE);
  100. CASE_RETURN_TEXT(BT_PROPERTY_SERVICE_RECORD);
  101. CASE_RETURN_TEXT(BT_PROPERTY_ADAPTER_SCAN_MODE);
  102. CASE_RETURN_TEXT(BT_PROPERTY_ADAPTER_BONDED_DEVICES);
  103. CASE_RETURN_TEXT(BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT);
  104. CASE_RETURN_TEXT(BT_PROPERTY_REMOTE_FRIENDLY_NAME);
  105. CASE_RETURN_TEXT(BT_PROPERTY_REMOTE_RSSI);
  106. CASE_RETURN_TEXT(BT_PROPERTY_REMOTE_VERSION_INFO);
  107. CASE_RETURN_TEXT(BT_PROPERTY_LOCAL_LE_FEATURES);
  108. CASE_RETURN_TEXT(BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP);
  109. default:
  110. return "Invalid property";
  111. }
  112. }
  113. const char* BtEventText(const bt_cb_thread_evt evt) {
  114. switch (evt) {
  115. CASE_RETURN_TEXT(ASSOCIATE_JVM);
  116. CASE_RETURN_TEXT(DISASSOCIATE_JVM);
  117. default:
  118. return "unknown state code";
  119. }
  120. }
  121. const char* BtAclText(const bt_acl_state_t code) {
  122. switch (code) {
  123. CASE_RETURN_TEXT(BT_ACL_STATE_CONNECTED);
  124. CASE_RETURN_TEXT(BT_ACL_STATE_DISCONNECTED);
  125. default:
  126. return "unknown ACL code";
  127. }
  128. }
  129. std::string BtAddrString(const RawAddress* addr) {
  130. char buffer[20];
  131. snprintf(buffer, sizeof(buffer), "%02X:%02X:%02X:%02X:%02X:%02X",
  132. addr->address[0], addr->address[1], addr->address[2],
  133. addr->address[3], addr->address[4], addr->address[5]);
  134. return std::string(buffer);
  135. }