Skip to content

Commit

Permalink
[qrouting] added grp score, drouting sorting callback based, free shm…
Browse files Browse the repository at this point in the history
… memory for dialog_prop and trans_prop
  • Loading branch information
tallicamike authored and razvancrainea committed Feb 11, 2020
1 parent 121fd30 commit 888053b
Show file tree
Hide file tree
Showing 8 changed files with 349 additions and 63 deletions.
146 changes: 133 additions & 13 deletions modules/drouting/dr_cb.c
Expand Up @@ -61,8 +61,42 @@ static void destroy_dr_callbacks_list(struct dr_callback *cb)
}
}

void destroy_dr_cbs(int types) {
int i;
struct dr_callback *dr_sort_cb_it;

if(types & DRCB_REG_ADD_RULE || types & DRCB_REG_CR
|| types & DRCB_REG_GW || types & DRCB_REG_INIT_RULE) {
if(dr_reg_cbs && dr_reg_cbs != POINTER_CLOSED_MARKER) {
destroy_dr_callbacks_list(dr_reg_cbs->first);
shm_free(dr_reg_cbs);
}
dr_reg_cbs = POINTER_CLOSED_MARKER;
}
else if(types & DRCB_ACC_CALL) {
if(dr_acc_cbs && dr_acc_cbs != POINTER_CLOSED_MARKER) {
destroy_dr_callbacks_list(dr_acc_cbs->first);
shm_free(dr_acc_cbs);
}
dr_acc_cbs = POINTER_CLOSED_MARKER;
}
else if(types & DRCB_SORT_DST) {
for(i=0; i <N_MAX_SORT_CBS; i++) {
dr_sort_cb_it = dr_sort_cbs[i];
if(dr_sort_cb_it->callback_param_free && dr_sort_cb_it->param) {
dr_sort_cb_it->callback_param_free(dr_sort_cb_it->param);
dr_sort_cb_it->param = NULL;
}
}
}

}

void destroy_dr_cbs(void)
/*
* adds a given callback to a given callback list
*/
int insert_drcb(struct dr_head_cbl **dr_cb_list, struct dr_callback *cb,
int types)
{
int i;
struct dr_callback *dr_sort_cb_it;
Expand All @@ -80,8 +114,16 @@ void destroy_dr_cbs(void)
dr_sort_cb_it->param = NULL;
}
}
cb->next = (*dr_cb_list)->first;
(*dr_cb_list)->first = cb;
(*dr_cb_list)->types |= types;
return 0;
}

