error_macros.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*************************************************************************/
  2. /* error_macros.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "error_macros.h"
  30. #include "os/os.h"
  31. bool _err_error_exists=false;
  32. static ErrorHandlerList *error_handler_list=NULL;
  33. void _err_set_last_error(const char* p_err) {
  34. OS::get_singleton()->set_last_error(p_err);
  35. }
  36. void _err_clear_last_error() {
  37. OS::get_singleton()->clear_last_error();
  38. }
  39. void add_error_handler(ErrorHandlerList *p_handler) {
  40. _global_lock();
  41. p_handler->next=error_handler_list;
  42. error_handler_list=p_handler;
  43. _global_unlock();
  44. }
  45. void remove_error_handler(ErrorHandlerList *p_handler) {
  46. _global_lock();
  47. ErrorHandlerList *prev = NULL;
  48. ErrorHandlerList *l = error_handler_list;
  49. while(l) {
  50. if (l==p_handler) {
  51. if (prev)
  52. prev->next=l->next;
  53. else
  54. error_handler_list=l->next;
  55. break;
  56. }
  57. prev=l;
  58. l=l->next;
  59. }
  60. _global_unlock();
  61. }
  62. void _err_print_error(const char* p_function, const char* p_file,int p_line,const char *p_error,ErrorHandlerType p_type) {
  63. OS::get_singleton()->print_error(p_function,p_file,p_line,p_error,_err_error_exists?OS::get_singleton()->get_last_error():"",(OS::ErrorType)p_type);
  64. _global_lock();
  65. ErrorHandlerList *l = error_handler_list;
  66. while(l) {
  67. l->errfunc(l->userdata,p_function,p_file,p_line,p_error,_err_error_exists?OS::get_singleton()->get_last_error():"",p_type);
  68. l=l->next;
  69. }
  70. _global_unlock();
  71. if (_err_error_exists) {
  72. OS::get_singleton()->clear_last_error();
  73. _err_error_exists=false;
  74. }
  75. }