WDEBUG.CPP 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. ** Command & Conquer Red Alert(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. #include <stdlib.h>
  19. #include "wdebug.h"
  20. #include "streamer.h"
  21. #include "odevice.h"
  22. static MsgManager *msg_manager=NULL;
  23. static int debug_enabled=0;
  24. static ostream *debug_ostream=NULL;
  25. static Streamer debug_streamer;
  26. static int info_enabled=0;
  27. static ostream *info_ostream=NULL;
  28. static Streamer info_streamer;
  29. static int warn_enabled=0;
  30. static ostream *warn_ostream=NULL;
  31. static Streamer warn_streamer;
  32. static int error_enabled=0;
  33. static ostream *error_ostream=NULL;
  34. static Streamer error_streamer;
  35. // Don't dare touch this semaphore in application code!
  36. Sem4 DebugLibSemaphore;
  37. int MsgManager::setAllStreams(OutputDevice *device)
  38. {
  39. if (device==NULL)
  40. return(1);
  41. DebugLibSemaphore.Wait();
  42. debug_streamer.setOutputDevice(device);
  43. delete(debug_ostream);
  44. debug_ostream=new ostream(&debug_streamer);
  45. info_streamer.setOutputDevice(device);
  46. delete(info_ostream);
  47. info_ostream=new ostream(&info_streamer);
  48. warn_streamer.setOutputDevice(device);
  49. delete(warn_ostream);
  50. warn_ostream=new ostream(&warn_streamer);
  51. error_streamer.setOutputDevice(device);
  52. delete(error_ostream);
  53. error_ostream=new ostream(&error_streamer);
  54. DebugLibSemaphore.Post();
  55. return(0);
  56. }
  57. int MsgManager::setDebugStream(OutputDevice *device)
  58. {
  59. if (device==NULL)
  60. return(1);
  61. DebugLibSemaphore.Wait();
  62. debug_streamer.setOutputDevice(device);
  63. delete(debug_ostream);
  64. debug_ostream=new ostream(&debug_streamer);
  65. DebugLibSemaphore.Post();
  66. return(0);
  67. }
  68. int MsgManager::setInfoStream(OutputDevice *device)
  69. {
  70. if (device==NULL)
  71. return(1);
  72. DebugLibSemaphore.Wait();
  73. info_streamer.setOutputDevice(device);
  74. delete(info_ostream);
  75. info_ostream=new ostream(&info_streamer);
  76. DebugLibSemaphore.Post();
  77. return(0);
  78. }
  79. int MsgManager::setWarnStream(OutputDevice *device)
  80. {
  81. if (device==NULL)
  82. return(1);
  83. DebugLibSemaphore.Wait();
  84. warn_streamer.setOutputDevice(device);
  85. delete(warn_ostream);
  86. warn_ostream=new ostream(&warn_streamer);
  87. DebugLibSemaphore.Post();
  88. return(0);
  89. }
  90. int MsgManager::setErrorStream(OutputDevice *device)
  91. {
  92. if (device==NULL)
  93. return(1);
  94. DebugLibSemaphore.Wait();
  95. error_streamer.setOutputDevice(device);
  96. delete(error_ostream);
  97. error_ostream=new ostream(&error_streamer);
  98. DebugLibSemaphore.Post();
  99. return(0);
  100. }
  101. ostream *MsgManager::debugStream(void)
  102. {
  103. return(debug_ostream);
  104. }
  105. ostream *MsgManager::infoStream(void)
  106. {
  107. return(info_ostream);
  108. }
  109. ostream *MsgManager::warnStream(void)
  110. {
  111. return(warn_ostream);
  112. }
  113. ostream *MsgManager::errorStream(void)
  114. {
  115. return(error_ostream);
  116. }