pua_callback.c

Go to the documentation of this file.
00001 /*
00002  * $Id: pua_callback.c,v 1.2 2007/02/20 13:40:09 anca_vamanu Exp $
00003  *
00004  * pua module - presence user agent module
00005  *
00006  * Copyright (C) 2007 Voice Sistem S.R.L.
00007  *
00008  * This file is part of Kamailio, a free SIP server.
00009  *
00010  * Kamailio is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version
00014  *
00015  * Kamailio is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License 
00021  * along with this program; if not, write to the Free Software 
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  */
00024 
00025 
00026 #include "../../dprint.h"
00027 #include "../../error.h"
00028 #include "../../mem/shm_mem.h"
00029 #include "pua_callback.h"
00030 
00031 
00032 struct puacb_head_list* puacb_list = 0;
00033 
00034 int init_puacb_list(void)
00035 {
00036    puacb_list = (struct puacb_head_list*)shm_malloc
00037       ( sizeof(struct puacb_head_list) );
00038    if (puacb_list==0)
00039    {
00040       LM_CRIT("no more shared mem\n");
00041       return -1;
00042    }
00043    puacb_list->first = 0;
00044    puacb_list->reg_types = 0;
00045    return 1;
00046 }
00047 
00048 
00049 void destroy_puacb_list(void)
00050 {
00051    struct pua_callback *cbp, *cbp_tmp;
00052 
00053    if (!puacb_list)
00054       return;
00055 
00056    for( cbp=puacb_list->first; cbp ; )
00057    {
00058       cbp_tmp = cbp;
00059       cbp = cbp->next;
00060       if (cbp_tmp->param) 
00061          shm_free( cbp_tmp->param );
00062       shm_free( cbp_tmp );
00063    }
00064    shm_free(puacb_list);
00065 }
00066 
00067 
00068 
00069 /* register a callback function 'f' for 'types' mask of events;
00070 */
00071 int register_puacb( int types, pua_cb f, void* param )
00072 {
00073    struct pua_callback *cbp;
00074 
00075    /* are the callback types valid?... */
00076    if ( types<0 || types>PUACB_MAX ) 
00077    {
00078       LM_CRIT("invalid callback types: mask=%d\n",types);
00079       return E_BUG;
00080    }
00081    /* we don't register null functions */
00082    if (f==0)
00083    {
00084       LM_CRIT("null callback function\n");
00085       return E_BUG;
00086    }
00087 
00088    /* build a new callback structure */
00089    if (!(cbp=(struct pua_callback*)shm_malloc(sizeof( struct pua_callback)))) 
00090    {
00091       LM_ERR("out of share mem\n");
00092       return E_OUT_OF_MEM;
00093    }
00094 
00095    /* link it into the proper place... */
00096    cbp->next = puacb_list->first;
00097    puacb_list->first = cbp;
00098    puacb_list->reg_types |= types;
00099 
00100    cbp->callback = f;
00101     cbp->param= param;
00102    cbp->types = types;
00103    if (cbp->next)
00104       cbp->id = cbp->next->id+1;
00105    else
00106       cbp->id = 0;
00107 
00108    return 1;
00109 }
00110 

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