ul_callback.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2003 FhG Fokus
  5. *
  6. * This file is part of Kamailio, a free SIP server.
  7. *
  8. * Kamailio is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version
  12. *
  13. * Kamailio 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
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * History:
  23. * --------
  24. * 2004-03-16 created (bogdan)
  25. */
  26. /*! \file
  27. * \brief USRLOC - Module callbacks
  28. * \ingroup usrloc
  29. */
  30. #ifndef _UL_CALLBACKS_H
  31. #define _UL_CALLBACKS_H
  32. #include "../../dprint.h"
  33. /* forward declaration for ucontact_t */
  34. struct ucontact;
  35. #define UL_CONTACT_INSERT (1<<0)
  36. #define UL_CONTACT_UPDATE (1<<1)
  37. #define UL_CONTACT_DELETE (1<<2)
  38. #define UL_CONTACT_EXPIRE (1<<3)
  39. #define ULCB_MAX ((1<<4)-1)
  40. /*! \brief callback function prototype */
  41. typedef void (ul_cb) (struct ucontact *c, int type, void *param);
  42. /*! \brief register callback function prototype */
  43. typedef int (*register_ulcb_t)( int cb_types, ul_cb f, void *param);
  44. struct ul_callback {
  45. int id; /*!< id of this callback - useless */
  46. int types; /*!< types of events that trigger the callback*/
  47. ul_cb* callback; /*!< callback function */
  48. void *param; /*!< param to be passed to callback function */
  49. struct ul_callback* next;
  50. };
  51. struct ulcb_head_list {
  52. struct ul_callback *first;
  53. int reg_types;
  54. };
  55. extern struct ulcb_head_list* ulcb_list;
  56. #define exists_ulcb_type(_types_) \
  57. ( (ulcb_list->reg_types)&(_types_) )
  58. int init_ulcb_list(void);
  59. void destroy_ulcb_list(void);
  60. /*! \brief register a callback for several types of events */
  61. int register_ulcb( int types, ul_cb f, void *param );
  62. /*! \brief run all transaction callbacks for an event type */
  63. static inline void run_ul_callbacks( int type , struct ucontact *c)
  64. {
  65. struct ul_callback *cbp;
  66. for (cbp=ulcb_list->first; cbp; cbp=cbp->next) {
  67. if(cbp->types&type) {
  68. LM_DBG("contact=%p, callback type %d/%d, id %d entered\n",
  69. c, type, cbp->types, cbp->id );
  70. cbp->callback( c, type, cbp->param );
  71. }
  72. }
  73. }
  74. #endif