Dialing API. More...
Go to the source code of this file.
Typedefs | |
typedef void(* | ast_dial_state_callback )(struct ast_dial *) |
Enumerations | |
enum | ast_dial_option { AST_DIAL_OPTION_RINGING, AST_DIAL_OPTION_ANSWER_EXEC, AST_DIAL_OPTION_MUSIC, AST_DIAL_OPTION_DISABLE_CALL_FORWARDING, AST_DIAL_OPTION_MAX } |
List of options that are applicable either globally or per dialed channel. More... | |
enum | ast_dial_result { AST_DIAL_RESULT_INVALID, AST_DIAL_RESULT_FAILED, AST_DIAL_RESULT_TRYING, AST_DIAL_RESULT_RINGING, AST_DIAL_RESULT_PROGRESS, AST_DIAL_RESULT_PROCEEDING, AST_DIAL_RESULT_ANSWERED, AST_DIAL_RESULT_TIMEOUT, AST_DIAL_RESULT_HANGUP, AST_DIAL_RESULT_UNANSWERED } |
List of return codes for dial run API calls. More... | |
Functions | |
struct ast_channel * | ast_dial_answered (struct ast_dial *dial) |
Return channel that answered. | |
struct ast_channel * | ast_dial_answered_steal (struct ast_dial *dial) |
Steal the channel that answered. | |
int | ast_dial_append (struct ast_dial *dial, const char *tech, const char *device) |
Append a channel. | |
struct ast_dial * | ast_dial_create (void) |
New dialing structure. | |
int | ast_dial_destroy (struct ast_dial *dial) |
Destroys a dialing structure. | |
void | ast_dial_hangup (struct ast_dial *dial) |
Hangup channels. | |
enum ast_dial_result | ast_dial_join (struct ast_dial *dial) |
Cancel async thread. | |
int | ast_dial_option_disable (struct ast_dial *dial, int num, enum ast_dial_option option) |
Disables an option per channel. | |
int | ast_dial_option_enable (struct ast_dial *dial, int num, enum ast_dial_option option, void *data) |
Enables an option per channel. | |
int | ast_dial_option_global_disable (struct ast_dial *dial, enum ast_dial_option option) |
Disables an option globally. | |
int | ast_dial_option_global_enable (struct ast_dial *dial, enum ast_dial_option option, void *data) |
Enables an option globally. | |
enum ast_dial_result | ast_dial_run (struct ast_dial *dial, struct ast_channel *chan, int async) |
Execute dialing synchronously or asynchronously. | |
void | ast_dial_set_global_timeout (struct ast_dial *dial, int timeout) |
Set the maximum time (globally) allowed for trying to ring phones. | |
void | ast_dial_set_state_callback (struct ast_dial *dial, ast_dial_state_callback callback) |
Set a callback for state changes. | |
void | ast_dial_set_timeout (struct ast_dial *dial, int num, int timeout) |
Set the maximum time (per channel) allowed for trying to ring the phone. | |
enum ast_dial_result | ast_dial_state (struct ast_dial *dial) |
Return state of dial. |
Dialing API.
Definition in file dial.h.
typedef void(* ast_dial_state_callback)(struct ast_dial *) |
enum ast_dial_option |
List of options that are applicable either globally or per dialed channel.
Definition at line 39 of file dial.h.
00039 { 00040 AST_DIAL_OPTION_RINGING, /*!< Always indicate ringing to caller */ 00041 AST_DIAL_OPTION_ANSWER_EXEC, /*!< Execute application upon answer in async mode */ 00042 AST_DIAL_OPTION_MUSIC, /*!< Play music on hold instead of ringing to the calling channel */ 00043 AST_DIAL_OPTION_DISABLE_CALL_FORWARDING, /*!< Disable call forwarding on channels */ 00044 AST_DIAL_OPTION_MAX, /*!< End terminator -- must always remain last */ 00045 };
enum ast_dial_result |
List of return codes for dial run API calls.
AST_DIAL_RESULT_INVALID |
Invalid options were passed to run function |
AST_DIAL_RESULT_FAILED |
Attempts to dial failed before reaching critical state |
AST_DIAL_RESULT_TRYING |
Currently trying to dial |
AST_DIAL_RESULT_RINGING |
Dial is presently ringing |
AST_DIAL_RESULT_PROGRESS |
Dial is presently progressing |
AST_DIAL_RESULT_PROCEEDING |
Dial is presently proceeding |
AST_DIAL_RESULT_ANSWERED |
A channel was answered |
AST_DIAL_RESULT_TIMEOUT |
Timeout was tripped, nobody answered |
AST_DIAL_RESULT_HANGUP |
Caller hung up |
AST_DIAL_RESULT_UNANSWERED |
Nobody answered |
Definition at line 48 of file dial.h.
00048 { 00049 AST_DIAL_RESULT_INVALID, /*!< Invalid options were passed to run function */ 00050 AST_DIAL_RESULT_FAILED, /*!< Attempts to dial failed before reaching critical state */ 00051 AST_DIAL_RESULT_TRYING, /*!< Currently trying to dial */ 00052 AST_DIAL_RESULT_RINGING, /*!< Dial is presently ringing */ 00053 AST_DIAL_RESULT_PROGRESS, /*!< Dial is presently progressing */ 00054 AST_DIAL_RESULT_PROCEEDING, /*!< Dial is presently proceeding */ 00055 AST_DIAL_RESULT_ANSWERED, /*!< A channel was answered */ 00056 AST_DIAL_RESULT_TIMEOUT, /*!< Timeout was tripped, nobody answered */ 00057 AST_DIAL_RESULT_HANGUP, /*!< Caller hung up */ 00058 AST_DIAL_RESULT_UNANSWERED, /*!< Nobody answered */ 00059 };
struct ast_channel* ast_dial_answered | ( | struct ast_dial * | dial | ) | [read] |
Return channel that answered.
dial | Dialing structure |
Definition at line 754 of file dial.c.
References AST_DIAL_RESULT_ANSWERED, AST_LIST_FIRST, ast_dial::channels, and ast_dial::state.
Referenced by dial_trunk(), and sla_handle_dial_state_event().
00755 { 00756 if (!dial) 00757 return NULL; 00758 00759 return ((dial->state == AST_DIAL_RESULT_ANSWERED) ? AST_LIST_FIRST(&dial->channels)->owner : NULL); 00760 }
struct ast_channel* ast_dial_answered_steal | ( | struct ast_dial * | dial | ) | [read] |
Steal the channel that answered.
dial | Dialing structure |
Definition at line 766 of file dial.c.
References AST_DIAL_RESULT_ANSWERED, AST_LIST_FIRST, ast_dial::channels, and ast_dial::state.
Referenced by do_notify().
00767 { 00768 struct ast_channel *chan = NULL; 00769 00770 if (!dial) 00771 return NULL; 00772 00773 if (dial->state == AST_DIAL_RESULT_ANSWERED) { 00774 chan = AST_LIST_FIRST(&dial->channels)->owner; 00775 AST_LIST_FIRST(&dial->channels)->owner = NULL; 00776 } 00777 00778 return chan; 00779 }
int ast_dial_append | ( | struct ast_dial * | dial, | |
const char * | tech, | |||
const char * | device | |||
) |
Append a channel.
Definition at line 229 of file dial.c.
References ast_atomic_fetchadd_int(), ast_calloc, AST_LIST_INSERT_TAIL, ast_strdup, ast_dial::channels, ast_dial_channel::device, ast_dial_channel::list, ast_dial::num, ast_dial_channel::num, ast_dial_channel::tech, and ast_dial_channel::timeout.
Referenced by dial_trunk(), do_notify(), page_exec(), and sla_ring_station().
00230 { 00231 struct ast_dial_channel *channel = NULL; 00232 00233 /* Make sure we have required arguments */ 00234 if (!dial || !tech || !device) 00235 return -1; 00236 00237 /* Allocate new memory for dialed channel structure */ 00238 if (!(channel = ast_calloc(1, sizeof(*channel)))) 00239 return -1; 00240 00241 /* Record technology and device for when we actually dial */ 00242 channel->tech = ast_strdup(tech); 00243 channel->device = ast_strdup(device); 00244 00245 /* Grab reference number from dial structure */ 00246 channel->num = ast_atomic_fetchadd_int(&dial->num, +1); 00247 00248 /* No timeout exists... yet */ 00249 channel->timeout = -1; 00250 00251 /* Insert into channels list */ 00252 AST_LIST_INSERT_TAIL(&dial->channels, channel, list); 00253 00254 return channel->num; 00255 }
struct ast_dial* ast_dial_create | ( | void | ) | [read] |
New dialing structure.
Definition at line 201 of file dial.c.
References ast_dial::actual_timeout, ast_calloc, AST_LIST_HEAD_INIT, ast_mutex_init, AST_PTHREADT_NULL, ast_dial::channels, ast_dial::lock, ast_dial::thread, and ast_dial::timeout.
Referenced by dial_trunk(), do_notify(), page_exec(), and sla_ring_station().
00202 { 00203 struct ast_dial *dial = NULL; 00204 00205 /* Allocate new memory for structure */ 00206 if (!(dial = ast_calloc(1, sizeof(*dial)))) 00207 return NULL; 00208 00209 /* Initialize list of channels */ 00210 AST_LIST_HEAD_INIT(&dial->channels); 00211 00212 /* Initialize thread to NULL */ 00213 dial->thread = AST_PTHREADT_NULL; 00214 00215 /* No timeout exists... yet */ 00216 dial->timeout = -1; 00217 dial->actual_timeout = -1; 00218 00219 /* Can't forget about the lock */ 00220 ast_mutex_init(&dial->lock); 00221 00222 return dial; 00223 }
int ast_dial_destroy | ( | struct ast_dial * | dial | ) |
Destroys a dialing structure.
dial | Dialing structure to free |
dial | Dialing structure to free |
Definition at line 866 of file dial.c.
References AST_DIAL_OPTION_MAX, ast_free, ast_hangup(), AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_mutex_destroy, ast_dial::channels, ast_dial_channel::device, ast_option_types::disable, ast_dial_channel::list, ast_dial::lock, ast_dial::options, ast_dial_channel::options, ast_dial_channel::owner, and ast_dial_channel::tech.
Referenced by dial_trunk(), do_notify(), page_exec(), run_station(), sla_handle_dial_state_event(), sla_hangup_stations(), sla_ring_station(), and sla_stop_ringing_station().
00867 { 00868 int i = 0; 00869 struct ast_dial_channel *channel = NULL; 00870 00871 if (!dial) 00872 return -1; 00873 00874 /* Hangup and deallocate all the dialed channels */ 00875 AST_LIST_LOCK(&dial->channels); 00876 AST_LIST_TRAVERSE_SAFE_BEGIN(&dial->channels, channel, list) { 00877 /* Disable any enabled options */ 00878 for (i = 0; i < AST_DIAL_OPTION_MAX; i++) { 00879 if (!channel->options[i]) 00880 continue; 00881 if (option_types[i].disable) 00882 option_types[i].disable(channel->options[i]); 00883 channel->options[i] = NULL; 00884 } 00885 /* Hang up channel if need be */ 00886 if (channel->owner) { 00887 ast_hangup(channel->owner); 00888 channel->owner = NULL; 00889 } 00890 /* Free structure */ 00891 ast_free(channel->tech); 00892 ast_free(channel->device); 00893 AST_LIST_REMOVE_CURRENT(list); 00894 ast_free(channel); 00895 } 00896 AST_LIST_TRAVERSE_SAFE_END; 00897 AST_LIST_UNLOCK(&dial->channels); 00898 00899 /* Disable any enabled options globally */ 00900 for (i = 0; i < AST_DIAL_OPTION_MAX; i++) { 00901 if (!dial->options[i]) 00902 continue; 00903 if (option_types[i].disable) 00904 option_types[i].disable(dial->options[i]); 00905 dial->options[i] = NULL; 00906 } 00907 00908 /* Lock be gone! */ 00909 ast_mutex_destroy(&dial->lock); 00910 00911 /* Free structure */ 00912 ast_free(dial); 00913 00914 return 0; 00915 }
void ast_dial_hangup | ( | struct ast_dial * | dial | ) |
Hangup channels.
dial | Dialing structure |
Definition at line 842 of file dial.c.
References ast_hangup(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_dial::channels, ast_dial_channel::list, and ast_dial_channel::owner.
Referenced by ast_dial_run(), and page_exec().
00843 { 00844 struct ast_dial_channel *channel = NULL; 00845 00846 if (!dial) 00847 return; 00848 00849 AST_LIST_LOCK(&dial->channels); 00850 AST_LIST_TRAVERSE(&dial->channels, channel, list) { 00851 if (channel->owner) { 00852 ast_hangup(channel->owner); 00853 channel->owner = NULL; 00854 } 00855 } 00856 AST_LIST_UNLOCK(&dial->channels); 00857 00858 return; 00859 }
enum ast_dial_result ast_dial_join | ( | struct ast_dial * | dial | ) |
Cancel async thread.
dial | Dialing structure |
Definition at line 794 of file dial.c.
References ast_channel_lock, ast_channel_unlock, AST_DIAL_RESULT_FAILED, AST_LIST_FIRST, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_mutex_lock, ast_mutex_unlock, AST_PTHREADT_NULL, AST_PTHREADT_STOP, ast_softhangup(), AST_SOFTHANGUP_EXPLICIT, ast_dial::channels, ast_dial::lock, ast_dial::state, and ast_dial::thread.
Referenced by dial_trunk(), page_exec(), run_station(), sla_handle_dial_state_event(), sla_hangup_stations(), sla_ring_station(), and sla_stop_ringing_station().
00795 { 00796 pthread_t thread; 00797 00798 /* If the dial structure is not running in async, return failed */ 00799 if (dial->thread == AST_PTHREADT_NULL) 00800 return AST_DIAL_RESULT_FAILED; 00801 00802 /* Record thread */ 00803 thread = dial->thread; 00804 00805 /* Boom, commence locking */ 00806 ast_mutex_lock(&dial->lock); 00807 00808 /* Stop the thread */ 00809 dial->thread = AST_PTHREADT_STOP; 00810 00811 /* If the answered channel is running an application we have to soft hangup it, can't just poke the thread */ 00812 AST_LIST_LOCK(&dial->channels); 00813 if (AST_LIST_FIRST(&dial->channels)->is_running_app) { 00814 struct ast_channel *chan = AST_LIST_FIRST(&dial->channels)->owner; 00815 if (chan) { 00816 ast_channel_lock(chan); 00817 ast_softhangup(chan, AST_SOFTHANGUP_EXPLICIT); 00818 ast_channel_unlock(chan); 00819 } 00820 } else { 00821 /* Now we signal it with SIGURG so it will break out of it's waitfor */ 00822 pthread_kill(thread, SIGURG); 00823 } 00824 AST_LIST_UNLOCK(&dial->channels); 00825 00826 /* Yay done with it */ 00827 ast_mutex_unlock(&dial->lock); 00828 00829 /* Finally wait for the thread to exit */ 00830 pthread_join(thread, NULL); 00831 00832 /* Yay thread is all gone */ 00833 dial->thread = AST_PTHREADT_NULL; 00834 00835 return dial->state; 00836 }
int ast_dial_option_disable | ( | struct ast_dial * | dial, | |
int | num, | |||
enum ast_dial_option | option | |||
) |
Disables an option per channel.
dial | Dial structure | |
num | Channel number to disable option on | |
option | Option to disable |
Definition at line 1018 of file dial.c.
References AST_LIST_EMPTY, ast_dial::channels, ast_option_types::disable, find_dial_channel(), and ast_dial_channel::options.
01019 { 01020 struct ast_dial_channel *channel = NULL; 01021 01022 /* Ensure we have required arguments */ 01023 if (!dial || AST_LIST_EMPTY(&dial->channels)) 01024 return -1; 01025 01026 if (!(channel = find_dial_channel(dial, num))) 01027 return -1; 01028 01029 /* If the option is not enabled, return failure */ 01030 if (!channel->options[option]) 01031 return -1; 01032 01033 /* Execute callback of option to disable it if it exists */ 01034 if (option_types[option].disable) 01035 option_types[option].disable(channel->options[option]); 01036 01037 /* Finally disable the option on the structure */ 01038 channel->options[option] = NULL; 01039 01040 return 0; 01041 }
int ast_dial_option_enable | ( | struct ast_dial * | dial, | |
int | num, | |||
enum ast_dial_option | option, | |||
void * | data | |||
) |
Enables an option per channel.
dial | Dial structure | |
num | Channel number to enable option on | |
option | Option to enable | |
data | Data to pass to this option (not always needed) |
Definition at line 966 of file dial.c.
References AST_LIST_EMPTY, ast_dial::channels, ast_option_types::enable, find_dial_channel(), and ast_dial_channel::options.
00967 { 00968 struct ast_dial_channel *channel = NULL; 00969 00970 /* Ensure we have required arguments */ 00971 if (!dial || AST_LIST_EMPTY(&dial->channels)) 00972 return -1; 00973 00974 if (!(channel = find_dial_channel(dial, num))) 00975 return -1; 00976 00977 /* If the option is already enabled, return failure */ 00978 if (channel->options[option]) 00979 return -1; 00980 00981 /* Execute enable callback if it exists, if not simply make sure the value is set */ 00982 if (option_types[option].enable) 00983 channel->options[option] = option_types[option].enable(data); 00984 else 00985 channel->options[option] = (void*)1; 00986 00987 return 0; 00988 }
int ast_dial_option_global_disable | ( | struct ast_dial * | dial, | |
enum ast_dial_option | option | |||
) |
Disables an option globally.
dial | Dial structure to disable option on | |
option | Option to disable |
Definition at line 995 of file dial.c.
References ast_option_types::disable, and ast_dial::options.
00996 { 00997 /* If the option is not enabled, return failure */ 00998 if (!dial->options[option]) { 00999 return -1; 01000 } 01001 01002 /* Execute callback of option to disable if it exists */ 01003 if (option_types[option].disable) 01004 option_types[option].disable(dial->options[option]); 01005 01006 /* Finally disable option on the structure */ 01007 dial->options[option] = NULL; 01008 01009 return 0; 01010 }
int ast_dial_option_global_enable | ( | struct ast_dial * | dial, | |
enum ast_dial_option | option, | |||
void * | data | |||
) |
Enables an option globally.
dial | Dial structure to enable option on | |
option | Option to enable | |
data | Data to pass to this option (not always needed) |
Definition at line 923 of file dial.c.
References ast_option_types::enable, and ast_dial::options.
Referenced by do_notify(), and page_exec().
00924 { 00925 /* If the option is already enabled, return failure */ 00926 if (dial->options[option]) 00927 return -1; 00928 00929 /* Execute enable callback if it exists, if not simply make sure the value is set */ 00930 if (option_types[option].enable) 00931 dial->options[option] = option_types[option].enable(data); 00932 else 00933 dial->options[option] = (void*)1; 00934 00935 return 0; 00936 }
enum ast_dial_result ast_dial_run | ( | struct ast_dial * | dial, | |
struct ast_channel * | chan, | |||
int | async | |||
) |
Execute dialing synchronously or asynchronously.
Definition at line 714 of file dial.c.
References ast_debug, ast_dial_hangup(), AST_DIAL_RESULT_FAILED, AST_DIAL_RESULT_INVALID, AST_DIAL_RESULT_TRYING, AST_LIST_EMPTY, ast_pthread_create, async_dial(), begin_dial(), ast_dial::channels, monitor_dial(), ast_dial::state, and ast_dial::thread.
Referenced by dial_trunk(), do_notify(), page_exec(), and sla_ring_station().
00715 { 00716 enum ast_dial_result res = AST_DIAL_RESULT_TRYING; 00717 00718 /* Ensure required arguments are passed */ 00719 if (!dial || (!chan && !async)) { 00720 ast_debug(1, "invalid #1\n"); 00721 return AST_DIAL_RESULT_INVALID; 00722 } 00723 00724 /* If there are no channels to dial we can't very well try to dial them */ 00725 if (AST_LIST_EMPTY(&dial->channels)) { 00726 ast_debug(1, "invalid #2\n"); 00727 return AST_DIAL_RESULT_INVALID; 00728 } 00729 00730 /* Dial each requested channel */ 00731 if (!begin_dial(dial, chan)) 00732 return AST_DIAL_RESULT_FAILED; 00733 00734 /* If we are running async spawn a thread and send it away... otherwise block here */ 00735 if (async) { 00736 dial->state = AST_DIAL_RESULT_TRYING; 00737 /* Try to create a thread */ 00738 if (ast_pthread_create(&dial->thread, NULL, async_dial, dial)) { 00739 /* Failed to create the thread - hangup all dialed channels and return failed */ 00740 ast_dial_hangup(dial); 00741 res = AST_DIAL_RESULT_FAILED; 00742 } 00743 } else { 00744 res = monitor_dial(dial, chan); 00745 } 00746 00747 return res; 00748 }
void ast_dial_set_global_timeout | ( | struct ast_dial * | dial, | |
int | timeout | |||
) |
Set the maximum time (globally) allowed for trying to ring phones.
dial | The dial structure to apply the time limit to | |
timeout | Maximum time allowed in milliseconds |
dial | The dial structure to apply the time limit to | |
timeout | Maximum time allowed |
Definition at line 1053 of file dial.c.
References ast_dial::actual_timeout, and ast_dial::timeout.
Referenced by do_notify(), and page_exec().
01054 { 01055 dial->timeout = timeout; 01056 01057 if (dial->timeout > 0 && (dial->actual_timeout > dial->timeout || dial->actual_timeout == -1)) 01058 dial->actual_timeout = dial->timeout; 01059 01060 return; 01061 }
void ast_dial_set_state_callback | ( | struct ast_dial * | dial, | |
ast_dial_state_callback | callback | |||
) |
Set a callback for state changes.
dial | The dial structure to watch for state changes | |
callback | the callback |
Definition at line 1043 of file dial.c.
References ast_dial::state_callback.
Referenced by sla_ring_station().
01044 { 01045 dial->state_callback = callback; 01046 }
void ast_dial_set_timeout | ( | struct ast_dial * | dial, | |
int | num, | |||
int | timeout | |||
) |
Set the maximum time (per channel) allowed for trying to ring the phone.
dial | The dial structure the channel belongs to | |
num | Channel number to set timeout on | |
timeout | Maximum time allowed in milliseconds |
dial | The dial structure the channel belongs to | |
num | Channel number to set timeout on | |
timeout | Maximum time allowed |
Definition at line 1069 of file dial.c.
References ast_dial::actual_timeout, find_dial_channel(), and ast_dial_channel::timeout.
01070 { 01071 struct ast_dial_channel *channel = NULL; 01072 01073 if (!(channel = find_dial_channel(dial, num))) 01074 return; 01075 01076 channel->timeout = timeout; 01077 01078 if (channel->timeout > 0 && (dial->actual_timeout > channel->timeout || dial->actual_timeout == -1)) 01079 dial->actual_timeout = channel->timeout; 01080 01081 return; 01082 }
enum ast_dial_result ast_dial_state | ( | struct ast_dial * | dial | ) |
Return state of dial.
dial | Dialing structure |
Definition at line 785 of file dial.c.
References ast_dial::state.
Referenced by dial_trunk(), and sla_handle_dial_state_event().
00786 { 00787 return dial->state; 00788 }