/contrib/bind9/lib/isc/include/isc/event.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 121 lines · 45 code · 18 blank · 58 comment · 1 complexity · cc9a414b81ec50a282b27449ddb7c727 MD5 · raw file

  1. /*
  2. * Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC")
  3. * Copyright (C) 1998-2002 Internet Software Consortium.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  10. * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  11. * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  12. * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  13. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  14. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. * PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. /* $Id: event.h,v 1.34 2007/06/19 23:47:18 tbox Exp $ */
  18. #ifndef ISC_EVENT_H
  19. #define ISC_EVENT_H 1
  20. /*! \file isc/event.h */
  21. #include <isc/lang.h>
  22. #include <isc/types.h>
  23. /*****
  24. ***** Events.
  25. *****/
  26. typedef void (*isc_eventdestructor_t)(isc_event_t *);
  27. #define ISC_EVENT_COMMON(ltype) \
  28. size_t ev_size; \
  29. unsigned int ev_attributes; \
  30. void * ev_tag; \
  31. isc_eventtype_t ev_type; \
  32. isc_taskaction_t ev_action; \
  33. void * ev_arg; \
  34. void * ev_sender; \
  35. isc_eventdestructor_t ev_destroy; \
  36. void * ev_destroy_arg; \
  37. ISC_LINK(ltype) ev_link
  38. /*%
  39. * Attributes matching a mask of 0x000000ff are reserved for the task library's
  40. * definition. Attributes of 0xffffff00 may be used by the application
  41. * or non-ISC libraries.
  42. */
  43. #define ISC_EVENTATTR_NOPURGE 0x00000001
  44. /*%
  45. * The ISC_EVENTATTR_CANCELED attribute is intended to indicate
  46. * that an event is delivered as a result of a canceled operation
  47. * rather than successful completion, by mutual agreement
  48. * between the sender and receiver. It is not set or used by
  49. * the task system.
  50. */
  51. #define ISC_EVENTATTR_CANCELED 0x00000002
  52. #define ISC_EVENT_INIT(event, sz, at, ta, ty, ac, ar, sn, df, da) \
  53. do { \
  54. (event)->ev_size = (sz); \
  55. (event)->ev_attributes = (at); \
  56. (event)->ev_tag = (ta); \
  57. (event)->ev_type = (ty); \
  58. (event)->ev_action = (ac); \
  59. (event)->ev_arg = (ar); \
  60. (event)->ev_sender = (sn); \
  61. (event)->ev_destroy = (df); \
  62. (event)->ev_destroy_arg = (da); \
  63. ISC_LINK_INIT((event), ev_link); \
  64. } while (0)
  65. /*%
  66. * This structure is public because "subclassing" it may be useful when
  67. * defining new event types.
  68. */
  69. struct isc_event {
  70. ISC_EVENT_COMMON(struct isc_event);
  71. };
  72. #define ISC_EVENTTYPE_FIRSTEVENT 0x00000000
  73. #define ISC_EVENTTYPE_LASTEVENT 0xffffffff
  74. #define ISC_EVENT_PTR(p) ((isc_event_t **)(void *)(p))
  75. ISC_LANG_BEGINDECLS
  76. isc_event_t *
  77. isc_event_allocate(isc_mem_t *mctx, void *sender, isc_eventtype_t type,
  78. isc_taskaction_t action, const void *arg, size_t size);
  79. /*%<
  80. * Allocate an event structure.
  81. *
  82. * Allocate and initialize in a structure with initial elements
  83. * defined by:
  84. *
  85. * \code
  86. * struct {
  87. * ISC_EVENT_COMMON(struct isc_event);
  88. * ...
  89. * };
  90. * \endcode
  91. *
  92. * Requires:
  93. *\li 'size' >= sizeof(struct isc_event)
  94. *\li 'action' to be non NULL
  95. *
  96. * Returns:
  97. *\li a pointer to a initialized structure of the requested size.
  98. *\li NULL if unable to allocate memory.
  99. */
  100. void
  101. isc_event_free(isc_event_t **);
  102. ISC_LANG_ENDDECLS
  103. #endif /* ISC_EVENT_H */