FlowError.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * @file FlowError.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * @section DESCRIPTION
  23. *
  24. * Flow error handling.
  25. */
  26. #ifndef BADVPN_FLOW_FLOWERROR_H
  27. #define BADVPN_FLOW_FLOWERROR_H
  28. #include <stdint.h>
  29. /**
  30. * Callback function invoked when {@link FlowErrorReporter_ReportError} is called.
  31. *
  32. * @param user value specified to {@link FlowErrorDomain_Init}
  33. * @param component identifier of the component reporting the error, as in
  34. * {@link FlowErrorReporter_Create}
  35. * @param code component-specific error data, as in {@link FlowErrorReporter_ReportError}
  36. */
  37. typedef void (*FlowErrorDomain_handler) (void *user, int component, int code);
  38. /**
  39. * Object used to report errors from multiple sources to the same error handler.
  40. */
  41. typedef struct {
  42. FlowErrorDomain_handler handler;
  43. void *user;
  44. } FlowErrorDomain;
  45. /**
  46. * Initializes the error domain.
  47. *
  48. * @param d the object
  49. * @param handler callback function invoked when {@link FlowErrorReporter_ReportError} is called
  50. * @param user value passed to callback functions
  51. */
  52. void FlowErrorDomain_Init (FlowErrorDomain *d, FlowErrorDomain_handler handler, void *user);
  53. /**
  54. * Structure that can be passed to flow components to ease error reporting.
  55. */
  56. typedef struct {
  57. FlowErrorDomain *domain;
  58. int component;
  59. } FlowErrorReporter;
  60. /**
  61. * Creates a {@link FlowErrorReporter} structure.
  62. *
  63. * @param domain error domain
  64. * @param component component identifier
  65. * @return a {@link FlowErrorReporter} structure with the specifed error domain and component.
  66. */
  67. FlowErrorReporter FlowErrorReporter_Create (FlowErrorDomain *domain, int component);
  68. /**
  69. * Reports an error.
  70. *
  71. * @param reporter a {@link FlowErrorReporter} structure containing the error domain and
  72. * component identifier user to report the error
  73. * @param code component-specific error data
  74. */
  75. void FlowErrorReporter_ReportError (FlowErrorReporter *reporter, int code);
  76. #endif