ul_callback.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <stdlib.h>
00036
00037 #include "../../dprint.h"
00038 #include "../../error.h"
00039 #include "../../mem/shm_mem.h"
00040 #include "ul_callback.h"
00041
00042
00043 struct ulcb_head_list* ulcb_list = 0;
00044
00045
00046
00047 int init_ulcb_list(void)
00048 {
00049 ulcb_list = (struct ulcb_head_list*)shm_malloc
00050 ( sizeof(struct ulcb_head_list) );
00051 if (ulcb_list==0) {
00052 LM_CRIT("no more shared mem\n");
00053 return -1;
00054 }
00055 ulcb_list->first = 0;
00056 ulcb_list->reg_types = 0;
00057 return 1;
00058 }
00059
00060
00061 void destroy_ulcb_list(void)
00062 {
00063 struct ul_callback *cbp, *cbp_tmp;
00064
00065 if (!ulcb_list)
00066 return;
00067
00068 for( cbp=ulcb_list->first; cbp ; ) {
00069 cbp_tmp = cbp;
00070 cbp = cbp->next;
00071 if (cbp_tmp->param) shm_free( cbp_tmp->param );
00072 shm_free( cbp_tmp );
00073 }
00074
00075 shm_free(ulcb_list);
00076 }
00077
00078
00079
00080
00081
00082
00083 int register_ulcb( int types, ul_cb f, void *param )
00084 {
00085 struct ul_callback *cbp;
00086
00087
00088 if ( types<0 || types>ULCB_MAX ) {
00089 LM_CRIT("invalid callback types: mask=%d\n",types);
00090 return E_BUG;
00091 }
00092
00093 if (f==0) {
00094 LM_CRIT("null callback function\n");
00095 return E_BUG;
00096 }
00097
00098
00099 if (!(cbp=(struct ul_callback*)shm_malloc(sizeof( struct ul_callback)))) {
00100 LM_ERR("no more share mem\n");
00101 return E_OUT_OF_MEM;
00102 }
00103
00104
00105 cbp->next = ulcb_list->first;
00106 ulcb_list->first = cbp;
00107 ulcb_list->reg_types |= types;
00108
00109 cbp->callback = f;
00110 cbp->param = param;
00111 cbp->types = types;
00112 if (cbp->next)
00113 cbp->id = cbp->next->id+1;
00114 else
00115 cbp->id = 0;
00116
00117 return 1;
00118 }
00119
00120
00121