/quesa-1.8/Source/Core/Support/E3ErrorManager.c

# · C · 549 lines · 180 code · 208 blank · 161 comment · 36 complexity · 3ed8a4508f0a610856bcfae74a0a00c2 MD5 · raw file

  1. /* NAME:
  2. E3ErrorManager.c
  3. DESCRIPTION:
  4. Quesa error manager.
  5. The error manager maintains a set of callbacks to receive notification
  6. of errors, warnings, notices, and platform specific errors as they are
  7. generated by Quesa.
  8. COPYRIGHT:
  9. Copyright (c) 1999-2004, Quesa Developers. All rights reserved.
  10. For the current release of Quesa, please see:
  11. <http://www.quesa.org/>
  12. Redistribution and use in source and binary forms, with or without
  13. modification, are permitted provided that the following conditions
  14. are met:
  15. o Redistributions of source code must retain the above copyright
  16. notice, this list of conditions and the following disclaimer.
  17. o Redistributions in binary form must reproduce the above
  18. copyright notice, this list of conditions and the following
  19. disclaimer in the documentation and/or other materials provided
  20. with the distribution.
  21. o Neither the name of Quesa nor the names of its contributors
  22. may be used to endorse or promote products derived from this
  23. software without specific prior written permission.
  24. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  27. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  28. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  30. TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  31. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  32. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  33. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. ___________________________________________________________________________
  36. */
  37. //=============================================================================
  38. // Include files
  39. //-----------------------------------------------------------------------------
  40. #include "E3Prefix.h"
  41. #include "E3ErrorManager.h"
  42. //=============================================================================
  43. // Public functions
  44. //-----------------------------------------------------------------------------
  45. // E3ErrorManager_PostError : Post an error.
  46. //-----------------------------------------------------------------------------
  47. void
  48. E3ErrorManager_PostError(TQ3Error theError, TQ3Boolean isFatal)
  49. { E3GlobalsPtr theGlobals = E3Globals_Get();
  50. // Update our state
  51. if (theGlobals->errMgrOldestError == kQ3ErrorNone)
  52. theGlobals->errMgrOldestError = theError;
  53. theGlobals->errMgrIsFatalError = isFatal;
  54. theGlobals->errMgrLatestError = theError;
  55. // Call the handler
  56. if (theGlobals->errMgrHandlerFuncError != NULL)
  57. theGlobals->errMgrHandlerFuncError(theGlobals->errMgrOldestError,
  58. theGlobals->errMgrLatestError,
  59. theGlobals->errMgrHandlerDataError);
  60. }
  61. //=============================================================================
  62. // E3ErrorManager_PostWarning : Post a warning.
  63. //-----------------------------------------------------------------------------
  64. void
  65. E3ErrorManager_PostWarning(TQ3Warning theWarning)
  66. { E3GlobalsPtr theGlobals = E3Globals_Get();
  67. // Update our state
  68. if (theGlobals->errMgrOldestWarning == kQ3WarningNone)
  69. theGlobals->errMgrOldestWarning = theWarning;
  70. theGlobals->errMgrLatestWarning = theWarning;
  71. // Call the handler
  72. if (theGlobals->errMgrHandlerFuncWarning != NULL)
  73. theGlobals->errMgrHandlerFuncWarning(theGlobals->errMgrOldestWarning,
  74. theGlobals->errMgrLatestWarning,
  75. theGlobals->errMgrHandlerDataWarning);
  76. }
  77. //=============================================================================
  78. // E3ErrorManager_PostNotice : Post a notice.
  79. //-----------------------------------------------------------------------------
  80. void
  81. E3ErrorManager_PostNotice(TQ3Notice theNotice)
  82. { E3GlobalsPtr theGlobals = E3Globals_Get();
  83. // Update our state
  84. if (theGlobals->errMgrOldestNotice == kQ3NoticeNone)
  85. theGlobals->errMgrOldestNotice = theNotice;
  86. theGlobals->errMgrLatestNotice = theNotice;
  87. // Call the handler in debug builds (notices are not posted in release builds)
  88. #if Q3_DEBUG
  89. if (theGlobals->errMgrHandlerFuncNotice != NULL)
  90. theGlobals->errMgrHandlerFuncNotice(theGlobals->errMgrOldestNotice,
  91. theGlobals->errMgrLatestNotice,
  92. theGlobals->errMgrHandlerDataNotice);
  93. #endif
  94. }
  95. //=============================================================================
  96. // E3ErrorManager_PostPlatformError : Post a platform specific error.
  97. //-----------------------------------------------------------------------------
  98. void
  99. E3ErrorManager_PostPlatformError(TQ3Uns32 theError)
  100. { E3GlobalsPtr theGlobals = E3Globals_Get();
  101. // Update our state
  102. if (theGlobals->errMgrOldestPlatform == 0)
  103. theGlobals->errMgrOldestPlatform = theError;
  104. theGlobals->errMgrLatestPlatform = theError;
  105. // Post the platform specific error
  106. //
  107. // At present, we don't provide a public API for registering a platform
  108. // error handler - instead we follow the original QD3D model, where a
  109. // kQ3Error<Platform>Error is posted to the generic error handler.
  110. //
  111. // In preparation for a separate channel for platform specific errors,
  112. // we post the error directly to a platform handler if it's registered.
  113. // When this API is made public, apps will be able to listen directly
  114. // to platform specific errors.
  115. if (theGlobals->errMgrHandlerFuncPlatform != NULL)
  116. theGlobals->errMgrHandlerFuncPlatform((TQ3Error) theGlobals->errMgrOldestPlatform,
  117. (TQ3Error) theGlobals->errMgrLatestPlatform,
  118. theGlobals->errMgrHandlerDataPlatform);
  119. else
  120. E3ErrorManager_PostError(
  121. #if QUESA_OS_MACINTOSH
  122. kQ3ErrorMacintoshError,
  123. #elif QUESA_OS_WIN32
  124. kQ3ErrorWin32Error,
  125. #elif QUESA_OS_UNIX
  126. kQ3ErrorUnixError,
  127. #else
  128. kQ3ErrorPlatformError,
  129. #endif
  130. kQ3False);
  131. }
  132. //=============================================================================
  133. // E3ErrorManager_GetIsFatalError : Get as the last error was fatal.
  134. //-----------------------------------------------------------------------------
  135. TQ3Boolean
  136. E3ErrorManager_GetIsFatalError(TQ3Error theError)
  137. { E3GlobalsPtr theGlobals = E3Globals_Get();
  138. // Determine if the error is fatal or not
  139. if (theError == kQ3ErrorInternalError || theError == kQ3ErrorNoRecovery)
  140. return(kQ3True);
  141. // If this error isn't fatal, see if we've hit one which is
  142. return(theGlobals->errMgrIsFatalError);
  143. }
  144. //=============================================================================
  145. // E3ErrorManager_GetError : Get the oldest and latest errors.
  146. //-----------------------------------------------------------------------------
  147. // Note : Both our parameters are optional.
  148. //-----------------------------------------------------------------------------
  149. void
  150. E3ErrorManager_GetError(TQ3Error *oldestError, TQ3Error *latestError)
  151. { E3GlobalsPtr theGlobals = E3Globals_Get();
  152. // Return the requested state
  153. if (oldestError != NULL)
  154. *oldestError = theGlobals->errMgrOldestError;
  155. if (latestError != NULL)
  156. *latestError = theGlobals->errMgrLatestError;
  157. // Set our flags
  158. theGlobals->systemDoBottleneck = kQ3True;
  159. theGlobals->errMgrClearError = kQ3True;
  160. }
  161. //=============================================================================
  162. // E3ErrorManager_GetWarning : Get the oldest and latest warnings.
  163. //-----------------------------------------------------------------------------
  164. // Note : Both our parameters are optional.
  165. //-----------------------------------------------------------------------------
  166. void
  167. E3ErrorManager_GetWarning(TQ3Warning *oldestWarning, TQ3Warning *latestWarning)
  168. { E3GlobalsPtr theGlobals = E3Globals_Get();
  169. // Return the requested state
  170. if (oldestWarning != NULL)
  171. *oldestWarning = theGlobals->errMgrOldestWarning;
  172. if (latestWarning != NULL)
  173. *latestWarning = theGlobals->errMgrLatestWarning;
  174. // Set our flags
  175. theGlobals->systemDoBottleneck = kQ3True;
  176. theGlobals->errMgrClearWarning = kQ3True;
  177. }
  178. //=============================================================================
  179. // E3ErrorManager_GetNotice : Get the oldest and latest notices.
  180. //-----------------------------------------------------------------------------
  181. // Note : Both our parameters are optional.
  182. //-----------------------------------------------------------------------------
  183. void
  184. E3ErrorManager_GetNotice(TQ3Notice *oldestNotice, TQ3Notice *latestNotice)
  185. { E3GlobalsPtr theGlobals = E3Globals_Get();
  186. // Return the requested state
  187. if (oldestNotice != NULL)
  188. *oldestNotice = theGlobals->errMgrOldestNotice;
  189. if (latestNotice != NULL)
  190. *latestNotice = theGlobals->errMgrLatestNotice;
  191. // Set our flags
  192. theGlobals->systemDoBottleneck = kQ3True;
  193. theGlobals->errMgrClearNotice = kQ3True;
  194. }
  195. //=============================================================================
  196. // E3ErrorManager_GetPlatformError : Get the oldest and latest platform.
  197. //-----------------------------------------------------------------------------
  198. // Note : Both our parameters are optional.
  199. //-----------------------------------------------------------------------------
  200. void
  201. E3ErrorManager_GetPlatformError(TQ3Uns32 *oldestPlatform, TQ3Uns32 *latestPlatform)
  202. { E3GlobalsPtr theGlobals = E3Globals_Get();
  203. // Return the requested state
  204. if (oldestPlatform != NULL)
  205. *oldestPlatform = theGlobals->errMgrOldestPlatform;
  206. if (latestPlatform != NULL)
  207. *latestPlatform = theGlobals->errMgrLatestPlatform;
  208. // Set our flags
  209. theGlobals->systemDoBottleneck = kQ3True;
  210. theGlobals->errMgrClearPlatform = kQ3True;
  211. }
  212. //=============================================================================
  213. // E3ErrorManager_ClearError : Clear the error state.
  214. //-----------------------------------------------------------------------------
  215. void
  216. E3ErrorManager_ClearError(void)
  217. { E3GlobalsPtr theGlobals = E3Globals_Get();
  218. // Clear our state
  219. theGlobals->errMgrClearError = kQ3False;
  220. theGlobals->errMgrOldestError = kQ3ErrorNone;
  221. theGlobals->errMgrLatestError = kQ3ErrorNone;
  222. }
  223. //=============================================================================
  224. // E3ErrorManager_ClearWarning : Clear the warning state.
  225. //-----------------------------------------------------------------------------
  226. void
  227. E3ErrorManager_ClearWarning(void)
  228. { E3GlobalsPtr theGlobals = E3Globals_Get();
  229. // Clear our state
  230. theGlobals->errMgrClearWarning = kQ3False;
  231. theGlobals->errMgrOldestWarning = kQ3WarningNone;
  232. theGlobals->errMgrLatestWarning = kQ3WarningNone;
  233. }
  234. //=============================================================================
  235. // E3ErrorManager_ClearNotice : Clear the notice state.
  236. //-----------------------------------------------------------------------------
  237. void
  238. E3ErrorManager_ClearNotice(void)
  239. { E3GlobalsPtr theGlobals = E3Globals_Get();
  240. // Clear our state
  241. theGlobals->errMgrClearNotice = kQ3False;
  242. theGlobals->errMgrOldestNotice = kQ3NoticeNone;
  243. theGlobals->errMgrLatestNotice = kQ3NoticeNone;
  244. }
  245. //=============================================================================
  246. // E3ErrorManager_ClearPlatformError : Clear the platform error state.
  247. //-----------------------------------------------------------------------------
  248. void
  249. E3ErrorManager_ClearPlatformError(void)
  250. { E3GlobalsPtr theGlobals = E3Globals_Get();
  251. // Clear our state
  252. theGlobals->errMgrClearPlatform = kQ3False;
  253. theGlobals->errMgrOldestPlatform = 0;
  254. theGlobals->errMgrLatestPlatform = 0;
  255. }
  256. //=============================================================================
  257. // E3ErrorManager_GetCallback_Error : Get the error handler.
  258. //-----------------------------------------------------------------------------
  259. TQ3ErrorMethod
  260. E3ErrorManager_GetCallback_Error(void)
  261. { E3GlobalsPtr theGlobals = E3Globals_Get();
  262. // Return our callback
  263. return(theGlobals->errMgrHandlerFuncError);
  264. }
  265. //=============================================================================
  266. // E3ErrorManager_GetCallback_Warning : Get the warning handler.
  267. //-----------------------------------------------------------------------------
  268. TQ3WarningMethod
  269. E3ErrorManager_GetCallback_Warning(void)
  270. { E3GlobalsPtr theGlobals = E3Globals_Get();
  271. // Return our callback
  272. return(theGlobals->errMgrHandlerFuncWarning);
  273. }
  274. //=============================================================================
  275. // E3ErrorManager_GetCallback_Notice : Get the notice handler.
  276. //-----------------------------------------------------------------------------
  277. TQ3NoticeMethod
  278. E3ErrorManager_GetCallback_Notice(void)
  279. { E3GlobalsPtr theGlobals = E3Globals_Get();
  280. // Return our callback
  281. return(theGlobals->errMgrHandlerFuncNotice);
  282. }
  283. //=============================================================================
  284. // E3ErrorManager_GetCallback_PlatformError : Get the platform handler.
  285. //-----------------------------------------------------------------------------
  286. TQ3ErrorMethod
  287. E3ErrorManager_GetCallback_PlatformError(void)
  288. { E3GlobalsPtr theGlobals = E3Globals_Get();
  289. // Return our callback
  290. return(theGlobals->errMgrHandlerFuncPlatform);
  291. }
  292. //=============================================================================
  293. // E3ErrorManager_SetCallback_Error : Set the error handler.
  294. //-----------------------------------------------------------------------------
  295. void
  296. E3ErrorManager_SetCallback_Error(TQ3ErrorMethod theCallback, TQ3Uns32 theData)
  297. { E3GlobalsPtr theGlobals = E3Globals_Get();
  298. // Set our callback
  299. theGlobals->errMgrHandlerFuncError = theCallback;
  300. theGlobals->errMgrHandlerDataError = theData;
  301. }
  302. //=============================================================================
  303. // E3ErrorManager_SetCallback_Warning : Set the warning handler.
  304. //-----------------------------------------------------------------------------
  305. void
  306. E3ErrorManager_SetCallback_Warning(TQ3WarningMethod theCallback, TQ3Uns32 theData)
  307. { E3GlobalsPtr theGlobals = E3Globals_Get();
  308. // Set our callback
  309. theGlobals->errMgrHandlerFuncWarning = theCallback;
  310. theGlobals->errMgrHandlerDataWarning = theData;
  311. }
  312. //=============================================================================
  313. // E3ErrorManager_SetCallback_Notice : Set the notice handler.
  314. //-----------------------------------------------------------------------------
  315. void
  316. E3ErrorManager_SetCallback_Notice(TQ3NoticeMethod theCallback, TQ3Uns32 theData)
  317. { E3GlobalsPtr theGlobals = E3Globals_Get();
  318. // Set our callback
  319. theGlobals->errMgrHandlerFuncNotice = theCallback;
  320. theGlobals->errMgrHandlerDataNotice = theData;
  321. }
  322. //=============================================================================
  323. // E3ErrorManager_SetCallback_PlatformError : Set the platform handler.
  324. //-----------------------------------------------------------------------------
  325. void
  326. E3ErrorManager_SetCallback_PlatformError(TQ3ErrorMethod theCallback, TQ3Uns32 theData)
  327. { E3GlobalsPtr theGlobals = E3Globals_Get();
  328. // Set our callback
  329. theGlobals->errMgrHandlerFuncPlatform = theCallback;
  330. theGlobals->errMgrHandlerDataPlatform = theData;
  331. }