You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

events.h 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*-
  2. * Copyright 2016 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef RSPAMD_EVENTS_H
  17. #define RSPAMD_EVENTS_H
  18. #include "config.h"
  19. #include "mem_pool.h"
  20. struct rspamd_async_event;
  21. struct rspamd_async_session;
  22. typedef void (*event_finalizer_t)(gpointer ud);
  23. typedef gboolean (*session_finalizer_t)(gpointer user_data);
  24. /**
  25. * Make new async session
  26. * @param pool pool to alloc memory from
  27. * @param fin a callback called when no events are found in session
  28. * @param restore a callback is called to restore processing of session
  29. * @param cleanup a callback called when session is forcefully destroyed
  30. * @param user_data abstract user data
  31. * @return
  32. */
  33. struct rspamd_async_session * rspamd_session_create (rspamd_mempool_t *pool,
  34. session_finalizer_t fin, event_finalizer_t restore,
  35. event_finalizer_t cleanup, gpointer user_data);
  36. /**
  37. * Insert new event to the session
  38. * @param session session object
  39. * @param fin finalizer callback
  40. * @param user_data abstract user_data
  41. * @param forced unused
  42. */
  43. struct rspamd_async_event *
  44. rspamd_session_add_event_full (struct rspamd_async_session *session,
  45. event_finalizer_t fin,
  46. gpointer user_data,
  47. const gchar *subsystem,
  48. const gchar *loc);
  49. #define rspamd_session_add_event(session, fin, user_data, subsystem) \
  50. rspamd_session_add_event_full(session, fin, user_data, subsystem, G_STRLOC)
  51. /**
  52. * Remove normal event
  53. * @param session session object
  54. * @param fin final callback
  55. * @param ud user data object
  56. */
  57. void rspamd_session_remove_event_full (struct rspamd_async_session *session,
  58. event_finalizer_t fin,
  59. gpointer ud,
  60. const gchar *loc);
  61. #define rspamd_session_remove_event(session, fin, user_data) \
  62. rspamd_session_remove_event_full(session, fin, user_data, G_STRLOC)
  63. /**
  64. * Must be called at the end of session, it calls fin functions for all non-forced callbacks
  65. * @return true if the whole session was destroyed and false if there are forced events
  66. */
  67. gboolean rspamd_session_destroy (struct rspamd_async_session *session);
  68. /**
  69. * Try to remove all events pending
  70. */
  71. void rspamd_session_cleanup (struct rspamd_async_session *session);
  72. /**
  73. * Returns mempool associated with async session
  74. * @param session
  75. * @return
  76. */
  77. rspamd_mempool_t * rspamd_session_mempool (struct rspamd_async_session *session);
  78. /**
  79. * Check session for events pending and call fin callback if no events are pending
  80. * @param session session object
  81. * @return TRUE if session has pending events
  82. */
  83. gboolean rspamd_session_pending (struct rspamd_async_session *session);
  84. /**
  85. * Returns number of events pending
  86. * @param session
  87. * @return
  88. */
  89. guint rspamd_session_events_pending (struct rspamd_async_session *session);
  90. /**
  91. * Returns TRUE if an async session is currently destroying
  92. * @param s
  93. * @return
  94. */
  95. gboolean rspamd_session_blocked (struct rspamd_async_session *s);
  96. #endif /* RSPAMD_EVENTS_H */