Skip to content
Snippets Groups Projects
Commit 9fc2cc17 authored by Joshua Colp's avatar Joshua Colp
Browse files

framehooks: Re-iterate if framehook provides different frame.

Framehooks can be used in a reactive manner to execute specific logic
when a frame is received with a certain type and payload. Since it is
possible for framehooks to provide frames it was possible for this
reactive framehook to be unaware of frames it is looking for.

This change makes it so that when framehooks return a modified frame
the code will now re-iterate (from the beginning) and call any
previous framehooks that have not provided a modified frame themselves.

Review: https://reviewboard.asterisk.org/r/3046/
........

Merged revisions 404027 from http://svn.asterisk.org/svn/asterisk/branches/12


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@404028 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent 27f37f6e
No related branches found
No related tags found
No related merge requests found
...@@ -49,6 +49,9 @@ struct ast_framehook { ...@@ -49,6 +49,9 @@ struct ast_framehook {
}; };
struct ast_framehook_list { struct ast_framehook_list {
/*! the number of hooks currently present */
unsigned int count;
/*! id for next framehook added */
unsigned int id_count; unsigned int id_count;
AST_LIST_HEAD_NOLOCK(, ast_framehook) list; AST_LIST_HEAD_NOLOCK(, ast_framehook) list;
}; };
...@@ -73,21 +76,49 @@ static void framehook_detach_and_destroy(struct ast_framehook *framehook) ...@@ -73,21 +76,49 @@ static void framehook_detach_and_destroy(struct ast_framehook *framehook)
static struct ast_frame *framehook_list_push_event(struct ast_framehook_list *framehooks, struct ast_frame *frame, enum ast_framehook_event event) static struct ast_frame *framehook_list_push_event(struct ast_framehook_list *framehooks, struct ast_frame *frame, enum ast_framehook_event event)
{ {
struct ast_framehook *framehook; struct ast_framehook *framehook;
struct ast_frame *original_frame;
int *skip;
size_t skip_size;
if (!framehooks) { if (!framehooks) {
return frame; return frame;
} }
AST_LIST_TRAVERSE_SAFE_BEGIN(&framehooks->list, framehook, list) { skip_size = sizeof(int) * framehooks->count;
if (framehook->detach_and_destroy_me) { skip = alloca(skip_size);
/* this guy is signaled for destruction */ memset(skip, 0, skip_size);
AST_LIST_REMOVE_CURRENT(list);
framehook_detach_and_destroy(framehook); do {
} else { unsigned int num = 0;
original_frame = frame;
AST_LIST_TRAVERSE_SAFE_BEGIN(&framehooks->list, framehook, list) {
if (framehook->detach_and_destroy_me) {
/* this guy is signaled for destruction */
AST_LIST_REMOVE_CURRENT(list);
framehook_detach_and_destroy(framehook);
continue;
}
/* If this framehook has been marked as needing to be skipped, do so */
if (skip[num]) {
num++;
continue;
}
frame = framehook->i.event_cb(framehook->chan, frame, event, framehook->i.data); frame = framehook->i.event_cb(framehook->chan, frame, event, framehook->i.data);
if (frame != original_frame) {
/* To prevent looping we skip any framehooks that have already provided a modified frame */
skip[num] = 1;
break;
}
num++;
} }
} AST_LIST_TRAVERSE_SAFE_END;
AST_LIST_TRAVERSE_SAFE_END; } while (frame != original_frame);
return frame; return frame;
} }
...@@ -116,6 +147,7 @@ int ast_framehook_attach(struct ast_channel *chan, struct ast_framehook_interfac ...@@ -116,6 +147,7 @@ int ast_framehook_attach(struct ast_channel *chan, struct ast_framehook_interfac
ast_channel_framehooks_set(chan, fh_list); ast_channel_framehooks_set(chan, fh_list);
} }
ast_channel_framehooks(chan)->count++;
framehook->id = ++ast_channel_framehooks(chan)->id_count; framehook->id = ++ast_channel_framehooks(chan)->id_count;
AST_LIST_INSERT_TAIL(&ast_channel_framehooks(chan)->list, framehook, list); AST_LIST_INSERT_TAIL(&ast_channel_framehooks(chan)->list, framehook, list);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment