1 /**************************************************************************
3 * Copyright 2013-2014 RAD Game Tools and Valve Software
4 * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 **************************************************************************/
27 // File: vogl_console.h
30 #include "vogl_core.h"
31 #include "vogl_dynamic_string.h"
39 enum eConsoleMessageType
41 cDebugConsoleMessage, // debugging messages
42 cProgressConsoleMessage, // progress messages
43 cInfoConsoleMessage, // ordinary messages
44 cConsoleConsoleMessage, // user console output
45 cMessageConsoleMessage, // high importance messages
46 cWarningConsoleMessage, // warnings
47 cErrorConsoleMessage, // errors
48 cHeader1ConsoleMessage, // header1
52 typedef bool (*console_output_func)(eConsoleMessageType type, const char *pMsg, void *pData);
60 static bool is_initialized()
62 return m_pMutex != NULL;
65 static const char *get_message_type_str(eConsoleMessageType type);
66 static eConsoleMessageType get_message_type_from_str(const char *str);
68 static void set_default_category(eConsoleMessageType category);
69 static eConsoleMessageType get_default_category();
71 static void add_console_output_func(console_output_func pFunc, void *pData);
72 static void remove_console_output_func(console_output_func pFunc);
74 static void printf(const char *p, ...) VOGL_ATTRIBUTE_PRINTF(1, 2);
76 static void vprintf(eConsoleMessageType type, const char *p, va_list args);
77 static void printf(eConsoleMessageType type, const char *p, ...) VOGL_ATTRIBUTE_PRINTF(2, 3);
79 static void cons(const char *p, ...) VOGL_ATTRIBUTE_PRINTF(1, 2);
80 static void debug(const char *p, ...) VOGL_ATTRIBUTE_PRINTF(1, 2);
81 static void progress(const char *p, ...) VOGL_ATTRIBUTE_PRINTF(1, 2);
82 static void info(const char *p, ...) VOGL_ATTRIBUTE_PRINTF(1, 2);
83 static void message(const char *p, ...) VOGL_ATTRIBUTE_PRINTF(1, 2);
84 static void warning(const char *p, ...) VOGL_ATTRIBUTE_PRINTF(1, 2);
85 static void error(const char *p, ...) VOGL_ATTRIBUTE_PRINTF(1, 2);
86 static void header1(const char *p, ...) VOGL_ATTRIBUTE_PRINTF(1, 2);
88 static void disable_prefixes()
92 static void enable_prefixes()
96 static bool get_prefixes()
100 static bool get_at_beginning_of_line()
102 return m_at_beginning_of_line;
105 static void set_tool_prefix(const char *pPrefix)
107 strcpy(m_tool_prefix, pPrefix);
109 static const char *get_tool_prefix()
111 return m_tool_prefix;
114 static void disable_output()
116 m_output_disabled = true;
118 static void enable_output()
120 m_output_disabled = false;
122 static bool get_output_disabled()
124 return m_output_disabled;
127 static void set_log_stream(data_stream *pStream)
129 m_pLog_stream = pStream;
131 static data_stream *get_log_stream()
133 return m_pLog_stream;
136 static uint get_total_messages(eConsoleMessageType type)
138 return m_num_messages[type];
142 static eConsoleMessageType m_default_category;
146 console_func(console_output_func func = NULL, void *pData = NULL)
147 : m_func(func), m_pData(pData)
151 console_output_func m_func;
159 static uint m_num_output_funcs;
160 static console_func m_output_funcs[cMaxOutputFuncs];
162 static bool m_prefixes, m_output_disabled;
163 static data_stream *m_pLog_stream;
164 static mutex *m_pMutex;
165 static uint m_num_messages[cCMTTotal];
166 static bool m_at_beginning_of_line;
167 static char m_tool_prefix[256];