qos_cb.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 #include "../../mem/shm_mem.h"
00030 #include "../../dprint.h"
00031 #include "qos_ctx_helpers.h"
00032 #include "qos_cb.h"
00033
00034 static struct qos_head_cbl* create_cbs = 0;
00035
00036 static struct qos_cb_params params = {NULL, NULL, 0, NULL};
00037
00038 int init_qos_callbacks(void)
00039 {
00040 create_cbs = (struct qos_head_cbl*)shm_malloc(sizeof(struct qos_head_cbl));
00041 if (create_cbs==0) {
00042 LM_ERR("no more shm mem\n");
00043 return -1;
00044 }
00045 create_cbs->first = 0;
00046 create_cbs->types = 0;
00047 return 0;
00048 }
00049
00050
00051 void destroy_qos_callbacks_list(struct qos_callback *cb)
00052 {
00053 struct qos_callback *cb_t;
00054
00055 while(cb) {
00056 cb_t = cb;
00057 cb = cb->next;
00058
00059 LM_DBG("freeing cp=%p\n", cb_t);
00060 shm_free(cb_t);
00061 }
00062 }
00063
00064
00065 void destroy_qos_callbacks(void)
00066 {
00067 if (create_cbs==0)
00068 return;
00069
00070 destroy_qos_callbacks_list(create_cbs->first);
00071 shm_free(create_cbs);
00072 create_cbs = 0;
00073 }
00074
00075
00076 int register_qoscb(qos_ctx_t *qos, int types, qos_cb f, void *param )
00077 {
00078 struct qos_callback *cb;
00079
00080 LM_DBG("registering qos CB\n");
00081
00082 if ( types&QOSCB_CREATED ) {
00083 if (types!=QOSCB_CREATED) {
00084 LM_CRIT("QOSCB_CREATED type must be register alone!\n");
00085 return -1;
00086 }
00087 } else {
00088 if (qos==0) {
00089 LM_CRIT("non-QOSCB_CREATED type "
00090 "must be register to a qos (qos missing)!\n");
00091 return -1;
00092 }
00093 }
00094 cb = (struct qos_callback*)shm_malloc(sizeof(struct qos_callback));
00095 if (cb==0) {
00096 LM_ERR("no more shm mem\n");
00097 return -1;
00098 }
00099
00100 LM_DBG("cb=%p\n", cb);
00101
00102 cb->types = types;
00103 cb->callback = f;
00104 cb->param = param;
00105
00106 if ( types&QOSCB_CREATED ) {
00107 cb->next = create_cbs->first;
00108 create_cbs->first = cb;
00109 create_cbs->types |= types;
00110 } else {
00111 cb->next = qos->cbs.first;
00112 qos->cbs.first = cb;
00113 qos->cbs.types |= types;
00114 LM_DBG("qos=%p qos->cbs=%p types=%d\n",
00115 qos, &(qos->cbs), qos->cbs.types);
00116 }
00117
00118 return 0;
00119 }
00120
00121
00122 void run_create_cbs(struct qos_ctx_st *qos, struct sip_msg *msg)
00123 {
00124 struct qos_callback *cb;
00125
00126 if (create_cbs->first==0)
00127 return;
00128
00129 params.msg = msg;
00130
00131 params.sdp = NULL;
00132 params.role = 0;
00133 params.param = NULL;
00134
00135 for ( cb=create_cbs->first; cb; cb=cb->next) {
00136 LM_DBG("qos=%p\n",qos);
00137 params.param = &cb->param;
00138 cb->callback( qos, QOSCB_CREATED, ¶ms );
00139 }
00140 return;
00141 }
00142
00143
00144 void run_qos_callbacks(int type, struct qos_ctx_st *qos,
00145 struct qos_sdp_st *sdp, unsigned int role,
00146 struct sip_msg *msg)
00147 {
00148 struct qos_callback *cb;
00149
00150 if (qos == NULL)
00151 return;
00152
00153 LM_DBG("qos=%p qos->cbs=%p, qos->cbs.types=%d\n",
00154 qos, &(qos->cbs), qos->cbs.types);
00155 if (qos->cbs.first==0 || ((qos->cbs.types)&type)==0 )
00156 return;
00157
00158 params.sdp = sdp;
00159 params.role = role;
00160 params.msg = msg;
00161
00162 LM_DBG("searching in %p\n", qos->cbs.first);
00163 for ( cb=qos->cbs.first; cb; cb=cb->next) {
00164 if ( (cb->types)&type ) {
00165 LM_DBG("qos=%p, type=%d\n", qos, type);
00166 params.param = &cb->param;
00167 cb->callback( qos, type, ¶ms );
00168 }
00169 }
00170 return;
00171 }