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 | |
ast_channel * | ast_dial_answered (struct ast_dial *dial) |
Return channel that answered. | |
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. | |
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. |
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.
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 | ) |
Return channel that answered.
dial | Dialing structure |
Definition at line 737 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().
00738 { 00739 if (!dial) 00740 return NULL; 00741 00742 return ((dial->state == AST_DIAL_RESULT_ANSWERED) ? AST_LIST_FIRST(&dial->channels)->owner : NULL); 00743 }
struct ast_channel* ast_dial_answered_steal | ( | struct ast_dial * | dial | ) |
Steal the channel that answered.
dial | Dialing structure |
Definition at line 749 of file dial.c.
References AST_DIAL_RESULT_ANSWERED, AST_LIST_FIRST, chan, ast_dial::channels, and ast_dial::state.
00750 { 00751 struct ast_channel *chan = NULL; 00752 00753 if (!dial) 00754 return NULL; 00755 00756 if (dial->state == AST_DIAL_RESULT_ANSWERED) { 00757 chan = AST_LIST_FIRST(&dial->channels)->owner; 00758 AST_LIST_FIRST(&dial->channels)->owner = NULL; 00759 } 00760 00761 return chan; 00762 }
int ast_dial_append | ( | struct ast_dial * | dial, | |
const char * | tech, | |||
const char * | device | |||
) |
Append a channel.
Definition at line 226 of file dial.c.
References ast_atomic_fetchadd_int(), ast_calloc, AST_LIST_INSERT_TAIL, ast_strdup, ast_dial::channels, ast_dial_channel::list, and ast_dial::num.
Referenced by dial_trunk(), page_exec(), and sla_ring_station().
00227 { 00228 struct ast_dial_channel *channel = NULL; 00229 00230 /* Make sure we have required arguments */ 00231 if (!dial || !tech || !device) 00232 return -1; 00233 00234 /* Allocate new memory for dialed channel structure */ 00235 if (!(channel = ast_calloc(1, sizeof(*channel)))) 00236 return -1; 00237 00238 /* Record technology and device for when we actually dial */ 00239 channel->tech = ast_strdup(tech); 00240 channel->device = ast_strdup(device); 00241 00242 /* Grab reference number from dial structure */ 00243 channel->num = ast_atomic_fetchadd_int(&dial->num, +1); 00244 00245 /* No timeout exists... yet */ 00246 channel->timeout = -1; 00247 00248 /* Insert into channels list */ 00249 AST_LIST_INSERT_TAIL(&dial->channels, channel, list); 00250 00251 return channel->num; 00252 }
struct ast_dial* ast_dial_create | ( | void | ) |
New dialing structure.
Definition at line 198 of file dial.c.
References ast_calloc, AST_LIST_HEAD_INIT, ast_mutex_init(), and AST_PTHREADT_NULL.
Referenced by dial_trunk(), page_exec(), and sla_ring_station().
00199 { 00200 struct ast_dial *dial = NULL; 00201 00202 /* Allocate new memory for structure */ 00203 if (!(dial = ast_calloc(1, sizeof(*dial)))) 00204 return NULL; 00205 00206 /* Initialize list of channels */ 00207 AST_LIST_HEAD_INIT(&dial->channels); 00208 00209 /* Initialize thread to NULL */ 00210 dial->thread = AST_PTHREADT_NULL; 00211 00212 /* No timeout exists... yet */ 00213 dial->timeout = -1; 00214 dial->actual_timeout = -1; 00215 00216 /* Can't forget about the lock */ 00217 ast_mutex_init(&dial->lock); 00218 00219 return dial; 00220 }
int ast_dial_destroy | ( | struct ast_dial * | dial | ) |
Destroys a dialing structure.
dial | Dialing structure to free |
Definition at line 849 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_dial::channels, ast_dial_channel::device, ast_dial_channel::list, option_types, ast_dial_channel::options, ast_dial_channel::owner, and ast_dial_channel::tech.
Referenced by dial_trunk(), page_exec(), run_station(), sla_hangup_stations(), sla_ring_station(), and sla_stop_ringing_station().
00850 { 00851 int i = 0; 00852 struct ast_dial_channel *channel = NULL; 00853 00854 if (!dial) 00855 return -1; 00856 00857 /* Hangup and deallocate all the dialed channels */ 00858 AST_LIST_LOCK(&dial->channels); 00859 AST_LIST_TRAVERSE_SAFE_BEGIN(&dial->channels, channel, list) { 00860 /* Disable any enabled options */ 00861 for (i = 0; i < AST_DIAL_OPTION_MAX; i++) { 00862 if (!channel->options[i]) 00863 continue; 00864 if (option_types[i].disable) 00865 option_types[i].disable(channel->options[i]); 00866 channel->options[i] = NULL; 00867 } 00868 /* Hang up channel if need be */ 00869 if (channel->owner) { 00870 ast_hangup(channel->owner); 00871 channel->owner = NULL; 00872 } 00873 /* Free structure */ 00874 ast_free(channel->tech); 00875 ast_free(channel->device); 00876 AST_LIST_REMOVE_CURRENT(list); 00877 ast_free(channel); 00878 } 00879 AST_LIST_TRAVERSE_SAFE_END; 00880 AST_LIST_UNLOCK(&dial->channels); 00881 00882 /* Disable any enabled options globally */ 00883 for (i = 0; i < AST_DIAL_OPTION_MAX; i++) { 00884 if (!dial->options[i]) 00885 continue; 00886 if (option_types[i].disable) 00887 option_types[i].disable(dial->options[i]); 00888 dial->options[i] = NULL; 00889 } 00890 00891 /* Lock be gone! */ 00892 ast_mutex_destroy(&dial->lock); 00893 00894 /* Free structure */ 00895 ast_free(dial); 00896 00897 return 0; 00898 }
void ast_dial_hangup | ( | struct ast_dial * | dial | ) |
Hangup channels.
dial | Dialing structure |
Definition at line 825 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().
00826 { 00827 struct ast_dial_channel *channel = NULL; 00828 00829 if (!dial) 00830 return; 00831 00832 AST_LIST_LOCK(&dial->channels); 00833 AST_LIST_TRAVERSE(&dial->channels, channel, list) { 00834 if (channel->owner) { 00835 ast_hangup(channel->owner); 00836 channel->owner = NULL; 00837 } 00838 } 00839 AST_LIST_UNLOCK(&dial->channels); 00840 00841 return; 00842 }
enum ast_dial_result ast_dial_join | ( | struct ast_dial * | dial | ) |
Cancel async thread.
dial | Dialing structure |
Definition at line 777 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, chan, ast_dial::channels, ast_dial::lock, ast_dial::state, and ast_dial::thread.
Referenced by dial_trunk(), page_exec(), run_station(), sla_hangup_stations(), sla_ring_station(), and sla_stop_ringing_station().
00778 { 00779 pthread_t thread; 00780 00781 /* If the dial structure is not running in async, return failed */ 00782 if (dial->thread == AST_PTHREADT_NULL) 00783 return AST_DIAL_RESULT_FAILED; 00784 00785 /* Record thread */ 00786 thread = dial->thread; 00787 00788 /* Boom, commence locking */ 00789 ast_mutex_lock(&dial->lock); 00790 00791 /* Stop the thread */ 00792 dial->thread = AST_PTHREADT_STOP; 00793 00794 /* If the answered channel is running an application we have to soft hangup it, can't just poke the thread */ 00795 AST_LIST_LOCK(&dial->channels); 00796 if (AST_LIST_FIRST(&dial->channels)->is_running_app) { 00797 struct ast_channel *chan = AST_LIST_FIRST(&dial->channels)->owner; 00798 if (chan) { 00799 ast_channel_lock(chan); 00800 ast_softhangup(chan, AST_SOFTHANGUP_EXPLICIT); 00801 ast_channel_unlock(chan); 00802 } 00803 } else { 00804 /* Now we signal it with SIGURG so it will break out of it's waitfor */ 00805 pthread_kill(thread, SIGURG); 00806 } 00807 AST_LIST_UNLOCK(&dial->channels); 00808 00809 /* Yay done with it */ 00810 ast_mutex_unlock(&dial->lock); 00811 00812 /* Finally wait for the thread to exit */ 00813 pthread_join(thread, NULL); 00814 00815 /* Yay thread is all gone */ 00816 dial->thread = AST_PTHREADT_NULL; 00817 00818 return dial->state; 00819 }
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 1001 of file dial.c.
References AST_LIST_EMPTY, ast_dial::channels, ast_option_types::disable, find_dial_channel(), option_types, and ast_dial_channel::options.
01002 { 01003 struct ast_dial_channel *channel = NULL; 01004 01005 /* Ensure we have required arguments */ 01006 if (!dial || AST_LIST_EMPTY(&dial->channels)) 01007 return -1; 01008 01009 if (!(channel = find_dial_channel(dial, num))) 01010 return -1; 01011 01012 /* If the option is not enabled, return failure */ 01013 if (!channel->options[option]) 01014 return -1; 01015 01016 /* Execute callback of option to disable it if it exists */ 01017 if (option_types[option].disable) 01018 option_types[option].disable(channel->options[option]); 01019 01020 /* Finally disable the option on the structure */ 01021 channel->options[option] = NULL; 01022 01023 return 0; 01024 }
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 949 of file dial.c.
References AST_LIST_EMPTY, ast_dial::channels, ast_option_types::enable, find_dial_channel(), option_types, and ast_dial_channel::options.
00950 { 00951 struct ast_dial_channel *channel = NULL; 00952 00953 /* Ensure we have required arguments */ 00954 if (!dial || AST_LIST_EMPTY(&dial->channels)) 00955 return -1; 00956 00957 if (!(channel = find_dial_channel(dial, num))) 00958 return -1; 00959 00960 /* If the option is already enabled, return failure */ 00961 if (channel->options[option]) 00962 return -1; 00963 00964 /* Execute enable callback if it exists, if not simply make sure the value is set */ 00965 if (option_types[option].enable) 00966 channel->options[option] = option_types[option].enable(data); 00967 else 00968 channel->options[option] = (void*)1; 00969 00970 return 0; 00971 }
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 978 of file dial.c.
References ast_option_types::disable, option_types, and ast_dial::options.
00979 { 00980 /* If the option is not enabled, return failure */ 00981 if (!dial->options[option]) { 00982 return -1; 00983 } 00984 00985 /* Execute callback of option to disable if it exists */ 00986 if (option_types[option].disable) 00987 option_types[option].disable(dial->options[option]); 00988 00989 /* Finally disable option on the structure */ 00990 dial->options[option] = NULL; 00991 00992 return 0; 00993 }
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 906 of file dial.c.
References ast_option_types::enable, option_types, and ast_dial::options.
Referenced by page_exec().
00907 { 00908 /* If the option is already enabled, return failure */ 00909 if (dial->options[option]) 00910 return -1; 00911 00912 /* Execute enable callback if it exists, if not simply make sure the value is set */ 00913 if (option_types[option].enable) 00914 dial->options[option] = option_types[option].enable(data); 00915 else 00916 dial->options[option] = (void*)1; 00917 00918 return 0; 00919 }
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 697 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(), chan, ast_dial::channels, monitor_dial(), ast_dial::state, and ast_dial::thread.
Referenced by dial_trunk(), page_exec(), and sla_ring_station().
00698 { 00699 enum ast_dial_result res = AST_DIAL_RESULT_TRYING; 00700 00701 /* Ensure required arguments are passed */ 00702 if (!dial || (!chan && !async)) { 00703 ast_debug(1, "invalid #1\n"); 00704 return AST_DIAL_RESULT_INVALID; 00705 } 00706 00707 /* If there are no channels to dial we can't very well try to dial them */ 00708 if (AST_LIST_EMPTY(&dial->channels)) { 00709 ast_debug(1, "invalid #2\n"); 00710 return AST_DIAL_RESULT_INVALID; 00711 } 00712 00713 /* Dial each requested channel */ 00714 if (!begin_dial(dial, chan)) 00715 return AST_DIAL_RESULT_FAILED; 00716 00717 /* If we are running async spawn a thread and send it away... otherwise block here */ 00718 if (async) { 00719 dial->state = AST_DIAL_RESULT_TRYING; 00720 /* Try to create a thread */ 00721 if (ast_pthread_create(&dial->thread, NULL, async_dial, dial)) { 00722 /* Failed to create the thread - hangup all dialed channels and return failed */ 00723 ast_dial_hangup(dial); 00724 res = AST_DIAL_RESULT_FAILED; 00725 } 00726 } else { 00727 res = monitor_dial(dial, chan); 00728 } 00729 00730 return res; 00731 }
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 |
Definition at line 1036 of file dial.c.
References ast_dial::actual_timeout, and ast_dial::timeout.
01037 { 01038 dial->timeout = timeout; 01039 01040 if (dial->timeout > 0 && dial->actual_timeout > dial->timeout) 01041 dial->actual_timeout = dial->timeout; 01042 01043 return; 01044 }
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 1026 of file dial.c.
References ast_dial::state_callback.
Referenced by sla_ring_station().
01027 { 01028 dial->state_callback = callback; 01029 }
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 |
Definition at line 1052 of file dial.c.
References ast_dial::actual_timeout, find_dial_channel(), and ast_dial_channel::timeout.
01053 { 01054 struct ast_dial_channel *channel = NULL; 01055 01056 if (!(channel = find_dial_channel(dial, num))) 01057 return; 01058 01059 channel->timeout = timeout; 01060 01061 if (channel->timeout > 0 && dial->actual_timeout > channel->timeout) 01062 dial->actual_timeout = channel->timeout; 01063 01064 return; 01065 }
enum ast_dial_result ast_dial_state | ( | struct ast_dial * | dial | ) |
Return state of dial.
dial | Dialing structure |
Definition at line 768 of file dial.c.
References ast_dial::state.
Referenced by dial_trunk(), and sla_handle_dial_state_event().
00769 { 00770 return dial->state; 00771 }