ul_callback.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2003 FhG Fokus
  5. *
  6. * This file is part of ser, a free SIP server.
  7. *
  8. * ser 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. * For a license to use the ser software under conditions
  14. * other than those described here, or to purchase support for this
  15. * software, please contact iptel.org by e-mail at the following addresses:
  16. * [email protected]
  17. *
  18. * ser is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  26. *
  27. * History:
  28. * --------
  29. * 2004-03-16 created (bogdan)
  30. */
  31. #ifndef _UL_CALLBACKS_H
  32. #define _UL_CALLBACKS_H
  33. #include "ucontact.h"
  34. #define UL_CONTACT_INSERT (1<<0)
  35. #define UL_CONTACT_UPDATE (1<<1)
  36. #define UL_CONTACT_DELETE (1<<2)
  37. #define UL_CONTACT_EXPIRE (1<<3)
  38. #define ULCB_MAX ((1<<4)-1)
  39. /* callback function prototype */
  40. typedef void (ul_cb) (ucontact_t *c, int type, void *param);
  41. /* register callback function prototype */
  42. typedef int (*register_ulcb_t)( int cb_types, ul_cb f, void *param);
  43. struct ul_callback {
  44. int id; /* id of this callback - useless */
  45. int types; /* types of events that trigger the callback*/
  46. ul_cb* callback; /* callback function */
  47. void *param; /* param to be passed to callback function */
  48. struct ul_callback* next;
  49. };
  50. struct ulcb_head_list {
  51. struct ul_callback *first;
  52. int reg_types;
  53. };
  54. extern struct ulcb_head_list* ulcb_list;
  55. #define exists_ulcb_type(_types_) \
  56. ( (ulcb_list->reg_types)|(_types_) )
  57. int init_ulcb_list();
  58. void destroy_ulcb_list();
  59. /* register a callback for several types of events */
  60. int register_ulcb( int types, ul_cb f, void *param );
  61. /* run all transaction callbacks for an event type */
  62. static inline void run_ul_callbacks( int type , ucontact_t *c)
  63. {
  64. struct ul_callback *cbp;
  65. for (cbp=ulcb_list->first; cbp; cbp=cbp->next) {
  66. DBG("DBG:usrloc: contact=%p, callback type %d, id %d entered\n",
  67. c, cbp->types, cbp->id );
  68. cbp->callback( c, type, cbp->param );
  69. }
  70. }
  71. #endif