blob: f27563deaf501bcf5d71e4c94f284bb30aee1a1a [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
Jakub Pawlowski5b790fe2017-09-18 09:00:20 -07003 * Copyright 1999-2012 Broadcom Corporation
The Android Open Source Project5738f832012-12-12 16:00:35 -08004 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
Chris Mantonaa0f6ec2014-09-24 15:18:41 -070019#pragma once
The Android Open Source Project5738f832012-12-12 16:00:35 -080020
Jack He1f60d2d2016-11-22 12:39:52 -080021#include <stdint.h>
22
Jakub Pawlowski713993d2016-04-21 13:16:45 -070023#ifdef __cplusplus
24extern "C" {
25#endif
26
Sharvil Nanavati06ef2052014-11-06 18:34:06 -080027static const char BTE_LOGMSG_MODULE[] = "bte_logmsg_module";
Zach Johnson9891f322014-09-22 22:11:55 -070028
The Android Open Source Project5738f832012-12-12 16:00:35 -080029/* BTE tracing IDs for debug purposes */
30/* LayerIDs for stack */
Myles Watsonc1e42392016-11-09 09:47:42 -080031#define BTTRC_ID_STK_GKI 1
32#define BTTRC_ID_STK_BTU 2
33#define BTTRC_ID_STK_HCI 3
34#define BTTRC_ID_STK_L2CAP 4
35#define BTTRC_ID_STK_RFCM_MX 5
36#define BTTRC_ID_STK_RFCM_PRT 6
37#define BTTRC_ID_STK_OBEX_C 7
38#define BTTRC_ID_STK_OBEX_S 8
39#define BTTRC_ID_STK_AVCT 9
40#define BTTRC_ID_STK_AVDT 10
41#define BTTRC_ID_STK_AVRC 11
42#define BTTRC_ID_STK_BIC 12
43#define BTTRC_ID_STK_BIS 13
44#define BTTRC_ID_STK_BNEP 14
45#define BTTRC_ID_STK_BPP 15
46#define BTTRC_ID_STK_BTM_ACL 16
47#define BTTRC_ID_STK_BTM_PM 17
48#define BTTRC_ID_STK_BTM_DEV_CTRL 18
49#define BTTRC_ID_STK_BTM_SVC_DSC 19
50#define BTTRC_ID_STK_BTM_INQ 20
51#define BTTRC_ID_STK_BTM_SCO 21
52#define BTTRC_ID_STK_BTM_SEC 22
53#define BTTRC_ID_STK_HID 24
54#define BTTRC_ID_STK_HSP2 25
55#define BTTRC_ID_STK_CTP 26
56#define BTTRC_ID_STK_FTC 27
57#define BTTRC_ID_STK_FTS 28
Myles Watsonc1e42392016-11-09 09:47:42 -080058#define BTTRC_ID_STK_HCRP 31
59#define BTTRC_ID_STK_ICP 32
60#define BTTRC_ID_STK_OPC 33
61#define BTTRC_ID_STK_OPS 34
62#define BTTRC_ID_STK_PAN 35
63#define BTTRC_ID_STK_SAP 36
64#define BTTRC_ID_STK_SDP 37
65#define BTTRC_ID_STK_SLIP 38
66#define BTTRC_ID_STK_SPP 39
67#define BTTRC_ID_STK_TCS 40
68#define BTTRC_ID_STK_VDP 41
Jack Hefb87f562019-01-09 20:47:57 -080069#define BTTRC_ID_STK_MCAP 42 /* OBSOLETE */
70#define BTTRC_ID_STK_GATT 43
Myles Watsonc1e42392016-11-09 09:47:42 -080071#define BTTRC_ID_STK_SMP 44
72#define BTTRC_ID_STK_NFC 45
73#define BTTRC_ID_STK_NCI 46
74#define BTTRC_ID_STK_IDEP 47
75#define BTTRC_ID_STK_NDEP 48
76#define BTTRC_ID_STK_LLCP 49
77#define BTTRC_ID_STK_RW 50
78#define BTTRC_ID_STK_CE 51
79#define BTTRC_ID_STK_SNEP 52
80#define BTTRC_ID_STK_NDEF 53
Hemant Gupta8843cc82014-04-18 12:34:55 +053081#define BTTRC_ID_STK_HIDD 54
The Android Open Source Project5738f832012-12-12 16:00:35 -080082
The Android Open Source Project5738f832012-12-12 16:00:35 -080083/* LayerIDs for BTA */
Myles Watsonc1e42392016-11-09 09:47:42 -080084#define BTTRC_ID_BTA_ACC 55 /* Advanced Camera Client */
85#define BTTRC_ID_BTA_AG 56 /* audio gateway */
86#define BTTRC_ID_BTA_AV 57 /* Advanced audio */
87#define BTTRC_ID_BTA_BIC 58 /* Basic Imaging Client */
88#define BTTRC_ID_BTA_BIS 59 /* Basic Imaging Server */
89#define BTTRC_ID_BTA_BP 60 /* Basic Printing Client */
90#define BTTRC_ID_BTA_CG 61
91#define BTTRC_ID_BTA_CT 62 /* cordless telephony terminal */
92#define BTTRC_ID_BTA_DG 63 /* data gateway */
93#define BTTRC_ID_BTA_DM 64 /* device manager */
94#define BTTRC_ID_BTA_DM_SRCH 65 /* device manager search */
95#define BTTRC_ID_BTA_DM_SEC 66 /* device manager security */
96#define BTTRC_ID_BTA_FM 67
97#define BTTRC_ID_BTA_FTC 68 /* file transfer client */
98#define BTTRC_ID_BTA_FTS 69 /* file transfer server */
99#define BTTRC_ID_BTA_HIDH 70
100#define BTTRC_ID_BTA_HIDD 71
101#define BTTRC_ID_BTA_JV 72
102#define BTTRC_ID_BTA_OPC 73 /* object push client */
103#define BTTRC_ID_BTA_OPS 74 /* object push server */
104#define BTTRC_ID_BTA_PAN 75 /* Personal Area Networking */
105#define BTTRC_ID_BTA_PR 76 /* Printer client */
106#define BTTRC_ID_BTA_SC 77 /* SIM Card Access server */
107#define BTTRC_ID_BTA_SS 78 /* synchronization server */
108#define BTTRC_ID_BTA_SYS 79 /* system manager */
109#define BTTRC_ID_AVDT_SCB 80 /* avdt scb */
110#define BTTRC_ID_AVDT_CCB 81 /* avdt ccb */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800111
Pavlin Radoslavovb2a292b2016-10-14 19:34:48 -0700112/* LayerIDs added for BTL-A. Probably should modify bte_logmsg.cc in future. */
Myles Watsonc1e42392016-11-09 09:47:42 -0800113#define BTTRC_ID_STK_RFCOMM 82
114#define BTTRC_ID_STK_RFCOMM_DATA 83
115#define BTTRC_ID_STK_OBEX 84
116#define BTTRC_ID_STK_A2DP 85
117#define BTTRC_ID_STK_BIP 86
The Android Open Source Project5738f832012-12-12 16:00:35 -0800118
119/* LayerIDs for BT APP */
Myles Watsonc1e42392016-11-09 09:47:42 -0800120#define BTTRC_ID_BTAPP 87
Hemant Gupta8843cc82014-04-18 12:34:55 +0530121/* this is a temporary solution to allow dynamic enable/disable of
122 * BT_PROTOCOL_TRACE */
123#define BTTRC_ID_BT_PROTOCOL 88
Myles Watsonc1e42392016-11-09 09:47:42 -0800124#define BTTRC_ID_MAX_ID BTTRC_ID_BT_PROTOCOL
125#define BTTRC_ID_ALL_LAYERS 0xFF /* all trace layers */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800126
The Android Open Source Project5738f832012-12-12 16:00:35 -0800127/******************************************************************************
Myles Watsona88d1e32016-11-09 09:41:48 -0800128 *
129 * Trace Levels
130 *
131 * The following values may be used for different levels:
132 * BT_TRACE_LEVEL_NONE 0 * No trace messages to be generated
133 * BT_TRACE_LEVEL_ERROR 1 * Error condition trace messages
134 * BT_TRACE_LEVEL_WARNING 2 * Warning condition trace messages
135 * BT_TRACE_LEVEL_API 3 * API traces
136 * BT_TRACE_LEVEL_EVENT 4 * Debug messages for events
137 * BT_TRACE_LEVEL_DEBUG 5 * Debug messages (general)
138 *****************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800139
The Android Open Source Project5738f832012-12-12 16:00:35 -0800140/* Core Stack default trace levels */
141#ifndef HCI_INITIAL_TRACE_LEVEL
Myles Watsonc1e42392016-11-09 09:47:42 -0800142#define HCI_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
The Android Open Source Project5738f832012-12-12 16:00:35 -0800143#endif
144
145#ifndef BTM_INITIAL_TRACE_LEVEL
Myles Watsonc1e42392016-11-09 09:47:42 -0800146#define BTM_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
The Android Open Source Project5738f832012-12-12 16:00:35 -0800147#endif
148
149#ifndef L2CAP_INITIAL_TRACE_LEVEL
Myles Watsonc1e42392016-11-09 09:47:42 -0800150#define L2CAP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
The Android Open Source Project5738f832012-12-12 16:00:35 -0800151#endif
152
The Android Open Source Project5738f832012-12-12 16:00:35 -0800153#ifndef RFCOMM_INITIAL_TRACE_LEVEL
Myles Watsonc1e42392016-11-09 09:47:42 -0800154#define RFCOMM_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
The Android Open Source Project5738f832012-12-12 16:00:35 -0800155#endif
156
The Android Open Source Project5738f832012-12-12 16:00:35 -0800157#ifndef SDP_INITIAL_TRACE_LEVEL
Myles Watsonc1e42392016-11-09 09:47:42 -0800158#define SDP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
The Android Open Source Project5738f832012-12-12 16:00:35 -0800159#endif
160
The Android Open Source Project5738f832012-12-12 16:00:35 -0800161#ifndef BNEP_INITIAL_TRACE_LEVEL
Myles Watsonc1e42392016-11-09 09:47:42 -0800162#define BNEP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
The Android Open Source Project5738f832012-12-12 16:00:35 -0800163#endif
164
165#ifndef PAN_INITIAL_TRACE_LEVEL
Myles Watsonc1e42392016-11-09 09:47:42 -0800166#define PAN_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
The Android Open Source Project5738f832012-12-12 16:00:35 -0800167#endif
168
Pavlin Radoslavovf66f4e92016-10-14 15:14:37 -0700169#ifndef A2DP_INITIAL_TRACE_LEVEL
Myles Watsonc1e42392016-11-09 09:47:42 -0800170#define A2DP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
The Android Open Source Project5738f832012-12-12 16:00:35 -0800171#endif
172
The Android Open Source Project5738f832012-12-12 16:00:35 -0800173#ifndef AVDT_INITIAL_TRACE_LEVEL
Myles Watsonc1e42392016-11-09 09:47:42 -0800174#define AVDT_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
The Android Open Source Project5738f832012-12-12 16:00:35 -0800175#endif
176
177#ifndef AVCT_INITIAL_TRACE_LEVEL
Myles Watsonc1e42392016-11-09 09:47:42 -0800178#define AVCT_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
The Android Open Source Project5738f832012-12-12 16:00:35 -0800179#endif
180
181#ifndef AVRC_INITIAL_TRACE_LEVEL
Myles Watsonc1e42392016-11-09 09:47:42 -0800182#define AVRC_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
The Android Open Source Project5738f832012-12-12 16:00:35 -0800183#endif
184
The Android Open Source Project5738f832012-12-12 16:00:35 -0800185#ifndef HID_INITIAL_TRACE_LEVEL
Myles Watsonc1e42392016-11-09 09:47:42 -0800186#define HID_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
The Android Open Source Project5738f832012-12-12 16:00:35 -0800187#endif
188
The Android Open Source Project5738f832012-12-12 16:00:35 -0800189#ifndef APPL_INITIAL_TRACE_LEVEL
Myles Watsonc1e42392016-11-09 09:47:42 -0800190#define APPL_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
The Android Open Source Project5738f832012-12-12 16:00:35 -0800191#endif
192
The Android Open Source Project5738f832012-12-12 16:00:35 -0800193#ifndef GATT_INITIAL_TRACE_LEVEL
Myles Watsonc1e42392016-11-09 09:47:42 -0800194#define GATT_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
The Android Open Source Project5738f832012-12-12 16:00:35 -0800195#endif
196
197#ifndef SMP_INITIAL_TRACE_LEVEL
Myles Watsonc1e42392016-11-09 09:47:42 -0800198#define SMP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
The Android Open Source Project5738f832012-12-12 16:00:35 -0800199#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -0800200
Myles Watsonc1e42392016-11-09 09:47:42 -0800201#define BT_TRACE(l, t, ...) \
202 LogMsg((TRACE_CTRL_GENERAL | (l) | TRACE_ORG_STACK | (t)), ##__VA_ARGS__)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800203
Hemant Gupta8843cc82014-04-18 12:34:55 +0530204/* Define tracing for the HCI unit */
Myles Watsonc1e42392016-11-09 09:47:42 -0800205#define HCI_TRACE_ERROR(...) \
206 { \
207 if (btu_trace_level >= BT_TRACE_LEVEL_ERROR) \
208 BT_TRACE(TRACE_LAYER_HCI, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
209 }
210#define HCI_TRACE_WARNING(...) \
211 { \
212 if (btu_trace_level >= BT_TRACE_LEVEL_WARNING) \
213 BT_TRACE(TRACE_LAYER_HCI, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
214 }
215#define HCI_TRACE_EVENT(...) \
216 { \
217 if (btu_trace_level >= BT_TRACE_LEVEL_EVENT) \
218 BT_TRACE(TRACE_LAYER_HCI, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
219 }
220#define HCI_TRACE_DEBUG(...) \
221 { \
222 if (btu_trace_level >= BT_TRACE_LEVEL_DEBUG) \
223 BT_TRACE(TRACE_LAYER_HCI, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
224 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800225
Hemant Gupta8843cc82014-04-18 12:34:55 +0530226/* Define tracing for BTM */
Myles Watsonc1e42392016-11-09 09:47:42 -0800227#define BTM_TRACE_ERROR(...) \
228 { \
229 if (btm_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
230 BT_TRACE(TRACE_LAYER_BTM, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
231 }
232#define BTM_TRACE_WARNING(...) \
233 { \
234 if (btm_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
235 BT_TRACE(TRACE_LAYER_BTM, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
236 }
237#define BTM_TRACE_API(...) \
238 { \
239 if (btm_cb.trace_level >= BT_TRACE_LEVEL_API) \
240 BT_TRACE(TRACE_LAYER_BTM, TRACE_TYPE_API, ##__VA_ARGS__); \
241 }
242#define BTM_TRACE_EVENT(...) \
243 { \
244 if (btm_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
245 BT_TRACE(TRACE_LAYER_BTM, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
246 }
247#define BTM_TRACE_DEBUG(...) \
248 { \
249 if (btm_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
250 BT_TRACE(TRACE_LAYER_BTM, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
251 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800252
Hemant Gupta8843cc82014-04-18 12:34:55 +0530253/* Define tracing for the L2CAP unit */
Myles Watsonc1e42392016-11-09 09:47:42 -0800254#define L2CAP_TRACE_ERROR(...) \
255 { \
256 if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_ERROR) \
257 BT_TRACE(TRACE_LAYER_L2CAP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
258 }
259#define L2CAP_TRACE_WARNING(...) \
260 { \
261 if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_WARNING) \
262 BT_TRACE(TRACE_LAYER_L2CAP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
263 }
264#define L2CAP_TRACE_API(...) \
265 { \
266 if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_API) \
267 BT_TRACE(TRACE_LAYER_L2CAP, TRACE_TYPE_API, ##__VA_ARGS__); \
268 }
269#define L2CAP_TRACE_EVENT(...) \
270 { \
271 if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_EVENT) \
272 BT_TRACE(TRACE_LAYER_L2CAP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
273 }
274#define L2CAP_TRACE_DEBUG(...) \
275 { \
276 if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_DEBUG) \
277 BT_TRACE(TRACE_LAYER_L2CAP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
278 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800279
Hemant Gupta8843cc82014-04-18 12:34:55 +0530280/* Define tracing for the SDP unit */
Myles Watsonc1e42392016-11-09 09:47:42 -0800281#define SDP_TRACE_ERROR(...) \
282 { \
283 if (sdp_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
284 BT_TRACE(TRACE_LAYER_SDP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
285 }
286#define SDP_TRACE_WARNING(...) \
287 { \
288 if (sdp_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
289 BT_TRACE(TRACE_LAYER_SDP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
290 }
291#define SDP_TRACE_API(...) \
292 { \
293 if (sdp_cb.trace_level >= BT_TRACE_LEVEL_API) \
294 BT_TRACE(TRACE_LAYER_SDP, TRACE_TYPE_API, ##__VA_ARGS__); \
295 }
296#define SDP_TRACE_EVENT(...) \
297 { \
298 if (sdp_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
299 BT_TRACE(TRACE_LAYER_SDP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
300 }
301#define SDP_TRACE_DEBUG(...) \
302 { \
303 if (sdp_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
304 BT_TRACE(TRACE_LAYER_SDP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
305 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800306
Hemant Gupta8843cc82014-04-18 12:34:55 +0530307/* Define tracing for the RFCOMM unit */
Myles Watsonc1e42392016-11-09 09:47:42 -0800308#define RFCOMM_TRACE_ERROR(...) \
309 { \
310 if (rfc_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
311 BT_TRACE(TRACE_LAYER_RFCOMM, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
312 }
313#define RFCOMM_TRACE_WARNING(...) \
314 { \
315 if (rfc_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
316 BT_TRACE(TRACE_LAYER_RFCOMM, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
317 }
318#define RFCOMM_TRACE_API(...) \
319 { \
320 if (rfc_cb.trace_level >= BT_TRACE_LEVEL_API) \
321 BT_TRACE(TRACE_LAYER_RFCOMM, TRACE_TYPE_API, ##__VA_ARGS__); \
322 }
323#define RFCOMM_TRACE_EVENT(...) \
324 { \
325 if (rfc_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
326 BT_TRACE(TRACE_LAYER_RFCOMM, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
327 }
328#define RFCOMM_TRACE_DEBUG(...) \
329 { \
330 if (rfc_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
331 BT_TRACE(TRACE_LAYER_RFCOMM, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
332 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800333
The Android Open Source Project5738f832012-12-12 16:00:35 -0800334/* define traces for HID Host */
Myles Watsonc1e42392016-11-09 09:47:42 -0800335#define HIDH_TRACE_ERROR(...) \
336 { \
337 if (hh_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
338 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
339 }
340#define HIDH_TRACE_WARNING(...) \
341 { \
342 if (hh_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
343 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
344 }
345#define HIDH_TRACE_API(...) \
346 { \
347 if (hh_cb.trace_level >= BT_TRACE_LEVEL_API) \
348 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_API, ##__VA_ARGS__); \
349 }
350#define HIDH_TRACE_EVENT(...) \
351 { \
352 if (hh_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
353 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
354 }
355#define HIDH_TRACE_DEBUG(...) \
356 { \
357 if (hh_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
358 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
359 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800360
Hemant Gupta8843cc82014-04-18 12:34:55 +0530361/* define traces for HID Device */
362#define HIDD_TRACE_ERROR(...) \
363 { \
364 if (hd_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
365 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
366 }
367#define HIDD_TRACE_WARNING(...) \
368 { \
369 if (hd_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
370 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
371 }
372#define HIDD_TRACE_API(...) \
373 { \
374 if (hd_cb.trace_level >= BT_TRACE_LEVEL_API) \
375 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_API, ##__VA_ARGS__); \
376 }
377#define HIDD_TRACE_EVENT(...) \
378 { \
379 if (hd_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
380 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
381 }
382#define HIDD_TRACE_DEBUG(...) \
383 { \
384 if (hd_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
385 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
386 }
387#define HIDD_TRACE_VERBOSE(...) \
388 { \
389 if (hd_cb.trace_level >= BT_TRACE_LEVEL_VERBOSE) \
390 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
391 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800392
Hemant Gupta8843cc82014-04-18 12:34:55 +0530393/* define traces for BNEP */
Myles Watsonc1e42392016-11-09 09:47:42 -0800394#define BNEP_TRACE_ERROR(...) \
395 { \
396 if (bnep_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
397 BT_TRACE(TRACE_LAYER_BNEP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
398 }
399#define BNEP_TRACE_WARNING(...) \
400 { \
401 if (bnep_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
402 BT_TRACE(TRACE_LAYER_BNEP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
403 }
404#define BNEP_TRACE_API(...) \
405 { \
406 if (bnep_cb.trace_level >= BT_TRACE_LEVEL_API) \
407 BT_TRACE(TRACE_LAYER_BNEP, TRACE_TYPE_API, ##__VA_ARGS__); \
408 }
409#define BNEP_TRACE_EVENT(...) \
410 { \
411 if (bnep_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
412 BT_TRACE(TRACE_LAYER_BNEP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
413 }
414#define BNEP_TRACE_DEBUG(...) \
415 { \
416 if (bnep_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
417 BT_TRACE(TRACE_LAYER_BNEP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
418 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800419
420/* define traces for PAN */
Myles Watsonc1e42392016-11-09 09:47:42 -0800421#define PAN_TRACE_ERROR(...) \
422 { \
423 if (pan_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
424 BT_TRACE(TRACE_LAYER_PAN, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
425 }
426#define PAN_TRACE_WARNING(...) \
427 { \
428 if (pan_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
429 BT_TRACE(TRACE_LAYER_PAN, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
430 }
431#define PAN_TRACE_API(...) \
432 { \
433 if (pan_cb.trace_level >= BT_TRACE_LEVEL_API) \
434 BT_TRACE(TRACE_LAYER_PAN, TRACE_TYPE_API, ##__VA_ARGS__); \
435 }
436#define PAN_TRACE_EVENT(...) \
437 { \
438 if (pan_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
439 BT_TRACE(TRACE_LAYER_PAN, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
440 }
441#define PAN_TRACE_DEBUG(...) \
442 { \
443 if (pan_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
444 BT_TRACE(TRACE_LAYER_PAN, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
445 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800446
Hemant Gupta8843cc82014-04-18 12:34:55 +0530447/* Define tracing for the A2DP profile */
Myles Watsonc1e42392016-11-09 09:47:42 -0800448#define A2DP_TRACE_ERROR(...) \
449 { \
450 if (a2dp_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
451 BT_TRACE(TRACE_LAYER_A2DP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
452 }
453#define A2DP_TRACE_WARNING(...) \
454 { \
455 if (a2dp_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
456 BT_TRACE(TRACE_LAYER_A2DP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
457 }
458#define A2DP_TRACE_EVENT(...) \
459 { \
460 if (a2dp_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
461 BT_TRACE(TRACE_LAYER_A2DP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
462 }
463#define A2DP_TRACE_DEBUG(...) \
464 { \
465 if (a2dp_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
466 BT_TRACE(TRACE_LAYER_A2DP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
467 }
468#define A2DP_TRACE_API(...) \
469 { \
470 if (a2dp_cb.trace_level >= BT_TRACE_LEVEL_API) \
471 BT_TRACE(TRACE_LAYER_A2DP, TRACE_TYPE_API, ##__VA_ARGS__); \
472 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800473
Hemant Gupta8843cc82014-04-18 12:34:55 +0530474/* AVDTP */
Myles Watsonc1e42392016-11-09 09:47:42 -0800475#define AVDT_TRACE_ERROR(...) \
476 { \
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800477 if (avdtp_cb.TraceLevel() >= BT_TRACE_LEVEL_ERROR) \
Myles Watsonc1e42392016-11-09 09:47:42 -0800478 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
479 }
480#define AVDT_TRACE_WARNING(...) \
481 { \
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800482 if (avdtp_cb.TraceLevel() >= BT_TRACE_LEVEL_WARNING) \
Myles Watsonc1e42392016-11-09 09:47:42 -0800483 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
484 }
485#define AVDT_TRACE_EVENT(...) \
486 { \
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800487 if (avdtp_cb.TraceLevel() >= BT_TRACE_LEVEL_EVENT) \
Myles Watsonc1e42392016-11-09 09:47:42 -0800488 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
489 }
490#define AVDT_TRACE_DEBUG(...) \
491 { \
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800492 if (avdtp_cb.TraceLevel() >= BT_TRACE_LEVEL_DEBUG) \
Myles Watsonc1e42392016-11-09 09:47:42 -0800493 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
494 }
495#define AVDT_TRACE_API(...) \
496 { \
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800497 if (avdtp_cb.TraceLevel() >= BT_TRACE_LEVEL_API) \
Myles Watsonc1e42392016-11-09 09:47:42 -0800498 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_API, ##__VA_ARGS__); \
499 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800500
Hemant Gupta8843cc82014-04-18 12:34:55 +0530501/* Define tracing for the AVCTP protocol */
Myles Watsonc1e42392016-11-09 09:47:42 -0800502#define AVCT_TRACE_ERROR(...) \
503 { \
504 if (avct_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
505 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
506 }
507#define AVCT_TRACE_WARNING(...) \
508 { \
509 if (avct_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
510 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
511 }
512#define AVCT_TRACE_EVENT(...) \
513 { \
514 if (avct_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
515 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
516 }
517#define AVCT_TRACE_DEBUG(...) \
518 { \
519 if (avct_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
520 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
521 }
522#define AVCT_TRACE_API(...) \
523 { \
524 if (avct_cb.trace_level >= BT_TRACE_LEVEL_API) \
525 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_API, ##__VA_ARGS__); \
526 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800527
Hemant Gupta8843cc82014-04-18 12:34:55 +0530528/* Define tracing for the AVRCP profile */
Myles Watsonc1e42392016-11-09 09:47:42 -0800529#define AVRC_TRACE_ERROR(...) \
530 { \
531 if (avrc_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
532 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
533 }
534#define AVRC_TRACE_WARNING(...) \
535 { \
536 if (avrc_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
537 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
538 }
539#define AVRC_TRACE_EVENT(...) \
540 { \
541 if (avrc_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
542 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
543 }
544#define AVRC_TRACE_DEBUG(...) \
545 { \
546 if (avrc_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
547 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
548 }
549#define AVRC_TRACE_API(...) \
550 { \
551 if (avrc_cb.trace_level >= BT_TRACE_LEVEL_API) \
552 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_API, ##__VA_ARGS__); \
553 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800554
Hemant Gupta8843cc82014-04-18 12:34:55 +0530555/* Define tracing for the SMP unit */
Myles Watsonc1e42392016-11-09 09:47:42 -0800556#define SMP_TRACE_ERROR(...) \
557 { \
558 if (smp_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
559 BT_TRACE(TRACE_LAYER_SMP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
560 }
561#define SMP_TRACE_WARNING(...) \
562 { \
563 if (smp_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
564 BT_TRACE(TRACE_LAYER_SMP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
565 }
566#define SMP_TRACE_API(...) \
567 { \
568 if (smp_cb.trace_level >= BT_TRACE_LEVEL_API) \
569 BT_TRACE(TRACE_LAYER_SMP, TRACE_TYPE_API, ##__VA_ARGS__); \
570 }
571#define SMP_TRACE_EVENT(...) \
572 { \
573 if (smp_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
574 BT_TRACE(TRACE_LAYER_SMP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
575 }
576#define SMP_TRACE_DEBUG(...) \
577 { \
578 if (smp_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
579 BT_TRACE(TRACE_LAYER_SMP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
580 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800581
Marie Janssend19e0782016-07-15 12:48:27 -0700582extern uint8_t btif_trace_level;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800583
584/* define traces for application */
Myles Watsonc1e42392016-11-09 09:47:42 -0800585#define BTIF_TRACE_ERROR(...) \
586 { \
587 if (btif_trace_level >= BT_TRACE_LEVEL_ERROR) \
588 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
589 TRACE_TYPE_ERROR, \
590 ##__VA_ARGS__); \
591 }
592#define BTIF_TRACE_WARNING(...) \
593 { \
594 if (btif_trace_level >= BT_TRACE_LEVEL_WARNING) \
595 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
596 TRACE_TYPE_WARNING, \
597 ##__VA_ARGS__); \
598 }
599#define BTIF_TRACE_API(...) \
600 { \
601 if (btif_trace_level >= BT_TRACE_LEVEL_API) \
602 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
603 TRACE_TYPE_API, \
604 ##__VA_ARGS__); \
605 }
606#define BTIF_TRACE_EVENT(...) \
607 { \
608 if (btif_trace_level >= BT_TRACE_LEVEL_EVENT) \
609 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
610 TRACE_TYPE_EVENT, \
611 ##__VA_ARGS__); \
612 }
613#define BTIF_TRACE_DEBUG(...) \
614 { \
615 if (btif_trace_level >= BT_TRACE_LEVEL_DEBUG) \
616 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
617 TRACE_TYPE_DEBUG, \
618 ##__VA_ARGS__); \
619 }
620#define BTIF_TRACE_VERBOSE(...) \
621 { \
622 if (btif_trace_level >= BT_TRACE_LEVEL_VERBOSE) \
623 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
624 TRACE_TYPE_DEBUG, \
625 ##__VA_ARGS__); \
626 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800627
The Android Open Source Project5738f832012-12-12 16:00:35 -0800628/* define traces for application */
Myles Watsonc1e42392016-11-09 09:47:42 -0800629#define APPL_TRACE_ERROR(...) \
630 { \
631 if (appl_trace_level >= BT_TRACE_LEVEL_ERROR) \
632 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
633 TRACE_TYPE_ERROR, \
634 ##__VA_ARGS__); \
635 }
636#define APPL_TRACE_WARNING(...) \
637 { \
638 if (appl_trace_level >= BT_TRACE_LEVEL_WARNING) \
639 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
640 TRACE_TYPE_WARNING, \
641 ##__VA_ARGS__); \
642 }
643#define APPL_TRACE_API(...) \
644 { \
645 if (appl_trace_level >= BT_TRACE_LEVEL_API) \
646 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
647 TRACE_TYPE_API, \
648 ##__VA_ARGS__); \
649 }
650#define APPL_TRACE_EVENT(...) \
651 { \
652 if (appl_trace_level >= BT_TRACE_LEVEL_EVENT) \
653 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
654 TRACE_TYPE_EVENT, \
655 ##__VA_ARGS__); \
656 }
657#define APPL_TRACE_DEBUG(...) \
658 { \
659 if (appl_trace_level >= BT_TRACE_LEVEL_DEBUG) \
660 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
661 TRACE_TYPE_DEBUG, \
662 ##__VA_ARGS__); \
663 }
664#define APPL_TRACE_VERBOSE(...) \
665 { \
666 if (appl_trace_level >= BT_TRACE_LEVEL_VERBOSE) \
667 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
668 TRACE_TYPE_DEBUG, \
669 ##__VA_ARGS__); \
670 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800671
Marie Janssend19e0782016-07-15 12:48:27 -0700672typedef uint8_t tBTTRC_LAYER_ID;
Myles Watsonc1e42392016-11-09 09:47:42 -0800673typedef uint8_t(tBTTRC_SET_TRACE_LEVEL)(uint8_t);
Chris Mantonaa0f6ec2014-09-24 15:18:41 -0700674
675typedef struct {
Myles Watsonc1e42392016-11-09 09:47:42 -0800676 const tBTTRC_LAYER_ID layer_id_start;
677 const tBTTRC_LAYER_ID layer_id_end;
678 tBTTRC_SET_TRACE_LEVEL* p_f;
679 const char* trc_name;
680 uint8_t trace_level;
Chris Mantonaa0f6ec2014-09-24 15:18:41 -0700681} tBTTRC_FUNC_MAP;
682
Myles Watsonc1e42392016-11-09 09:47:42 -0800683/* External declaration for appl_trace_level here to avoid to add the
684 * declaration in all the files using APPL_TRACExxx macros */
Marie Janssend19e0782016-07-15 12:48:27 -0700685extern uint8_t appl_trace_level;
Pavlin Radoslavov258c2532015-09-27 20:59:05 -0700686
Myles Watsonc1e42392016-11-09 09:47:42 -0800687void LogMsg(uint32_t trace_set_mask, const char* fmt_str, ...);
Jakub Pawlowski713993d2016-04-21 13:16:45 -0700688
689#ifdef __cplusplus
690}
Marie Janssend19e0782016-07-15 12:48:27 -0700691#endif
Jakub Pawlowski26474522017-10-04 12:22:10 -0700692
693#ifdef __cplusplus
694
695#include <iomanip>
696#include <sstream>
697#include <type_traits>
698
Pavlin Radoslavov25cd0542018-04-06 17:05:47 -0700699#include <base/logging.h>
700
Jack He78b69d92018-11-16 02:59:43 -0800701/* Prints integral parameter x as hex string, with '0' fill */
Jakub Pawlowski26474522017-10-04 12:22:10 -0700702template <typename T>
703std::string loghex(T x) {
704 static_assert(std::is_integral<T>::value,
705 "loghex parameter must be integral.");
706 std::stringstream tmp;
707 tmp << std::showbase << std::internal << std::hex << std::setfill('0')
Jakub Pawlowski78b3e7b2018-02-12 13:18:33 -0800708 << std::setw((sizeof(T) * 2) + 2) << +x;
Jakub Pawlowski26474522017-10-04 12:22:10 -0700709 return tmp.str();
710}
711
Jack He78b69d92018-11-16 02:59:43 -0800712/* Prints integral array as hex string, with '0' fill */
713template <typename T, size_t N>
714std::string loghex(std::array<T, N> array) {
715 static_assert(std::is_integral<T>::value,
716 "type stored in array must be integral.");
717 std::stringstream tmp;
718 for (const auto& x : array) {
719 tmp << std::internal << std::hex << std::setfill('0')
720 << std::setw((sizeof(uint8_t) * 2) + 2) << +x;
721 }
722 return tmp.str();
723}
724
Pavlin Radoslavov25cd0542018-04-06 17:05:47 -0700725/**
Guang Xie1b548bb2018-02-15 12:42:15 -0800726 * Obtains the string representation of a boolean value.
727 *
728 * @param value the boolean value to use
729 * @return the string representation of the boolean value: "true" or "false"
730 */
731inline std::string logbool(bool value) {
732 std::stringstream tmp;
733 tmp << std::boolalpha << value;
734 return tmp.str();
735}
736
737/**
Pavlin Radoslavov25cd0542018-04-06 17:05:47 -0700738 * Append a field name to a string.
739 *
740 * The field names are added to the string with "|" in between.
741 *
742 * @param p_result a pointer to the result string to add the field name to
743 * @param append if true the field name will be added
744 * @param name the field name to add
745 * @return the result string
746 */
747inline std::string& AppendField(std::string* p_result, bool append,
748 const std::string& name) {
749 CHECK(p_result != nullptr);
750 if (!append) return *p_result;
751 if (!p_result->empty()) *p_result += "|";
752 *p_result += name;
753 return *p_result;
754}
755
Ajay Panickerfe8edd02018-05-03 12:58:53 -0700756// This object puts the stream in a state where every time that a new line
757// occurs, the next line is indented a certain number of spaces. The stream is
758// reset to its previous state when the object is destroyed.
759class ScopedIndent {
760 public:
761 ScopedIndent(std::ostream& stream, int indent_size = DEFAULT_TAB)
762 : indented_buf_(stream, indent_size) {
763 old_stream_ = &stream;
764 old_stream_buf_ = stream.rdbuf();
765 stream.rdbuf(&indented_buf_);
766 }
767
768 ~ScopedIndent() { old_stream_->rdbuf(old_stream_buf_); }
769
770 static const size_t DEFAULT_TAB = 2;
771
772 private:
773 class IndentedStreamBuf : public std::streambuf {
774 public:
775 IndentedStreamBuf(std::ostream& stream, int indent_size)
776 : wrapped_buf_(stream.rdbuf()),
777 indent_size_(indent_size),
778 indent_next_line_(true){};
779
780 protected:
781 virtual int overflow(int character) override {
782 if (indent_next_line_ && character != '\n') {
783 for (int i = 0; i < indent_size_; i++) wrapped_buf_->sputc(' ');
784 }
785
786 indent_next_line_ = false;
787 if (character == '\n') {
788 indent_next_line_ = true;
789 }
790
791 return wrapped_buf_->sputc(character);
792 }
793
794 private:
795 std::streambuf* wrapped_buf_;
796 int indent_size_;
797 bool indent_next_line_;
798 };
799
800 std::ostream* old_stream_;
801 std::streambuf* old_stream_buf_;
802 IndentedStreamBuf indented_buf_;
803};
804
Jakub Pawlowski26474522017-10-04 12:22:10 -0700805#endif