1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
/*
* $Id$
*
* Copyright (C) 2007 SOMA Networks, Inc.
* Written by Ovidiu Sas (osas)
*
* This file is part of Kamailio, a free SIP server.
*
* Kamailio is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
* Kamailio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* History:
* --------
* 2007-07-14 initial version (osas)
*/
#include "../../mem/shm_mem.h"
#include "../../dprint.h"
#include "qos_ctx_helpers.h"
#include "qos_cb.h"
static struct qos_head_cbl* create_cbs = 0;
static struct qos_cb_params params = {NULL, NULL, 0, NULL};
int init_qos_callbacks(void)
{
create_cbs = (struct qos_head_cbl*)shm_malloc(sizeof(struct qos_head_cbl));
if (create_cbs==0) {
LM_ERR("no more shm mem\n");
return -1;
}
create_cbs->first = 0;
create_cbs->types = 0;
return 0;
}
void destroy_qos_callbacks_list(struct qos_callback *cb)
{
struct qos_callback *cb_t;
while(cb) {
cb_t = cb;
cb = cb->next;
/* FIXME - what about parameters ? */
LM_DBG("freeing cp=%p\n", cb_t);
shm_free(cb_t);
}
}
void destroy_qos_callbacks(void)
{
if (create_cbs==0)
return;
destroy_qos_callbacks_list(create_cbs->first);
shm_free(create_cbs);
create_cbs = 0;
}
int register_qoscb(qos_ctx_t *qos, int types, qos_cb f, void *param )
{
struct qos_callback *cb;
LM_DBG("registering qos CB\n");
if ( types&QOSCB_CREATED ) {
if (types!=QOSCB_CREATED) {
LM_CRIT("QOSCB_CREATED type must be register alone!\n");
return -1;
}
} else {
if (qos==0) {
LM_CRIT("non-QOSCB_CREATED type "
"must be register to a qos (qos missing)!\n");
return -1;
}
}
cb = (struct qos_callback*)shm_malloc(sizeof(struct qos_callback));
if (cb==0) {
LM_ERR("no more shm mem\n");
return -1;
}
LM_DBG("cb=%p\n", cb);
cb->types = types;
cb->callback = f;
cb->param = param;
if ( types&QOSCB_CREATED ) {
cb->next = create_cbs->first;
create_cbs->first = cb;
create_cbs->types |= types;
} else {
cb->next = qos->cbs.first;
qos->cbs.first = cb;
qos->cbs.types |= types;
LM_DBG("qos=%p qos->cbs=%p types=%d\n",
qos, &(qos->cbs), qos->cbs.types);
}
return 0;
}
void run_create_cbs(struct qos_ctx_st *qos, struct sip_msg *msg)
{
struct qos_callback *cb;
if (create_cbs->first==0)
return;
params.msg = msg;
/* avoid garbage due static structure */
params.sdp = NULL;
params.role = 0;
params.param = NULL;
for ( cb=create_cbs->first; cb; cb=cb->next) {
LM_DBG("qos=%p\n",qos);
params.param = &cb->param;
cb->callback( qos, QOSCB_CREATED, ¶ms );
}
return;
}
void run_qos_callbacks(int type, struct qos_ctx_st *qos,
struct qos_sdp_st *sdp, unsigned int role,
struct sip_msg *msg)
{
struct qos_callback *cb;
if (qos == NULL)
return;
LM_DBG("qos=%p qos->cbs=%p, qos->cbs.types=%d\n",
qos, &(qos->cbs), qos->cbs.types);
if (qos->cbs.first==0 || ((qos->cbs.types)&type)==0 )
return;
params.sdp = sdp;
params.role = role;
params.msg = msg;
LM_DBG("searching in %p\n", qos->cbs.first);
for ( cb=qos->cbs.first; cb; cb=cb->next) {
if ( (cb->types)&type ) {
LM_DBG("qos=%p, type=%d\n", qos, type);
params.param = &cb->param;
cb->callback( qos, type, ¶ms );
}
}
return;
}
|