#include "asterisk/linkedlists.h"
#include "asterisk/frame.h"
Go to the source code of this file.
Data Structures | |
struct | ast_framehook_interface |
Defines | |
#define | AST_FRAMEHOOK_INTERFACE_VERSION 1 |
Typedefs | |
typedef void(*) | ast_framehook_destroy_callback (void *data) |
This callback is called immediately before the framehook is destroyed. | |
typedef ast_frame *(*) | ast_framehook_event_callback (struct ast_channel *chan, struct ast_frame *frame, enum ast_framehook_event event, void *data) |
This callback is called every time an event occurs on the framehook. | |
Enumerations | |
enum | ast_framehook_event { AST_FRAMEHOOK_EVENT_READ, AST_FRAMEHOOK_EVENT_WRITE, AST_FRAMEHOOK_EVENT_ATTACHED, AST_FRAMEHOOK_EVENT_DETACHED } |
These are the types of events that the framehook's event callback can receive. More... | |
Functions | |
int | ast_framehook_attach (struct ast_channel *chan, struct ast_framehook_interface *i) |
Attach an framehook onto a channel for frame interception. | |
int | ast_framehook_detach (struct ast_channel *chan, int framehook_id) |
Detach an framehook from a channel. | |
int | ast_framehook_list_destroy (struct ast_channel *chan) |
This is used by the channel API to detach and destroy all framehooks on a channel during channel destruction. | |
int | ast_framehook_list_is_empty (struct ast_framehook_list *framehooks) |
Determine if an framehook list is empty or not. | |
ast_frame * | ast_framehook_list_read_event (struct ast_framehook_list *framehooks, struct ast_frame *frame) |
This is used by the channel API push a frame read event to a channel's framehook list. | |
ast_frame * | ast_framehook_list_write_event (struct ast_framehook_list *framehooks, struct ast_frame *frame) |
This is used by the channel API push a frame write event to a channel's framehook list. |
Definition in file framehook.h.
#define AST_FRAMEHOOK_INTERFACE_VERSION 1 |
Definition at line 202 of file framehook.h.
Referenced by ast_framehook_attach(), and frame_trace_helper().
typedef void(*) ast_framehook_destroy_callback(void *data) |
This callback is called immediately before the framehook is destroyed.
data,The | data pointer provided at framehook initialization. This is a good place to clean up any state data allocated for the framehook stored in this pointer. |
Definition at line 200 of file framehook.h.
typedef struct ast_frame*(*) ast_framehook_event_callback(struct ast_channel *chan, struct ast_frame *frame, enum ast_framehook_event event, void *data) |
This callback is called every time an event occurs on the framehook.
It is completely valid for the frame variable to be set to NULL. Always do a NULL check on the frame before attempted to access it. When the frame variable is present, it is safe to view and manipulate that frame in any way possible. It is even safe to return a completely different frame, but when that occurs this function is in charge of freeing the previous frame.
The ast_channel will always be locked during this callback. Never attempt to unlock the channel for any reason.
channel,The | ast_channel this framehook is attached to | |
frame,The | ast_frame being intercepted for viewing and manipulation | |
event,The | type of event which is occurring | |
data,The | data pointer provided at framehook initilization. |
the | resulting frame. |
Definition at line 184 of file framehook.h.
enum ast_framehook_event |
These are the types of events that the framehook's event callback can receive.
Definition at line 151 of file framehook.h.
00151 { 00152 AST_FRAMEHOOK_EVENT_READ, /*!< frame is intercepted in the read direction on the channel. */ 00153 AST_FRAMEHOOK_EVENT_WRITE, /*!< frame is intercepted on the write direction on the channel. */ 00154 AST_FRAMEHOOK_EVENT_ATTACHED, /*!< framehook is attached and running on the channel, the first message sent to event_cb. */ 00155 AST_FRAMEHOOK_EVENT_DETACHED /*!< framehook is detached from the channel, last message sent to event_cb. */ 00156 };
int ast_framehook_attach | ( | struct ast_channel * | chan, | |
struct ast_framehook_interface * | i | |||
) |
Attach an framehook onto a channel for frame interception.
ast_channel,The | channel to attach the hook on to. | |
framehook | interface, The framehook's callback functions and stored data. |
On | success, positive id representing this hook on the channel | |
On | failure, -1 |
Definition at line 90 of file framehook.c.
References ast_calloc, AST_FRAMEHOOK_EVENT_ATTACHED, AST_FRAMEHOOK_INTERFACE_VERSION, ast_free, ast_frfree, AST_LIST_INSERT_TAIL, ast_log(), ast_framehook::chan, ast_framehook_interface::event_cb, ast_channel::framehooks, ast_framehook::i, ast_framehook_list::id_count, ast_framehook_list::list, ast_framehook::list, LOG_ERROR, and ast_framehook_interface::version.
Referenced by frame_trace_helper().
00091 { 00092 struct ast_framehook *framehook; 00093 struct ast_frame *frame; 00094 if (i->version != AST_FRAMEHOOK_INTERFACE_VERSION) { 00095 ast_log(LOG_ERROR, "Version '%hu' of framehook interface not what we compiled against (%hu)\n", 00096 i->version, AST_FRAMEHOOK_INTERFACE_VERSION); 00097 return -1; 00098 } 00099 if (!i->event_cb || !(framehook = ast_calloc(1, sizeof(*framehook)))) { 00100 return -1; 00101 } 00102 framehook->i = *i; 00103 framehook->chan = chan; 00104 00105 /* create the framehook list if it didn't already exist */ 00106 if (!chan->framehooks && !(chan->framehooks = ast_calloc(1, sizeof(*chan->framehooks)))) { 00107 ast_free(framehook); 00108 return -1; 00109 } 00110 00111 framehook->id = ++chan->framehooks->id_count; 00112 AST_LIST_INSERT_TAIL(&chan->framehooks->list, framehook, list); 00113 00114 /* Tell the event callback we're live and rocking */ 00115 frame = framehook->i.event_cb(framehook->chan, NULL, AST_FRAMEHOOK_EVENT_ATTACHED, framehook->i.data); 00116 00117 /* Never assume anything about this function. If you can return a frame during 00118 * the attached event, then assume someone will. */ 00119 if (frame) { 00120 ast_frfree(frame); 00121 } 00122 00123 return framehook->id; 00124 }
int ast_framehook_detach | ( | struct ast_channel * | chan, | |
int | framehook_id | |||
) |
Detach an framehook from a channel.
The | channel the framehook is attached to | |
The | framehook's id |
0 | success | |
-1 | framehook did not exist on the channel. This means the framehook either never existed on the channel, or was already detached. |
Definition at line 126 of file framehook.c.
References AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_framehook::chan, ast_framehook::detach_and_destroy_me, ast_channel::framehooks, ast_framehook::id, ast_framehook_list::list, and ast_framehook::list.
Referenced by frame_trace_helper().
00127 { 00128 struct ast_framehook *framehook; 00129 int res = -1; 00130 00131 if (!chan->framehooks) { 00132 return res; 00133 } 00134 00135 AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->framehooks->list, framehook, list) { 00136 if (framehook->id == id) { 00137 /* we mark for detachment rather than doing explicitly here because 00138 * it needs to be safe for this function to be called within the 00139 * event callback. If we allowed the hook to actually be destroyed 00140 * immediately here, the event callback would crash on exit. */ 00141 framehook->detach_and_destroy_me = 1; 00142 res = 0; 00143 break; 00144 } 00145 } 00146 AST_LIST_TRAVERSE_SAFE_END; 00147 00148 return res; 00149 }
int ast_framehook_list_destroy | ( | struct ast_channel * | chan | ) |
This is used by the channel API to detach and destroy all framehooks on a channel during channel destruction.
channel | containing the framehook list to destroy. |
0 | success | |
-1 | failure |
Definition at line 151 of file framehook.c.
References ast_free, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_framehook::chan, framehook_detach_and_destroy(), ast_channel::framehooks, ast_framehook_list::list, and ast_framehook::list.
Referenced by ast_hangup().
00152 { 00153 struct ast_framehook *framehook; 00154 00155 if (!chan->framehooks) { 00156 return 0; 00157 } 00158 AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->framehooks->list, framehook, list) { 00159 AST_LIST_REMOVE_CURRENT(list); 00160 framehook_detach_and_destroy(framehook); 00161 } 00162 AST_LIST_TRAVERSE_SAFE_END; 00163 ast_free(chan->framehooks); 00164 chan->framehooks = NULL; 00165 return 0; 00166 }
int ast_framehook_list_is_empty | ( | struct ast_framehook_list * | framehooks | ) |
Determine if an framehook list is empty or not.
the | framehook list |
0,not | empty | |
1,is | empty |
Definition at line 168 of file framehook.c.
References AST_LIST_EMPTY, and ast_framehook_list::list.
Referenced by ast_indicate_data().
00169 { 00170 if (!framehooks) { 00171 return 1; 00172 } 00173 return AST_LIST_EMPTY(&framehooks->list) ? 1 : 0; 00174 }
struct ast_frame* ast_framehook_list_read_event | ( | struct ast_framehook_list * | framehooks, | |
struct ast_frame * | frame | |||
) |
This is used by the channel API push a frame read event to a channel's framehook list.
framehook | list to push event to. | |
frame | being pushed to the framehook list. |
Definition at line 181 of file framehook.c.
References AST_FRAMEHOOK_EVENT_READ, and framehook_list_push_event().
Referenced by __ast_read(), and ast_indicate_data().
00182 { 00183 return framehook_list_push_event(framehooks, frame, AST_FRAMEHOOK_EVENT_READ); 00184 }
struct ast_frame* ast_framehook_list_write_event | ( | struct ast_framehook_list * | framehooks, | |
struct ast_frame * | frame | |||
) |
This is used by the channel API push a frame write event to a channel's framehook list.
framehook | list to push event to. | |
frame | being pushed to the framehook list. |
Definition at line 176 of file framehook.c.
References AST_FRAMEHOOK_EVENT_WRITE, and framehook_list_push_event().
Referenced by ast_write().
00177 { 00178 return framehook_list_push_event(framehooks, frame, AST_FRAMEHOOK_EVENT_WRITE); 00179 }