2 Copyright (c) 2013 Advanced Micro Devices, Inc.
4 This software is provided 'as-is', without any express or implied warranty.
5 In no event will the authors be held liable for any damages arising from the use of this software.
6 Permission is granted to anyone to use this software for any purpose,
7 including commercial applications, and to alter it and redistribute it freely,
8 subject to the following restrictions:
10 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
11 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
12 3. This notice may not be removed or altered from any source distribution.
14 //Originally written by Erwin Coumans
16 #include "b3Logging.h"
25 void b3PrintfFuncDefault(const char* msg)
28 OutputDebugStringA(msg);
35 void b3WarningMessageFuncDefault(const char* msg)
38 OutputDebugStringA(msg);
45 void b3ErrorMessageFuncDefault(const char* msg)
48 OutputDebugStringA(msg);
56 static b3PrintfFunc* b3s_printfFunc = b3PrintfFuncDefault;
57 static b3WarningMessageFunc* b3s_warningMessageFunc = b3WarningMessageFuncDefault;
58 static b3ErrorMessageFunc* b3s_errorMessageFunc = b3ErrorMessageFuncDefault;
60 ///The developer can route b3Printf output using their own implementation
61 void b3SetCustomPrintfFunc(b3PrintfFunc* printfFunc)
63 b3s_printfFunc = printfFunc;
65 void b3SetCustomWarningMessageFunc(b3PrintfFunc* warningMessageFunc)
67 b3s_warningMessageFunc = warningMessageFunc;
69 void b3SetCustomErrorMessageFunc(b3PrintfFunc* errorMessageFunc)
71 b3s_errorMessageFunc = errorMessageFunc;
74 //#define B3_MAX_DEBUG_STRING_LENGTH 2048
75 #define B3_MAX_DEBUG_STRING_LENGTH 32768
77 void b3OutputPrintfVarArgsInternal(const char* str, ...)
79 char strDebug[B3_MAX_DEBUG_STRING_LENGTH] = {0};
81 va_start(argList, str);
83 vsprintf_s(strDebug, B3_MAX_DEBUG_STRING_LENGTH, str, argList);
85 vsnprintf(strDebug, B3_MAX_DEBUG_STRING_LENGTH, str, argList);
87 (b3s_printfFunc)(strDebug);
90 void b3OutputWarningMessageVarArgsInternal(const char* str, ...)
92 char strDebug[B3_MAX_DEBUG_STRING_LENGTH] = {0};
94 va_start(argList, str);
96 vsprintf_s(strDebug, B3_MAX_DEBUG_STRING_LENGTH, str, argList);
98 vsnprintf(strDebug, B3_MAX_DEBUG_STRING_LENGTH, str, argList);
100 (b3s_warningMessageFunc)(strDebug);
103 void b3OutputErrorMessageVarArgsInternal(const char* str, ...)
105 char strDebug[B3_MAX_DEBUG_STRING_LENGTH] = {0};
107 va_start(argList, str);
109 vsprintf_s(strDebug, B3_MAX_DEBUG_STRING_LENGTH, str, argList);
111 vsnprintf(strDebug, B3_MAX_DEBUG_STRING_LENGTH, str, argList);
113 (b3s_errorMessageFunc)(strDebug);
117 void b3EnterProfileZoneDefault(const char* name)
120 void b3LeaveProfileZoneDefault()
123 static b3EnterProfileZoneFunc* b3s_enterFunc = b3EnterProfileZoneDefault;
124 static b3LeaveProfileZoneFunc* b3s_leaveFunc = b3LeaveProfileZoneDefault;
125 void b3EnterProfileZone(const char* name)
127 (b3s_enterFunc)(name);
129 void b3LeaveProfileZone()
134 void b3SetCustomEnterProfileZoneFunc(b3EnterProfileZoneFunc* enterFunc)
136 b3s_enterFunc = enterFunc;
138 void b3SetCustomLeaveProfileZoneFunc(b3LeaveProfileZoneFunc* leaveFunc)
140 b3s_leaveFunc = leaveFunc;