UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
sv_log.cpp
Go to the documentation of this file.
1 
8 /*
9 All original material Copyright (C) 2002-2020 UFO: Alien Invasion.
10 
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License
13 as published by the Free Software Foundation; either version 2
14 of the License, or (at your option) any later version.
15 
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 
20 See the GNU General Public License for more details.
21 
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 */
26 
27 #include "server.h"
28 #include "sv_log.h"
29 #include "../shared/stringhunk.h"
30 #include <SDL_thread.h>
31 
32 static SDL_mutex* svLogMutex;
34 
35 static void SV_LogPrintOutput (const char* string)
36 {
37  Com_Printf("%s", string);
38 }
39 
44 void SV_LogHandleOutput (void)
45 {
46  SDL_LockMutex(svLogMutex);
47  STRHUNK_Visit(svLogHunk, SV_LogPrintOutput);
48  STRHUNK_Reset(svLogHunk);
49  SDL_UnlockMutex(svLogMutex);
50 }
51 
60 void SV_LogAdd (const char* format, va_list ap)
61 {
62  char msg[1024];
63 
64  Q_vsnprintf(msg, sizeof(msg), format, ap);
65 
66  SDL_LockMutex(svLogMutex);
67  STRHUNK_Add(svLogHunk, msg);
68  SDL_UnlockMutex(svLogMutex);
69 }
70 
71 void SV_LogInit (void)
72 {
73  const size_t svHunkSize = 32768;
74  svLogMutex = SDL_CreateMutex();
75  svLogHunk = STRHUNK_Create(svHunkSize);
76 }
77 
78 void SV_LogShutdown (void)
79 {
80  SDL_DestroyMutex(svLogMutex);
81  svLogMutex = nullptr;
82  STRHUNK_Delete(&svLogHunk);
83 }
static stringHunk_t * svLogHunk
Definition: sv_log.cpp:33
int Q_vsnprintf(char *str, size_t size, const char *format, va_list ap)
Safe (null terminating) vsnprintf implementation.
Definition: shared.cpp:535
void SV_LogInit(void)
Definition: sv_log.cpp:71
bool STRHUNK_Add(stringHunk_t *hunk, const char *string)
Definition: stringhunk.cpp:32
void Com_Printf(const char *const fmt,...)
Definition: common.cpp:386
void SV_LogShutdown(void)
Definition: sv_log.cpp:78
static SDL_mutex * svLogMutex
Definition: sv_log.cpp:32
void SV_LogHandleOutput(void)
Handle the log output from the main thread by reading the strings from the dbuffer the game lib threa...
Definition: sv_log.cpp:44
game lib logging handling
stringHunk_t * STRHUNK_Create(size_t size)
Definition: stringhunk.cpp:88
Main server include file.
static void SV_LogPrintOutput(const char *string)
Definition: sv_log.cpp:35
void STRHUNK_Reset(stringHunk_t *hunk)
Definition: stringhunk.cpp:55
void SV_LogAdd(const char *format, va_list ap)
Async version to add a log entry for the game lib.
Definition: sv_log.cpp:60
void STRHUNK_Delete(stringHunk_t **hunk)
Definition: stringhunk.cpp:97
void STRHUNK_Visit(stringHunk_t *hunk, stringHunkVisitor_t visitor)
Definition: stringhunk.cpp:62
void format(__printf__, 1, 2)))