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