|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "stdafx.h" |
|
22 #include <string.h> |
|
23 #include <malloc.h> |
|
24 #include <winbase.h> |
|
25 #include "cReporter.h" |
|
26 |
|
27 CRITICAL_SECTION aCriticalSection; |
|
28 |
|
29 /***************************************************************************** |
|
30 * Basic constructor |
|
31 *****************************************************************************/ |
|
32 |
|
33 Reporter::Reporter() |
|
34 : pCurrent((va_list)0), state(0), prefix(0), hFile((HANDLE)0), fileRead(0) |
|
35 { |
|
36 memset(filename, 0, sizeof(filename)); |
|
37 memset(progname, 0, sizeof(progname)); |
|
38 memset(buffer, 0, sizeof(buffer)); |
|
39 |
|
40 int i; |
|
41 for (i=0;i<RPT_MAX_LIST_ENTRIES;i++) |
|
42 messageList[i] = NULL; |
|
43 } |
|
44 |
|
45 /*************************************************************************** |
|
46 * Destructor to free any memory we've allocated. |
|
47 ***************************************************************************/ |
|
48 |
|
49 Reporter::~Reporter ( void ) |
|
50 { |
|
51 kill(); |
|
52 } |
|
53 |
|
54 /***************************************************************************** |
|
55 * Initialiser for Reporter using automatic filename generator. |
|
56 * |
|
57 * Generates a filename if requested. If file doesn't exist, it is created. |
|
58 *****************************************************************************/ |
|
59 |
|
60 CPO_BOOL |
|
61 Reporter::init ( const char * appName, |
|
62 const BITFIELD prefixMask, |
|
63 const BITFIELD destination ) |
|
64 { |
|
65 // must not be initialised |
|
66 if ( state & CPO_CONNECTED ) |
|
67 { |
|
68 return ( CPO_FALSE ); |
|
69 } |
|
70 |
|
71 // initialise variables |
|
72 prepare ( ); |
|
73 |
|
74 // set up logging file |
|
75 state = destination; |
|
76 if ( state & RPT_FILE ) |
|
77 { |
|
78 generateFilename ( filename, appName ); |
|
79 } |
|
80 |
|
81 // final preparations |
|
82 if ( ! ( setup ( appName, prefixMask ) ) ) |
|
83 { |
|
84 return ( CPO_FALSE ); |
|
85 } |
|
86 |
|
87 #ifdef RPT_DEBUG_PROG |
|
88 (void) fprintf ( stdout, |
|
89 "progname [%s] prefix %ld dest %ld file [%s] state %ld\n", |
|
90 progname, prefixMask, destination, filename, state ); |
|
91 (void) fflush ( stdout ); |
|
92 #endif |
|
93 |
|
94 InitializeCriticalSection(&aCriticalSection); |
|
95 return ( CPO_TRUE ); |
|
96 } |
|
97 |
|
98 /***************************************************************************** |
|
99 * Initialiser for Reporter using specific path for file output. |
|
100 * |
|
101 * Opens an output file if requested at the supplied path. |
|
102 * If the requested file doesn't exist, it is created. |
|
103 * If the path is invalid, initialisation will fail. |
|
104 *****************************************************************************/ |
|
105 |
|
106 CPO_BOOL |
|
107 Reporter::init ( const char * appName, |
|
108 const BITFIELD prefixMask, |
|
109 const BITFIELD destination, |
|
110 const char * path ) |
|
111 { |
|
112 char tmpFile [ CPO_MAX_FILENAME_LEN + 1 ]; |
|
113 char tmpPath [ CPO_MAX_FILENAME_LEN + 1 ]; |
|
114 |
|
115 // must not be initialised |
|
116 if ( state & CPO_CONNECTED ) |
|
117 { |
|
118 return ( CPO_FALSE ); |
|
119 } |
|
120 |
|
121 // initialise variables |
|
122 prepare ( ); |
|
123 |
|
124 // because we supplied a path, make sure we are setup for file output |
|
125 state = destination; |
|
126 if ( !(state & RPT_FILE) ) |
|
127 { |
|
128 state += RPT_FILE; |
|
129 } |
|
130 |
|
131 // generate the output filename |
|
132 generateFilename ( tmpFile, appName ); |
|
133 |
|
134 // add a backslash if there isn't one |
|
135 strcpy(tmpPath, path); |
|
136 if ((*(tmpPath + strlen(tmpPath) - 1)) != '\\') |
|
137 strcat(tmpPath, "\\"); |
|
138 |
|
139 (void) sprintf ( filename, "%s%s", tmpPath, tmpFile ); |
|
140 |
|
141 // final preparations |
|
142 if ( ! ( setup ( appName, prefixMask ) ) ) |
|
143 { |
|
144 return ( CPO_FALSE ); |
|
145 } |
|
146 |
|
147 #ifdef RPT_DEBUG_PROG |
|
148 (void) fprintf ( stdout, |
|
149 "appname [%s] prefix %ld dest %ld file [%s] state %ld\n", |
|
150 appName, prefixMask, destination, filename, state ); |
|
151 (void) fflush ( stdout ); |
|
152 #endif |
|
153 |
|
154 InitializeCriticalSection(&aCriticalSection); |
|
155 return ( CPO_TRUE ); |
|
156 } |
|
157 |
|
158 /***************************************************************************** |
|
159 * Initialiser for Reporter using specific path and filename for output. |
|
160 * |
|
161 * Opens an output file using supplied name at supplied path. |
|
162 * If the requested file doesn't exist, it is created. |
|
163 * If the path is invalid, initialisation will fail. |
|
164 *****************************************************************************/ |
|
165 |
|
166 CPO_BOOL |
|
167 Reporter::init ( const char * appName, |
|
168 const BITFIELD prefixMask, |
|
169 const BITFIELD destination, |
|
170 const char * path, |
|
171 const char * file, |
|
172 const unsigned long ulOpenAttributes) |
|
173 { |
|
174 char tmpFile [ CPO_MAX_FILENAME_LEN + 1 ]; |
|
175 char tmpPath [ CPO_MAX_FILENAME_LEN + 1 ]; |
|
176 |
|
177 // must not be initialised |
|
178 if ( state & CPO_CONNECTED ) |
|
179 { |
|
180 return ( CPO_FALSE ); |
|
181 } |
|
182 |
|
183 // initialise variables |
|
184 prepare ( ); |
|
185 |
|
186 // because we supplied a filename, make sure we are setup for file output |
|
187 state = destination; |
|
188 if ( ! ( state & RPT_FILE ) ) |
|
189 { |
|
190 state += RPT_FILE; |
|
191 } |
|
192 |
|
193 // get the actual filename if a full path has been supplied |
|
194 extractName ( tmpFile, file, CPO_MAX_FILENAME_LEN ); |
|
195 |
|
196 // add a backslash if there isn't one |
|
197 strcpy(tmpPath, path); |
|
198 if ((*(tmpPath + strlen(tmpPath) - 1)) != '\\') |
|
199 strcat(tmpPath, "\\"); |
|
200 |
|
201 (void) sprintf ( filename, "%s%s", tmpPath, tmpFile ); |
|
202 |
|
203 // final preparations |
|
204 if ( ! ( setup ( appName, prefixMask, ulOpenAttributes ) ) ) |
|
205 { |
|
206 return ( CPO_FALSE ); |
|
207 } |
|
208 |
|
209 #ifdef RPT_DEBUG_PROG |
|
210 (void) fprintf ( stdout, |
|
211 "appname [%s] prefix %ld dest %ld file [%s] state %ld\n", |
|
212 appName, prefixMask, destination, filename, state ); |
|
213 (void) fflush ( stdout ); |
|
214 #endif |
|
215 |
|
216 InitializeCriticalSection(&aCriticalSection); |
|
217 return ( CPO_TRUE ); |
|
218 } |
|
219 |
|
220 /***************************************************************************** |
|
221 * Append a 'Warning' message to file |
|
222 *****************************************************************************/ |
|
223 |
|
224 void |
|
225 Reporter::warn ( char * message, ... ) |
|
226 { |
|
227 // must be initialised and activated |
|
228 if ( ( state & CPO_CONNECTED ) && ( state & CPO_ACTIVATED ) ) |
|
229 { |
|
230 EnterCriticalSection(&aCriticalSection); |
|
231 va_start ( pCurrent, message ); |
|
232 buildMessage ( message, RPT_WARN ); |
|
233 va_end ( pCurrent ); |
|
234 LeaveCriticalSection(&aCriticalSection); |
|
235 } |
|
236 } |
|
237 |
|
238 /***************************************************************************** |
|
239 * Append an 'Error' message to file |
|
240 *****************************************************************************/ |
|
241 |
|
242 void |
|
243 Reporter::error ( char * message, ... ) |
|
244 { |
|
245 // must be initialised and activated |
|
246 if ( ( state & CPO_CONNECTED ) && ( state & CPO_ACTIVATED ) ) |
|
247 { |
|
248 EnterCriticalSection(&aCriticalSection); |
|
249 va_start ( pCurrent, message ); |
|
250 buildMessage ( message, RPT_ERROR ); |
|
251 va_end ( pCurrent ); |
|
252 LeaveCriticalSection(&aCriticalSection); |
|
253 } |
|
254 } |
|
255 |
|
256 /***************************************************************************** |
|
257 * Append a 'Info' message to file |
|
258 *****************************************************************************/ |
|
259 |
|
260 void |
|
261 Reporter::info ( char * message, ... ) |
|
262 { |
|
263 // must be initialised and activated |
|
264 if ( ( state & CPO_CONNECTED ) && ( state & CPO_ACTIVATED ) ) |
|
265 { |
|
266 EnterCriticalSection(&aCriticalSection); |
|
267 va_start ( pCurrent, message ); |
|
268 buildMessage ( message, RPT_INFO ); |
|
269 va_end ( pCurrent ); |
|
270 LeaveCriticalSection(&aCriticalSection); |
|
271 } |
|
272 } |
|
273 |
|
274 /***************************************************************************** |
|
275 * Append a 'Debug' message to file |
|
276 *****************************************************************************/ |
|
277 |
|
278 void |
|
279 Reporter::debug ( char * message, ... ) |
|
280 { |
|
281 // must be initialised and activated |
|
282 if ( ( state & CPO_CONNECTED ) && |
|
283 ( state & CPO_ACTIVATED ) && |
|
284 ( state & RPT_DEBUG_ON ) ) |
|
285 { |
|
286 EnterCriticalSection(&aCriticalSection); |
|
287 va_start ( pCurrent, message ); |
|
288 buildMessage ( message, RPT_DEBUG ); |
|
289 va_end ( pCurrent ); |
|
290 LeaveCriticalSection(&aCriticalSection); |
|
291 } |
|
292 } |
|
293 |
|
294 /***************************************************************************** |
|
295 * Append a message to output stream with no accompanying information. |
|
296 *****************************************************************************/ |
|
297 |
|
298 void |
|
299 Reporter::msg ( char * message, ... ) |
|
300 { |
|
301 // must be initialised and activated |
|
302 if ( ( state & CPO_CONNECTED ) && ( state & CPO_ACTIVATED ) ) |
|
303 { |
|
304 EnterCriticalSection(&aCriticalSection); |
|
305 va_start ( pCurrent, message ); |
|
306 buildMessage ( message, RPT_MSG ); |
|
307 va_end ( pCurrent ); |
|
308 LeaveCriticalSection(&aCriticalSection); |
|
309 } |
|
310 } |
|
311 |
|
312 /***************************************************************************** |
|
313 * Write a special message containing day, mth, year, and time with the text. |
|
314 *****************************************************************************/ |
|
315 |
|
316 void |
|
317 Reporter::header ( char * message, ... ) |
|
318 { |
|
319 if ( ( state & CPO_CONNECTED ) && ( state & CPO_ACTIVATED ) ) |
|
320 { |
|
321 EnterCriticalSection(&aCriticalSection); |
|
322 va_start ( pCurrent, message ); |
|
323 buildMessage ( message, RPT_HEADER ); |
|
324 va_end ( pCurrent ); |
|
325 LeaveCriticalSection(&aCriticalSection); |
|
326 } |
|
327 } |
|
328 |
|
329 /***************************************************************************** |
|
330 * Return the text associated with a particular code. |
|
331 *****************************************************************************/ |
|
332 |
|
333 char * |
|
334 Reporter::text ( char * message, ... ) |
|
335 { |
|
336 *( buffer ) = '\0'; |
|
337 |
|
338 if ( ( state & CPO_CONNECTED ) && ( state & CPO_ACTIVATED ) ) |
|
339 { |
|
340 EnterCriticalSection(&aCriticalSection); |
|
341 va_start ( pCurrent, message ); |
|
342 buildMessage ( message, RPT_TEXT ); |
|
343 va_end ( pCurrent ); |
|
344 LeaveCriticalSection(&aCriticalSection); |
|
345 } |
|
346 |
|
347 return ( buffer ); |
|
348 } |
|
349 |
|
350 /***************************************************************************** |
|
351 * Append a 'Warning' message to file from message list. |
|
352 *****************************************************************************/ |
|
353 |
|
354 void |
|
355 Reporter::warn ( int code, ... ) |
|
356 { |
|
357 if ( ( state & CPO_CONNECTED ) && ( state & CPO_ACTIVATED ) ) |
|
358 { |
|
359 EnterCriticalSection(&aCriticalSection); |
|
360 |
|
361 va_start ( pCurrent, code ); |
|
362 actOnCode ( code, RPT_WARN ); |
|
363 va_end ( pCurrent ); |
|
364 |
|
365 LeaveCriticalSection(&aCriticalSection); |
|
366 } |
|
367 } |
|
368 |
|
369 /***************************************************************************** |
|
370 * Append an 'Error' message to file from message list. |
|
371 *****************************************************************************/ |
|
372 |
|
373 void |
|
374 Reporter::error ( int code, ... ) |
|
375 { |
|
376 if ( ( state & CPO_CONNECTED ) && ( state & CPO_ACTIVATED ) ) |
|
377 { |
|
378 EnterCriticalSection(&aCriticalSection); |
|
379 |
|
380 va_start ( pCurrent, code ); |
|
381 actOnCode ( code, RPT_ERROR ); |
|
382 va_end ( pCurrent ); |
|
383 |
|
384 LeaveCriticalSection(&aCriticalSection); |
|
385 } |
|
386 } |
|
387 |
|
388 /***************************************************************************** |
|
389 * Append a 'Info' message to file from message list. |
|
390 *****************************************************************************/ |
|
391 |
|
392 void |
|
393 Reporter::info ( int code, ... ) |
|
394 { |
|
395 if ( ( state & CPO_CONNECTED ) && ( state & CPO_ACTIVATED ) ) |
|
396 { |
|
397 EnterCriticalSection(&aCriticalSection); |
|
398 |
|
399 va_start ( pCurrent, code ); |
|
400 actOnCode ( code, RPT_INFO ); |
|
401 va_end ( pCurrent ); |
|
402 |
|
403 LeaveCriticalSection(&aCriticalSection); |
|
404 } |
|
405 } |
|
406 |
|
407 /***************************************************************************** |
|
408 * Append a 'Debug' message to file from message list. |
|
409 *****************************************************************************/ |
|
410 |
|
411 void |
|
412 Reporter::debug ( int code, ... ) |
|
413 { |
|
414 if ( ( state & CPO_CONNECTED ) && ( state & CPO_ACTIVATED ) ) |
|
415 { |
|
416 EnterCriticalSection(&aCriticalSection); |
|
417 |
|
418 if ( state & RPT_DEBUG_ON ) |
|
419 { |
|
420 va_start ( pCurrent, code ); |
|
421 actOnCode ( code, RPT_DEBUG ); |
|
422 va_end ( pCurrent ); |
|
423 } |
|
424 |
|
425 LeaveCriticalSection(&aCriticalSection); |
|
426 } |
|
427 } |
|
428 |
|
429 /***************************************************************************** |
|
430 * Append a message to output stream with no accompanying information. |
|
431 *****************************************************************************/ |
|
432 |
|
433 void |
|
434 Reporter::msg ( int code, ... ) |
|
435 { |
|
436 if ( ( state & CPO_CONNECTED ) && ( state & CPO_ACTIVATED ) ) |
|
437 { |
|
438 EnterCriticalSection(&aCriticalSection); |
|
439 |
|
440 va_start ( pCurrent, code ); |
|
441 actOnCode ( code, RPT_MSG ); |
|
442 va_end ( pCurrent ); |
|
443 |
|
444 LeaveCriticalSection(&aCriticalSection); |
|
445 } |
|
446 } |
|
447 |
|
448 /***************************************************************************** |
|
449 * Write a special message containing day, mth, year, and time with the text. |
|
450 *****************************************************************************/ |
|
451 |
|
452 void |
|
453 Reporter::header ( int code, ... ) |
|
454 { |
|
455 if ( ( state & CPO_CONNECTED ) && ( state & CPO_ACTIVATED ) ) |
|
456 { |
|
457 EnterCriticalSection(&aCriticalSection); |
|
458 |
|
459 va_start ( pCurrent, code ); |
|
460 actOnCode ( code, RPT_HEADER ); |
|
461 va_end ( pCurrent ); |
|
462 |
|
463 LeaveCriticalSection(&aCriticalSection); |
|
464 } |
|
465 } |
|
466 |
|
467 /***************************************************************************** |
|
468 * Return the text associated with a particular code. |
|
469 *****************************************************************************/ |
|
470 |
|
471 char * |
|
472 Reporter::text ( int code, ... ) |
|
473 { |
|
474 if ( ( state & CPO_CONNECTED ) && ( state & CPO_ACTIVATED ) ) |
|
475 { |
|
476 EnterCriticalSection(&aCriticalSection); |
|
477 |
|
478 *( buffer ) = '\0'; |
|
479 |
|
480 va_start ( pCurrent, code ); |
|
481 actOnCode ( code, RPT_TEXT ); |
|
482 va_end ( pCurrent ); |
|
483 |
|
484 LeaveCriticalSection(&aCriticalSection); |
|
485 } |
|
486 return ( buffer ); |
|
487 } |
|
488 |
|
489 /***************************************************************************** |
|
490 * Append a dashed line to file |
|
491 *****************************************************************************/ |
|
492 |
|
493 void |
|
494 Reporter::dash ( void ) |
|
495 { |
|
496 // must be initialised and activated |
|
497 if ( ( state & CPO_CONNECTED ) && ( state & CPO_ACTIVATED ) ) |
|
498 { |
|
499 EnterCriticalSection(&aCriticalSection); |
|
500 writeToStream ( "----------------------------------------" |
|
501 "---------------------------------------" ); |
|
502 LeaveCriticalSection(&aCriticalSection); |
|
503 } |
|
504 } |
|
505 |
|
506 /***************************************************************************** |
|
507 * Append a star line to file |
|
508 *****************************************************************************/ |
|
509 |
|
510 void |
|
511 Reporter::star ( void ) |
|
512 { |
|
513 // must be initialised and activated |
|
514 if ( ( state & CPO_CONNECTED ) && ( state & CPO_ACTIVATED ) ) |
|
515 { |
|
516 EnterCriticalSection(&aCriticalSection); |
|
517 writeToStream ( "****************************************" |
|
518 "***************************************" ); |
|
519 LeaveCriticalSection(&aCriticalSection); |
|
520 } |
|
521 } |
|
522 |
|
523 /***************************************************************************** |
|
524 * Append a blank line to file |
|
525 *****************************************************************************/ |
|
526 |
|
527 void |
|
528 Reporter::blank ( void ) |
|
529 { |
|
530 // must be initialised and activated |
|
531 if ( ( state & CPO_CONNECTED ) && ( state & CPO_ACTIVATED ) ) |
|
532 { |
|
533 EnterCriticalSection(&aCriticalSection); |
|
534 writeToStream ( " " ); |
|
535 LeaveCriticalSection(&aCriticalSection); |
|
536 } |
|
537 } |
|
538 |
|
539 /***************************************************************************** |
|
540 * Shutdown the Reporter |
|
541 * Puts a message into the logging file that the Reporter has shutdown. |
|
542 * Closes the logging file. |
|
543 *****************************************************************************/ |
|
544 |
|
545 void |
|
546 Reporter::kill ( void ) |
|
547 { |
|
548 // must be initialised |
|
549 if ( state & CPO_CONNECTED ) |
|
550 { |
|
551 EnterCriticalSection(&aCriticalSection); |
|
552 if ( state & RPT_FILE ) |
|
553 { |
|
554 closeFile ( ); |
|
555 } |
|
556 |
|
557 // clear in case actions are tried on an uninitialised Reporter |
|
558 state = CPO_CLEAR; |
|
559 |
|
560 // free any memory allocated |
|
561 if ( fileRead ) |
|
562 { |
|
563 for (int i=0;i<RPT_MAX_LIST_ENTRIES;i++) |
|
564 { |
|
565 if ( messageList [ i ] ) |
|
566 { |
|
567 //delete ( messageList [ i ] ); |
|
568 free ( messageList [ i ] ); |
|
569 } |
|
570 } |
|
571 } |
|
572 LeaveCriticalSection(&aCriticalSection); |
|
573 } |
|
574 |
|
575 DeleteCriticalSection(&aCriticalSection); |
|
576 } |
|
577 |
|
578 /***************************************************************************** |
|
579 * Return whether the Reporter is currently initialised or not. |
|
580 *****************************************************************************/ |
|
581 |
|
582 CPO_BOOL |
|
583 Reporter::connected ( void ) |
|
584 { |
|
585 return ( (BOOLEAN) state & CPO_CONNECTED ); |
|
586 } |
|
587 |
|
588 /***************************************************************************** |
|
589 * Return whether the Reporter is currently active or not. |
|
590 *****************************************************************************/ |
|
591 |
|
592 CPO_BOOL |
|
593 Reporter::active ( void ) |
|
594 { |
|
595 return ( (BOOLEAN) state & CPO_ACTIVATED ); |
|
596 } |
|
597 |
|
598 /***************************************************************************** |
|
599 * Suspend the Reporter |
|
600 *****************************************************************************/ |
|
601 |
|
602 void |
|
603 Reporter::sleep ( void ) |
|
604 { |
|
605 // must be initialised and activated |
|
606 if ( ( state & CPO_CONNECTED ) && ( state & CPO_ACTIVATED ) ) |
|
607 { |
|
608 EnterCriticalSection(&aCriticalSection); |
|
609 state -= CPO_ACTIVATED; |
|
610 |
|
611 if ( state & RPT_FILE ) |
|
612 { |
|
613 closeFile ( ); |
|
614 } |
|
615 LeaveCriticalSection(&aCriticalSection); |
|
616 } |
|
617 } |
|
618 |
|
619 /***************************************************************************** |
|
620 * Re-activate the Reporter |
|
621 *****************************************************************************/ |
|
622 |
|
623 void |
|
624 Reporter::wake ( void ) |
|
625 { |
|
626 // must be initialised but not activated |
|
627 if ( ( state & CPO_CONNECTED ) && ! ( state & CPO_ACTIVATED ) ) |
|
628 { |
|
629 EnterCriticalSection(&aCriticalSection); |
|
630 state += CPO_ACTIVATED; |
|
631 |
|
632 if ( state & RPT_FILE && !openFile ( ) ) |
|
633 { |
|
634 // couldn't reopen the file so stop outputting to it |
|
635 state -= RPT_FILE; |
|
636 |
|
637 // no output left so shutdown Reporter |
|
638 if ( !( state & RPT_OUTPUT_MASK ) ) |
|
639 { |
|
640 kill ( ); |
|
641 } |
|
642 } |
|
643 LeaveCriticalSection(&aCriticalSection); |
|
644 } |
|
645 } |
|
646 |
|
647 /***************************************************************************** |
|
648 * Allow debug messages. |
|
649 *****************************************************************************/ |
|
650 |
|
651 void |
|
652 Reporter::debugON ( void ) |
|
653 { |
|
654 if ( state & CPO_CONNECTED ) |
|
655 { |
|
656 EnterCriticalSection(&aCriticalSection); |
|
657 if ( !( state & RPT_DEBUG_ON ) ) |
|
658 { |
|
659 state += RPT_DEBUG_ON; |
|
660 debug ( "DEBUG messages will be processed" ); |
|
661 } |
|
662 LeaveCriticalSection(&aCriticalSection); |
|
663 } |
|
664 } |
|
665 |
|
666 /***************************************************************************** |
|
667 * Refuse debug messages. |
|
668 *****************************************************************************/ |
|
669 |
|
670 void |
|
671 Reporter::debugOFF ( void ) |
|
672 { |
|
673 if ( state & CPO_CONNECTED ) |
|
674 { |
|
675 EnterCriticalSection(&aCriticalSection); |
|
676 if ( state & RPT_DEBUG_ON ) |
|
677 { |
|
678 debug ( "DEBUG messages will not be processed" ); |
|
679 state -= RPT_DEBUG_ON; |
|
680 } |
|
681 LeaveCriticalSection(&aCriticalSection); |
|
682 } |
|
683 } |
|
684 |
|
685 /*************************************************************************** |
|
686 * Loads the contents of a message file into memory. |
|
687 ***************************************************************************/ |
|
688 |
|
689 void |
|
690 Reporter::load ( const char * file ) |
|
691 { |
|
692 if ( state & CPO_CONNECTED ) |
|
693 { |
|
694 EnterCriticalSection(&aCriticalSection); |
|
695 readMessageFile ( file ); |
|
696 if ( fileRead ) |
|
697 { |
|
698 debug ( "Messages loaded from %s", file ); |
|
699 } |
|
700 else |
|
701 { |
|
702 debug ( "No messages loaded from %s", file ); |
|
703 } |
|
704 |
|
705 #ifdef RPT_DEBUG_PROG |
|
706 if ( fileRead ) |
|
707 { |
|
708 for (int i=0;i<RPT_MAX_LIST_ENTRIES;i++) |
|
709 { |
|
710 if ( messageList [ i ] ) |
|
711 { |
|
712 (void) fprintf ( stdout, "%d : [%s] %d\n", |
|
713 i, messageList [ i ], |
|
714 strlen ( messageList [ i ] ) ); |
|
715 } |
|
716 } |
|
717 } |
|
718 #endif |
|
719 LeaveCriticalSection(&aCriticalSection); |
|
720 } |
|
721 } |
|
722 |
|
723 /***************************************************************************/ |