blob: 933012c161af5e5c26c07232078db8f3a7a7b28f [file] [log] [blame]
Jon Ashburn21001f62015-02-16 08:26:50 -07001/*
2 * XGL
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24#include <stdio.h>
25
26static XGL_LAYER_DBG_FUNCTION_NODE *g_pDbgFunctionHead = NULL;
27static XGL_LAYER_DBG_REPORT_LEVEL g_reportingLevel = XGL_DBG_LAYER_LEVEL_INFO;
28static XGL_LAYER_DBG_ACTION g_debugAction = XGL_DBG_LAYER_ACTION_LOG_MSG;
29static FILE *g_logFile = NULL;
30
31// Utility function to handle reporting
32// If callbacks are enabled, use them, otherwise use printf
33static void layerCbMsg(XGL_DBG_MSG_TYPE msgType,
34 XGL_VALIDATION_LEVEL validationLevel,
35 XGL_BASE_OBJECT srcObject,
36 size_t location,
37 int32_t msgCode,
38 const char* pLayerPrefix,
39 const char* pMsg)
40{
41 if (g_debugAction & (XGL_DBG_LAYER_ACTION_LOG_MSG | XGL_DBG_LAYER_ACTION_CALLBACK)) {
42 XGL_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;
43 switch (msgType) {
44 case XGL_DBG_MSG_ERROR:
45 if (g_reportingLevel <= XGL_DBG_LAYER_LEVEL_ERROR) {
Courtney Goeltzenleuchter0c7be302015-02-25 16:56:00 -070046 if (g_debugAction & XGL_DBG_LAYER_ACTION_LOG_MSG) {
Jon Ashburn21001f62015-02-16 08:26:50 -070047 fprintf(g_logFile, "{%s}ERROR : %s\n", pLayerPrefix, pMsg);
Courtney Goeltzenleuchter0c7be302015-02-25 16:56:00 -070048 fflush(g_logFile);
49 }
Jon Ashburn21001f62015-02-16 08:26:50 -070050 if (g_debugAction & XGL_DBG_LAYER_ACTION_CALLBACK)
51 while (pTrav) {
52 pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData);
53 pTrav = pTrav->pNext;
54 }
55 }
56 break;
57 case XGL_DBG_MSG_WARNING:
58 if (g_reportingLevel <= XGL_DBG_LAYER_LEVEL_WARN) {
59 if (g_debugAction & XGL_DBG_LAYER_ACTION_LOG_MSG)
60 fprintf(g_logFile, "{%s}WARN : %s\n", pLayerPrefix, pMsg);
61 if (g_debugAction & XGL_DBG_LAYER_ACTION_CALLBACK)
62 while (pTrav) {
63 pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData);
64 pTrav = pTrav->pNext;
65 }
66 }
67 break;
68 case XGL_DBG_MSG_PERF_WARNING:
69 if (g_reportingLevel <= XGL_DBG_LAYER_LEVEL_PERF_WARN) {
70 if (g_debugAction & XGL_DBG_LAYER_ACTION_LOG_MSG)
71 fprintf(g_logFile, "{%s}PERF_WARN : %s\n", pLayerPrefix, pMsg);
72 if (g_debugAction & XGL_DBG_LAYER_ACTION_CALLBACK)
73 while (pTrav) {
74 pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData);
75 pTrav = pTrav->pNext;
76 }
77 }
78 break;
79 default:
80 if (g_reportingLevel <= XGL_DBG_LAYER_LEVEL_INFO) {
81 if (g_debugAction & XGL_DBG_LAYER_ACTION_LOG_MSG)
82 fprintf(g_logFile, "{%s}INFO : %s\n", pLayerPrefix, pMsg);
83 if (g_debugAction & XGL_DBG_LAYER_ACTION_CALLBACK)
84 while (pTrav) {
85 pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData);
86 pTrav = pTrav->pNext;
87 }
88 }
89 break;
90 }
91 }
92}