ul_callback.h

Go to the documentation of this file.
00001 /*
00002  * $Id: ul_callback.h 5003 2008-09-26 11:01:51Z henningw $
00003  *
00004  * Copyright (C) 2001-2003 FhG Fokus
00005  *
00006  * This file is part of Kamailio, a free SIP server.
00007  *
00008  * Kamailio is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * Kamailio is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License 
00019  * along with this program; if not, write to the Free Software 
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  * History:
00023  * --------
00024  *  2004-03-16  created (bogdan)
00025  */
00026 
00027 /*! \file
00028  *  \brief USRLOC - Module callbacks
00029  *  \ingroup usrloc
00030  */
00031 
00032 #ifndef _UL_CALLBACKS_H
00033 #define _UL_CALLBACKS_H
00034 
00035 #include "ucontact.h"
00036 
00037 
00038 #define UL_CONTACT_INSERT      (1<<0)
00039 #define UL_CONTACT_UPDATE      (1<<1)
00040 #define UL_CONTACT_DELETE      (1<<2)
00041 #define UL_CONTACT_EXPIRE      (1<<3)
00042 #define ULCB_MAX               ((1<<4)-1)
00043 
00044 /*! \brief callback function prototype */
00045 typedef void (ul_cb) (ucontact_t *c, int type, void *param);
00046 /*! \brief register callback function prototype */
00047 typedef int (*register_ulcb_t)( int cb_types, ul_cb f, void *param);
00048 
00049 
00050 struct ul_callback {
00051    int id;                      /*!< id of this callback - useless */
00052    int types;                   /*!< types of events that trigger the callback*/
00053    ul_cb* callback;             /*!< callback function */
00054    void *param;                 /*!< param to be passed to callback function */
00055    struct ul_callback* next;
00056 };
00057 
00058 struct ulcb_head_list {
00059    struct ul_callback *first;
00060    int reg_types;
00061 };
00062 
00063 
00064 extern struct ulcb_head_list*  ulcb_list;
00065 
00066 
00067 #define exists_ulcb_type(_types_) \
00068    ( (ulcb_list->reg_types)|(_types_) )
00069 
00070 
00071 int init_ulcb_list(void);
00072 
00073 void destroy_ulcb_list(void);
00074 
00075 
00076 /*! \brief register a callback for several types of events */
00077 int register_ulcb( int types, ul_cb f, void *param );
00078 
00079 /*! \brief run all transaction callbacks for an event type */
00080 static inline void run_ul_callbacks( int type , ucontact_t *c)
00081 {
00082    struct ul_callback *cbp;
00083 
00084    for (cbp=ulcb_list->first; cbp; cbp=cbp->next)  {
00085       if(cbp->types&type) {
00086          LM_DBG("contact=%p, callback type %d/%d, id %d entered\n",
00087             c, type, cbp->types, cbp->id );
00088          cbp->callback( c, type, cbp->param );
00089       }
00090    }
00091 }
00092 
00093 
00094 
00095 #endif

Generated on Thu May 24 22:00:35 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6