#include "asterisk.h"
#include "asterisk/channel.h"
#include "asterisk/linkedlists.h"
#include "asterisk/framehook.h"
#include "asterisk/frame.h"

Go to the source code of this file.
Data Structures | |
| struct | ast_framehook |
| struct | ast_framehook_list |
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 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. | |
| 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. | |
| 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. | |
| 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) |
Definition in file framehook.c.
| 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_channel_framehooks(), ast_channel_framehooks_set(), AST_FRAMEHOOK_EVENT_ATTACHED, AST_FRAMEHOOK_INTERFACE_VERSION, ast_free, ast_frfree, AST_LIST_INSERT_TAIL, ast_log(), ast_framehook::chan, ast_framehook_interface::data, ast_framehook_interface::event_cb, ast_framehook::i, ast_framehook::id, ast_framehook_list::id_count, LOG_ERROR, and ast_framehook_interface::version.
Referenced by fax_detect_attach(), fax_gateway_attach(), frame_trace_helper(), and jb_helper().
00091 { 00092 struct ast_framehook *framehook; 00093 struct ast_framehook_list *fh_list; 00094 struct ast_frame *frame; 00095 if (i->version != AST_FRAMEHOOK_INTERFACE_VERSION) { 00096 ast_log(LOG_ERROR, "Version '%hu' of framehook interface not what we compiled against (%hu)\n", 00097 i->version, AST_FRAMEHOOK_INTERFACE_VERSION); 00098 return -1; 00099 } 00100 if (!i->event_cb || !(framehook = ast_calloc(1, sizeof(*framehook)))) { 00101 return -1; 00102 } 00103 framehook->i = *i; 00104 framehook->chan = chan; 00105 00106 /* create the framehook list if it didn't already exist */ 00107 if (!ast_channel_framehooks(chan)) { 00108 if (!(fh_list = ast_calloc(1, sizeof(*ast_channel_framehooks(chan))))) { 00109 ast_free(framehook); 00110 return -1; 00111 } 00112 ast_channel_framehooks_set(chan, fh_list); 00113 } 00114 00115 framehook->id = ++ast_channel_framehooks(chan)->id_count; 00116 AST_LIST_INSERT_TAIL(&ast_channel_framehooks(chan)->list, framehook, list); 00117 00118 /* Tell the event callback we're live and rocking */ 00119 frame = framehook->i.event_cb(framehook->chan, NULL, AST_FRAMEHOOK_EVENT_ATTACHED, framehook->i.data); 00120 00121 /* Never assume anything about this function. If you can return a frame during 00122 * the attached event, then assume someone will. */ 00123 if (frame) { 00124 ast_frfree(frame); 00125 } 00126 00127 return framehook->id; 00128 }
| 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 130 of file framehook.c.
References ast_channel_framehooks(), AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_framehook::detach_and_destroy_me, and ast_framehook::id.
Referenced by acf_faxopt_write(), fax_detect_framehook(), fax_gateway_detect_t38(), fax_gateway_framehook(), fax_gateway_request_t38(), frame_trace_helper(), and jb_helper().
00131 { 00132 struct ast_framehook *framehook; 00133 int res = -1; 00134 00135 if (!ast_channel_framehooks(chan)) { 00136 return res; 00137 } 00138 00139 AST_LIST_TRAVERSE_SAFE_BEGIN(&ast_channel_framehooks(chan)->list, framehook, list) { 00140 if (framehook->id == id) { 00141 /* we mark for detachment rather than doing explicitly here because 00142 * it needs to be safe for this function to be called within the 00143 * event callback. If we allowed the hook to actually be destroyed 00144 * immediately here, the event callback would crash on exit. */ 00145 framehook->detach_and_destroy_me = 1; 00146 res = 0; 00147 break; 00148 } 00149 } 00150 AST_LIST_TRAVERSE_SAFE_END; 00151 00152 return res; 00153 }
| 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 155 of file framehook.c.
References ast_channel_framehooks(), ast_channel_framehooks_set(), ast_free, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, and framehook_detach_and_destroy().
Referenced by destroy_hooks().
00156 { 00157 struct ast_framehook *framehook; 00158 00159 if (!ast_channel_framehooks(chan)) { 00160 return 0; 00161 } 00162 AST_LIST_TRAVERSE_SAFE_BEGIN(&ast_channel_framehooks(chan)->list, framehook, list) { 00163 AST_LIST_REMOVE_CURRENT(list); 00164 framehook_detach_and_destroy(framehook); 00165 } 00166 AST_LIST_TRAVERSE_SAFE_END; 00167 ast_free(ast_channel_framehooks(chan)); 00168 ast_channel_framehooks_set(chan, NULL); 00169 return 0; 00170 }
| 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 172 of file framehook.c.
References AST_LIST_EMPTY, and ast_framehook_list::list.
Referenced by ast_channel_bridge(), ast_indicate_data(), local_bridge_loop(), and remote_bridge_loop().
00173 { 00174 if (!framehooks) { 00175 return 1; 00176 } 00177 return AST_LIST_EMPTY(&framehooks->list) ? 1 : 0; 00178 }
| struct ast_frame* ast_framehook_list_read_event | ( | struct ast_framehook_list * | framehooks, | |
| struct ast_frame * | frame | |||
| ) | [read] |
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 185 of file framehook.c.
References AST_FRAMEHOOK_EVENT_READ, and framehook_list_push_event().
Referenced by __ast_read().
00186 { 00187 return framehook_list_push_event(framehooks, frame, AST_FRAMEHOOK_EVENT_READ); 00188 }
| struct ast_frame* ast_framehook_list_write_event | ( | struct ast_framehook_list * | framehooks, | |
| struct ast_frame * | frame | |||
| ) | [read] |
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 180 of file framehook.c.
References AST_FRAMEHOOK_EVENT_WRITE, and framehook_list_push_event().
Referenced by ast_indicate_data(), and ast_write().
00181 { 00182 return framehook_list_push_event(framehooks, frame, AST_FRAMEHOOK_EVENT_WRITE); 00183 }
| static void framehook_detach_and_destroy | ( | struct ast_framehook * | framehook | ) | [static] |
Definition at line 52 of file framehook.c.
References AST_FRAMEHOOK_EVENT_DETACHED, ast_free, and ast_frfree.
Referenced by ast_framehook_list_destroy(), and framehook_list_push_event().
00053 { 00054 struct ast_frame *frame; 00055 frame = framehook->i.event_cb(framehook->chan, NULL, AST_FRAMEHOOK_EVENT_DETACHED, framehook->i.data); 00056 /* never assume anything about this function. If you can return a frame during 00057 * the detached event, then assume someone will. */ 00058 if (frame) { 00059 ast_frfree(frame); 00060 } 00061 framehook->chan = NULL; 00062 00063 if (framehook->i.destroy_cb) { 00064 framehook->i.destroy_cb(framehook->i.data); 00065 } 00066 ast_free(framehook); 00067 }
| static struct ast_frame* framehook_list_push_event | ( | struct ast_framehook_list * | framehooks, | |
| struct ast_frame * | frame, | |||
| enum ast_framehook_event | event | |||
| ) | [static, read] |
Definition at line 69 of file framehook.c.
References AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_framehook::chan, ast_framehook_interface::data, ast_framehook::detach_and_destroy_me, ast_framehook_interface::event_cb, framehook_detach_and_destroy(), ast_framehook::i, and ast_framehook_list::list.
Referenced by ast_framehook_list_read_event(), and ast_framehook_list_write_event().
00070 { 00071 struct ast_framehook *framehook; 00072 00073 if (!framehooks) { 00074 return frame; 00075 } 00076 00077 AST_LIST_TRAVERSE_SAFE_BEGIN(&framehooks->list, framehook, list) { 00078 if (framehook->detach_and_destroy_me) { 00079 /* this guy is signaled for destruction */ 00080 AST_LIST_REMOVE_CURRENT(list); 00081 framehook_detach_and_destroy(framehook); 00082 } else { 00083 frame = framehook->i.event_cb(framehook->chan, frame, event, framehook->i.data); 00084 } 00085 } 00086 AST_LIST_TRAVERSE_SAFE_END; 00087 return frame; 00088 }
1.5.6