modules_k/usrloc/ul_callback.h

Go to the documentation of this file.
00001 /*
00002  * $Id$
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 
00032 #ifndef _UL_CALLBACKS_H
00033 #define _UL_CALLBACKS_H
00034 
00035 #include "../../dprint.h"
00036 
00037 /* forward declaration for ucontact_t */
00038 struct ucontact;
00039 
00040 #define UL_CONTACT_INSERT      (1<<0)
00041 #define UL_CONTACT_UPDATE      (1<<1)
00042 #define UL_CONTACT_DELETE      (1<<2)
00043 #define UL_CONTACT_EXPIRE      (1<<3)
00044 #define ULCB_MAX               ((1<<4)-1)
00045 
00047 typedef void (ul_cb) (struct ucontact *c, int type, void *param);
00049 typedef int (*register_ulcb_t)( int cb_types, ul_cb f, void *param);
00050 
00051 
00052 struct ul_callback {
00053         int id;                      
00054         int types;                   
00055         ul_cb* callback;             
00056         void *param;                 
00057         struct ul_callback* next;
00058 };
00059 
00060 struct ulcb_head_list {
00061         struct ul_callback *first;
00062         int reg_types;
00063 };
00064 
00065 
00066 extern struct ulcb_head_list*  ulcb_list;
00067 
00068 
00069 #define exists_ulcb_type(_types_) \
00070         ( (ulcb_list->reg_types)|(_types_) )
00071 
00072 
00073 int init_ulcb_list(void);
00074 
00075 void destroy_ulcb_list(void);
00076 
00077 
00079 int register_ulcb( int types, ul_cb f, void *param );
00080 
00082 static inline void run_ul_callbacks( int type , struct ucontact *c)
00083 {
00084         struct ul_callback *cbp;
00085 
00086         for (cbp=ulcb_list->first; cbp; cbp=cbp->next)  {
00087                 if(cbp->types&type) {
00088                         LM_DBG("contact=%p, callback type %d/%d, id %d entered\n",
00089                                 c, type, cbp->types, cbp->id );
00090                         cbp->callback( c, type, cbp->param );
00091                 }
00092         }
00093 }
00094 
00095 
00096 
00097 #endif