modules_s/usrloc/ul_callback.h

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