Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
wdebug.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#include <stdlib.h>
20#include "wdebug.h"
21#include "streamer.h"
22#include "odevice.h"
23
24
25static MsgManager *msg_manager=NULL;
26
27static int debug_enabled=0;
28static ostream *debug_ostream=NULL;
29static Streamer debug_streamer;
30
31static int info_enabled=0;
32static ostream *info_ostream=NULL;
33static Streamer info_streamer;
34
35static int warn_enabled=0;
36static ostream *warn_ostream=NULL;
37static Streamer warn_streamer;
38
39static int error_enabled=0;
40static ostream *error_ostream=NULL;
41static Streamer error_streamer;
42
43
44// Don't dare touch this semaphore in application code!
45#ifdef USE_DEBUG_SEM
47#else
49#endif
50
51
53{
54 if (device==NULL)
55 return(1);
56
58 debug_streamer.setOutputDevice(device);
59 delete(debug_ostream);
60 debug_ostream=new ostream(&debug_streamer);
61
62 info_streamer.setOutputDevice(device);
63 delete(info_ostream);
64 info_ostream=new ostream(&info_streamer);
65
66 warn_streamer.setOutputDevice(device);
67 delete(warn_ostream);
68 warn_ostream=new ostream(&warn_streamer);
69
70 error_streamer.setOutputDevice(device);
71 delete(error_ostream);
72 error_ostream=new ostream(&error_streamer);
73
75
76 return(0);
77}
78
79
80int MsgManager::ReplaceAllStreams(FileD * output_device, IN char *device_filename, IN char *copy_filename)
81{
82 DebugLibSemaphore.Wait();
83
84 delete(debug_ostream);
85 delete(info_ostream);
86 delete(warn_ostream);
87 delete(error_ostream);
88
89 if (output_device != NULL)
90 {
91 delete(output_device);
93 }
94
95 rename(device_filename, copy_filename);
96
97// FileD new_device(device_filename);
98 output_device = new FileD(device_filename);
99
100 debug_streamer.setOutputDevice(output_device);
101 debug_ostream = new ostream(&debug_streamer);
102
103 info_streamer.setOutputDevice(output_device);
104 info_ostream=new ostream(&info_streamer);
105
106 warn_streamer.setOutputDevice(output_device);
107 warn_ostream = new ostream(&warn_streamer);
108
109 error_streamer.setOutputDevice(output_device);
110 error_ostream = new ostream(&error_streamer);
111
112 DebugLibSemaphore.Post();
113
114 return(0);
115}
116
117
119{
120 if (device==NULL)
121 return(1);
122
123 DEBUGLOCK;
124 debug_streamer.setOutputDevice(device);
125 delete(debug_ostream);
126 debug_ostream=new ostream(&debug_streamer);
128 return(0);
129}
130
132{
133 if (device==NULL)
134 return(1);
135
136 DEBUGLOCK;
137 info_streamer.setOutputDevice(device);
138 delete(info_ostream);
139 info_ostream=new ostream(&info_streamer);
141 return(0);
142}
143
145{
146 if (device==NULL)
147 return(1);
148
149 DEBUGLOCK;
150 warn_streamer.setOutputDevice(device);
151 delete(warn_ostream);
152 warn_ostream=new ostream(&warn_streamer);
154 return(0);
155}
156
158{
159 if (device==NULL)
160 return(1);
161
162 DEBUGLOCK;
163 error_streamer.setOutputDevice(device);
164 delete(error_ostream);
165 error_ostream=new ostream(&error_streamer);
167 return(0);
168}
169
170
171
172ostream *MsgManager::debugStream(void)
173{
174 return(debug_ostream);
175}
176
177ostream *MsgManager::infoStream(void)
178{
179 return(info_ostream);
180}
181
182ostream *MsgManager::warnStream(void)
183{
184 return(warn_ostream);
185}
186
187ostream *MsgManager::errorStream(void)
188{
189 return(error_ostream);
190}
#define NULL
Definition BaseType.h:92
Definition filed.h:25
static int setAllStreams(OutputDevice *device)
Definition wdebug.cpp:45
static int setErrorStream(OutputDevice *device)
Definition wdebug.cpp:110
static ostream * warnStream(void)
Definition wdebug.cpp:135
static int ReplaceAllStreams(FileD *output_device, IN char *device_filename, IN char *copy_filename)
Definition wdebug.cpp:80
static ostream * infoStream(void)
Definition wdebug.cpp:130
static ostream * debugStream(void)
Definition wdebug.cpp:125
static int setInfoStream(OutputDevice *device)
Definition wdebug.cpp:84
static ostream * errorStream(void)
Definition wdebug.cpp:140
static int setWarnStream(OutputDevice *device)
Definition wdebug.cpp:97
static int setDebugStream(OutputDevice *device)
Definition wdebug.cpp:71
Definition sem4.h:43
int setOutputDevice(OutputDevice *output_device)
Definition streamer.cpp:38
Sem4 DebugLibSemaphore
Definition wdebug.cpp:46
#define DEBUGUNLOCK
Definition wdebug.h:94
#define DEBUGLOCK
Definition wdebug.h:93
OutputDevice * output_device
Definition main.cpp:59
#define DEBUGUNLOCK
Definition wdebug.h:94
#define DEBUGLOCK
Definition wdebug.h:93
#define IN
Definition wdebug.h:70
Sem4 DebugLibSemaphore
Definition wdebug.cpp:46