FreeSWITCH API Documentation  1.7.0
switch_core_event_hook.h
Go to the documentation of this file.
1 /*
2  * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
3  * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
4  *
5  * Version: MPL 1.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
18  *
19  * The Initial Developer of the Original Code is
20  * Anthony Minessale II <anthm@freeswitch.org>
21  * Portions created by the Initial Developer are Copyright (C)
22  * the Initial Developer. All Rights Reserved.
23  *
24  * Contributor(s):
25  *
26  * Anthony Minessale II <anthm@freeswitch.org>
27  *
28  * switch_core_event_hook.h Core Event Hooks
29  *
30  */
31 #ifndef SWITCH_EVENT_HOOKS_H
32 #define SWITCH_EVENT_HOOKS_H
33 
34 #include <switch.h>
36 
52 typedef switch_status_t (*switch_receive_event_hook_t) (switch_core_session_t *, switch_event_t *);
53 typedef switch_status_t (*switch_read_frame_hook_t) (switch_core_session_t *, switch_frame_t **, switch_io_flag_t, int);
54 typedef switch_status_t (*switch_video_read_frame_hook_t) (switch_core_session_t *, switch_frame_t **, switch_io_flag_t, int);
55 typedef switch_status_t (*switch_write_frame_hook_t) (switch_core_session_t *, switch_frame_t *, switch_io_flag_t, int);
57 typedef switch_status_t (*switch_kill_channel_hook_t) (switch_core_session_t *, int);
58 typedef switch_status_t (*switch_send_dtmf_hook_t) (switch_core_session_t *, const switch_dtmf_t *, switch_dtmf_direction_t direction);
59 typedef switch_status_t (*switch_recv_dtmf_hook_t) (switch_core_session_t *, const switch_dtmf_t *, switch_dtmf_direction_t direction);
60 typedef switch_status_t (*switch_state_change_hook_t) (switch_core_session_t *);
61 typedef switch_status_t (*switch_state_run_hook_t) (switch_core_session_t *);
62 
63 /*! \brief Node in which to store custom receive message callback hooks */
67 };
68 
69 /*! \brief Node in which to store custom receive message callback hooks */
73 };
74 
75 
76 /*! \brief Node in which to store custom receive message callback hooks */
78  /*! the event callback hook */
81 };
82 
83 /*! \brief Node in which to store custom read frame channel callback hooks */
85  /*! the read frame channel callback hook */
88 };
89 
90 /*! \brief Node in which to store custom read frame channel callback hooks */
92  /*! the read frame channel callback hook */
95 };
96 
97 /*! \brief Node in which to store custom write_frame channel callback hooks */
99  /*! the write_frame channel callback hook */
102 };
103 
104 /*! \brief Node in which to store custom video_write_frame channel callback hooks */
106  /*! the video_write_frame channel callback hook */
109 };
110 
111 /*! \brief Node in which to store custom kill channel callback hooks */
113  /*! the kill channel callback hook */
116 };
117 
118 /*! \brief Node in which to store custom send dtmf channel callback hooks */
120  /*! the send dtmf channel callback hook */
123 };
124 
125 /*! \brief Node in which to store custom recv dtmf channel callback hooks */
127  /*! the recv dtmf channel callback hook */
130 };
131 
132 /*! \brief Node in which to store state change callback hooks */
134  /*! the state change channel callback hook */
137 };
138 
139 /*! \brief Node in which to store state run callback hooks */
141  /*! the state run channel callback hook */
144 };
145 
146 
147 /*! \brief A table of lists of io_event_hooks to store the event hooks associated with a session */
149  /*! a list of outgoing channel hooks */
151  /*! a list of receive message hooks */
153  /*! a list of queue message hooks */
155  /*! a list of read frame hooks */
157  /*! a list of video read frame hooks */
159  /*! a list of write frame hooks */
161  /*! a list of video write frame hooks */
163  /*! a list of kill channel hooks */
165  /*! a list of send dtmf hooks */
167  /*! a list of recv dtmf hooks */
169  /*! a list of state change hooks */
172 };
173 
174 extern switch_io_event_hooks_t switch_core_session_get_event_hooks(switch_core_session_t *session);
175 
176 #define NEW_HOOK_DECL_ADD_P(_NAME) SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_##_NAME \
177  (switch_core_session_t *session, switch_##_NAME##_hook_t _NAME)
178 
179 #define NEW_HOOK_DECL_REM_P(_NAME) SWITCH_DECLARE(switch_status_t) switch_core_event_hook_remove_##_NAME \
180  (switch_core_session_t *session, switch_##_NAME##_hook_t _NAME)
181 
182 #define NEW_HOOK_DECL(_NAME) NEW_HOOK_DECL_ADD_P(_NAME) \
183  { \
184  switch_io_event_hook_##_NAME##_t *hook, *ptr; \
185  assert(_NAME != NULL); \
186  for (ptr = session->event_hooks._NAME; ptr && ptr->next; ptr = ptr->next) \
187  if (ptr->_NAME == _NAME) return SWITCH_STATUS_FALSE; \
188  if (ptr && ptr->_NAME == _NAME) return SWITCH_STATUS_FALSE; \
189  if ((hook = switch_core_session_alloc(session, sizeof(*hook))) != 0) { \
190  hook->_NAME = _NAME ; \
191  if (! session->event_hooks._NAME ) { \
192  session->event_hooks._NAME = hook; \
193  } else { \
194  ptr->next = hook; \
195  } \
196  return SWITCH_STATUS_SUCCESS; \
197  } \
198  return SWITCH_STATUS_MEMERR; \
199  } \
200  NEW_HOOK_DECL_REM_P(_NAME) \
201  { \
202  switch_io_event_hook_##_NAME##_t *ptr, *last = NULL; \
203  assert(_NAME != NULL); \
204  for (ptr = session->event_hooks._NAME; ptr; ptr = ptr->next) { \
205  if (ptr->_NAME == _NAME) { \
206  if (last) { \
207  last->next = ptr->next; \
208  } else { \
209  session->event_hooks._NAME = ptr->next; \
210  } \
211  return SWITCH_STATUS_SUCCESS; \
212  } \
213  last = ptr; \
214  } \
215  return SWITCH_STATUS_FALSE; \
216  }
217 
218 
219 NEW_HOOK_DECL_ADD_P(outgoing_channel);
220 NEW_HOOK_DECL_ADD_P(receive_message);
221 NEW_HOOK_DECL_ADD_P(receive_event);
222 NEW_HOOK_DECL_ADD_P(state_change);
223 NEW_HOOK_DECL_ADD_P(state_run);
224 NEW_HOOK_DECL_ADD_P(read_frame);
225 NEW_HOOK_DECL_ADD_P(write_frame);
226 NEW_HOOK_DECL_ADD_P(video_read_frame);
227 NEW_HOOK_DECL_ADD_P(video_write_frame);
228 NEW_HOOK_DECL_ADD_P(kill_channel);
229 NEW_HOOK_DECL_ADD_P(send_dtmf);
230 NEW_HOOK_DECL_ADD_P(recv_dtmf);
231 
232 NEW_HOOK_DECL_REM_P(outgoing_channel);
233 NEW_HOOK_DECL_REM_P(receive_message);
234 NEW_HOOK_DECL_REM_P(receive_event);
235 NEW_HOOK_DECL_REM_P(state_change);
236 NEW_HOOK_DECL_REM_P(state_run);
237 NEW_HOOK_DECL_REM_P(read_frame);
238 NEW_HOOK_DECL_REM_P(write_frame);
239 NEW_HOOK_DECL_REM_P(video_read_frame);
240 NEW_HOOK_DECL_REM_P(video_write_frame);
241 NEW_HOOK_DECL_REM_P(kill_channel);
242 NEW_HOOK_DECL_REM_P(send_dtmf);
243 NEW_HOOK_DECL_REM_P(recv_dtmf);
244 
245 
247 #endif
248 /* For Emacs:
249  * Local Variables:
250  * mode:c
251  * indent-tabs-mode:t
252  * tab-width:4
253  * c-basic-offset:4
254  * End:
255  * For VIM:
256  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
257  */
switch_status_t(* switch_read_frame_hook_t)(switch_core_session_t *, switch_frame_t **, switch_io_flag_t, int)
switch_status_t(* switch_receive_event_hook_t)(switch_core_session_t *, switch_event_t *)
switch_status_t(* switch_video_read_frame_hook_t)(switch_core_session_t *, switch_frame_t **, switch_io_flag_t, int)
switch_status_t(* switch_kill_channel_hook_t)(switch_core_session_t *, int)
Call Specific Data.
Definition: switch_caller.h:73
struct switch_io_event_hook_outgoing_channel * next
uint32_t switch_io_flag_t
#define SWITCH_END_EXTERN_C
Definition: switch.h:43
switch_read_frame_hook_t read_frame
switch_status_t(* switch_video_write_frame_hook_t)(switch_core_session_t *, switch_frame_t *, switch_io_flag_t, int)
Node in which to store state change callback hooks.
struct switch_io_event_hook_send_dtmf * next
Node in which to store custom receive message callback hooks.
switch_status_t(* switch_outgoing_channel_hook_t)(switch_core_session_t *, switch_event_t *, switch_caller_profile_t *, switch_core_session_t *, switch_originate_flag_t)
switch_kill_channel_hook_t kill_channel
Node in which to store custom video_write_frame channel callback hooks.
struct switch_io_event_hook_receive_event * next
Representation of an event.
Definition: switch_event.h:80
switch_status_t(* switch_receive_message_hook_t)(switch_core_session_t *, switch_core_session_message_t *)
struct switch_io_event_hook_video_read_frame * next
Node in which to store custom read frame channel callback hooks.
switch_receive_event_hook_t receive_event
switch_video_write_frame_hook_t video_write_frame
struct switch_io_event_hook_read_frame * next
struct switch_io_event_hook_video_write_frame * next
uint32_t switch_originate_flag_t
Definition: switch_types.h:325
switch_status_t(* switch_send_dtmf_hook_t)(switch_core_session_t *, const switch_dtmf_t *, switch_dtmf_direction_t direction)
struct switch_io_event_hook_state_run * next
Node in which to store custom receive message callback hooks.
A message object designed to allow unlike technologies to exchange data.
Definition: switch_core.h:177
Node in which to store custom write_frame channel callback hooks.
switch_io_event_hook_write_frame_t * write_frame
switch_receive_message_hook_t receive_message
switch_status_t(* switch_state_run_hook_t)(switch_core_session_t *)
switch_status_t(* switch_write_frame_hook_t)(switch_core_session_t *, switch_frame_t *, switch_io_flag_t, int)
switch_write_frame_hook_t write_frame
switch_io_event_hooks_t switch_core_session_get_event_hooks(switch_core_session_t *session)
Node in which to store state run callback hooks.
switch_io_event_hook_video_read_frame_t * video_read_frame
An abstraction of a data frame.
Definition: switch_frame.h:43
switch_io_event_hook_send_dtmf_t * send_dtmf
struct switch_io_event_hook_kill_channel * next
switch_io_event_hook_outgoing_channel_t * outgoing_channel
switch_io_event_hook_read_frame_t * read_frame
struct switch_io_event_hook_receive_message * next
switch_dtmf_direction_t
Definition: switch_types.h:310
Node in which to store custom read frame channel callback hooks.
switch_state_change_hook_t state_change
struct switch_io_event_hook_state_change * next
switch_status_t
Common return values.
switch_status_t(* switch_recv_dtmf_hook_t)(switch_core_session_t *, const switch_dtmf_t *, switch_dtmf_direction_t direction)
Node in which to store custom receive message callback hooks.
Node in which to store custom send dtmf channel callback hooks.
switch_io_event_hook_video_write_frame_t * video_write_frame
switch_status_t(* switch_state_change_hook_t)(switch_core_session_t *)
Main Library Header.
#define NEW_HOOK_DECL_REM_P(_NAME)
switch_io_event_hook_receive_event_t * receive_event
switch_io_event_hook_receive_message_t * receive_message
struct switch_io_event_hook_recv_dtmf * next
Node in which to store custom kill channel callback hooks.
struct switch_io_event_hook_write_frame * next
switch_io_event_hook_state_run_t * state_run
switch_io_event_hook_recv_dtmf_t * recv_dtmf
typedefSWITCH_BEGIN_EXTERN_C struct switch_io_event_hooks switch_io_event_hooks_t
Node in which to store custom recv dtmf channel callback hooks.
switch_io_event_hook_kill_channel_t * kill_channel
#define NEW_HOOK_DECL_ADD_P(_NAME)
switch_outgoing_channel_hook_t outgoing_channel
A table of lists of io_event_hooks to store the event hooks associated with a session.
switch_io_event_hook_state_change_t * state_change
#define SWITCH_BEGIN_EXTERN_C
Definition: switch.h:42