/* TODO: param will be the index in the array */
int register_dr_cb(int types, drouting_cb f, void *param,
param_free_cb ff) {
long int cb_sort_index = 0;

/* TODO: param will be the index in the array */
int register_dr_cb(enum drcb_types type, dr_cb f, void *param,
Expand All @@ -90,11 +132,49 @@ int register_dr_cb(enum drcb_types type, dr_cb f, void *param,
long int cb_sort_index = 0;
struct dr_callback *cb;

cb = (struct dr_callback*)shm_malloc(sizeof(struct dr_callback));
if (cb == 0) {
LM_ERR("no more shm memory\n");
return -1;
}
if((types != 0) && (types & (types-1)) == 0) { /* check that the type is a
power of two - only one
type of cb selected */
cb = (struct dr_callback*)shm_malloc(sizeof(struct dr_callback));
if(cb == 0) {
LM_ERR("no more shm memory\n");
return -1;
}

cb->types = types;
cb->callback = f;
if(!(types & DRCB_SORT_DST)) {
cb->param = param; /* because now param holds the type of the
sorting function */
} else {
cb->param = NULL;
}
cb->callback_param_free = ff;
cb->next = NULL;

if(types & DRCB_SORT_DST) {
if(param == NULL) {
LM_ERR("no index supplied for sort callback registered at dr\n");
return -1;
}
cb_sort_index = (long int)param;
if(cb_sort_index > N_MAX_SORT_CBS) {
LM_ERR("Sort cbs array not large enough to accomodate cb at dr\n");
return -1;
}
if(dr_sort_cbs[cb_sort_index] != NULL) {
LM_WARN("[dr] sort callback at index '%ld' will be overwritten\n",
cb_sort_index);
}
dr_sort_cbs[cb_sort_index] = cb;
} else if(types & DRCB_ACC_CALL) {
if(insert_drcb(&dr_acc_cbs, cb, types) == -1)
goto error;
} else if(types & (DRCB_REG_INIT_RULE | DRCB_REG_GW |
DRCB_REG_CR | DRCB_REG_ADD_RULE)) {
if(insert_drcb(&dr_reg_cbs, cb, types) == -1)
goto error;
}

cb->callback = f;
cb->callback_param_free = ff;
Expand Down Expand Up @@ -147,15 +227,55 @@ int run_dr_sort_cbs(sort_cb_type type, void *param)
return 0;
}

/* runs a callback from an array - sort_cb_type will represent
* the index within the array */
int run_indexed_callback(struct dr_callback **dr_sort_cbs_lst, sort_cb_type type,
void *params, int max_type) {
struct dr_cb_params *param = NULL;

int run_dr_cbs(enum drcb_types type, void *param)
{
struct dr_callback *it;
if(type > max_type) {
LM_WARN("No such '%d' callback exists\n", type);
return -1;
}

it = dr_cbs[type];
while(it) {
it->callback(param);
it = it->next;
if(dr_sort_cbs_lst[type] == NULL) {
LM_WARN("callback type '%d' not registered\n", type);
return -1;
}
if(params != NULL) {
param = (struct dr_cb_params *) shm_malloc(sizeof(struct dr_cb_params));
if(param == NULL) {
LM_ERR("no more shm memory\n");
return -1;
}
}
param->param = &params;
dr_sort_cbs_lst[type]->callback(0, param);
return 0;
}

int run_dr_cbs(struct dr_head_cbl *dr_cb_lst, int type, void *params) {
struct dr_callback * dr_cb_it;
struct dr_cb_params *param = NULL;
if(params != NULL) {
param = (struct dr_cb_params *) shm_malloc(sizeof(struct dr_cb_params));
if(param == NULL) {
LM_ERR("no more shm memory\n");
return -1;
}
}
if(dr_cb_lst != NULL && (dr_cb_lst->types & type)) {
dr_cb_it = dr_cb_lst->first;
while(dr_cb_it) {
if(dr_cb_it->types & type) {
param->param = &params;
dr_cb_it->callback(dr_cb_it->types, param);
}
dr_cb_it = dr_cb_it->next;
}
} else {
LM_WARN("No callback list to match the given type\n");
return -1;
}
return 0;
}
Expand Down
14 changes: 8 additions & 6 deletions modules/drouting/dr_cb.h
Expand Up @@ -19,14 +19,8 @@
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* History
* -------
* 2014-09-24 initial version (Mihai Tiganus)
* 2016-02-18 ported to 2.2 (bogdan)
*/


#ifndef _DR_CB_H_
#define _DR_CB_H_

Expand Down Expand Up @@ -61,6 +55,13 @@ struct dr_acc_call_params {
struct sip_msg *msg;
};

struct dr_sort_params {
pgw_list_t *pgwl; /* gws/cr to be sorted */
int size; /* the size of pgwl */
unsigned short *sorted_dst; /* returns an array with the indexes of the sorted dest */
int rc; /* return code for the funciton */
};



/* callback function prototype */
Expand All @@ -80,6 +81,7 @@ struct dr_callback {
dr_param_free_cb* callback_param_free;
struct dr_callback * next;
};
/* TODO: should i have a different structure for sort_callbacks */


/* sorting related data */
Expand Down

0 comments on commit 888053b

Please sign in to comment.