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_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. | |
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_state_callback (struct ast_dial *dial, ast_dial_state_callback callback) |
Set a callback for state changes. | |
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.
AST_DIAL_OPTION_RINGING | Always indicate ringing to caller |
AST_DIAL_OPTION_ANSWER_EXEC | Execute application upon answer in async mode |
AST_DIAL_OPTION_MAX | End terminator -- must always remain last |
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_MAX, /*!< End terminator -- must always remain last */ 00043 };
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 46 of file dial.h.
00046 { 00047 AST_DIAL_RESULT_INVALID, /*!< Invalid options were passed to run function */ 00048 AST_DIAL_RESULT_FAILED, /*!< Attempts to dial failed before reaching critical state */ 00049 AST_DIAL_RESULT_TRYING, /*!< Currently trying to dial */ 00050 AST_DIAL_RESULT_RINGING, /*!< Dial is presently ringing */ 00051 AST_DIAL_RESULT_PROGRESS, /*!< Dial is presently progressing */ 00052 AST_DIAL_RESULT_PROCEEDING, /*!< Dial is presently proceeding */ 00053 AST_DIAL_RESULT_ANSWERED, /*!< A channel was answered */ 00054 AST_DIAL_RESULT_TIMEOUT, /*!< Timeout was tripped, nobody answered */ 00055 AST_DIAL_RESULT_HANGUP, /*!< Caller hung up */ 00056 AST_DIAL_RESULT_UNANSWERED, /*!< Nobody answered */ 00057 };
struct ast_channel* ast_dial_answered | ( | struct ast_dial * | dial | ) | [read] |
Return channel that answered.
dial | Dialing structure |
Definition at line 594 of file dial.c.
References AST_DIAL_RESULT_ANSWERED, AST_LIST_FIRST, and ast_dial::state.
Referenced by dial_trunk(), and sla_handle_dial_state_event().
00595 { 00596 if (!dial) 00597 return NULL; 00598 00599 return ((dial->state == AST_DIAL_RESULT_ANSWERED) ? AST_LIST_FIRST(&dial->channels)->owner : NULL); 00600 }
int ast_dial_append | ( | struct ast_dial * | dial, | |
const char * | tech, | |||
const char * | device | |||
) |
Append a channel.
Definition at line 201 of file dial.c.
References ast_calloc, AST_LIST_INSERT_TAIL, ast_dial_channel::device, ast_dial::num, ast_dial_channel::num, and ast_dial_channel::tech.
Referenced by dial_trunk(), page_exec(), and sla_ring_station().
00202 { 00203 struct ast_dial_channel *channel = NULL; 00204 00205 /* Make sure we have required arguments */ 00206 if (!dial || !tech || !device) 00207 return -1; 00208 00209 /* Allocate new memory for dialed channel structure */ 00210 if (!(channel = ast_calloc(1, sizeof(*channel)))) 00211 return -1; 00212 00213 /* Record technology and device for when we actually dial */ 00214 channel->tech = tech; 00215 channel->device = device; 00216 00217 /* Grab reference number from dial structure */ 00218 channel->num = ast_atomic_fetchadd_int(&dial->num, +1); 00219 00220 /* Insert into channels list */ 00221 AST_LIST_INSERT_TAIL(&dial->channels, channel, list); 00222 00223 return channel->num; 00224 }
struct ast_dial* ast_dial_create | ( | void | ) | [read] |
New dialing structure.
Definition at line 180 of file dial.c.
References ast_calloc, AST_LIST_HEAD_INIT_NOLOCK, and AST_PTHREADT_NULL.
Referenced by dial_trunk(), page_exec(), and sla_ring_station().
00181 { 00182 struct ast_dial *dial = NULL; 00183 00184 /* Allocate new memory for structure */ 00185 if (!(dial = ast_calloc(1, sizeof(*dial)))) 00186 return NULL; 00187 00188 /* Initialize list of channels */ 00189 AST_LIST_HEAD_INIT_NOLOCK(&dial->channels); 00190 00191 /* Initialize thread to NULL */ 00192 dial->thread = AST_PTHREADT_NULL; 00193 00194 return dial; 00195 }
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 675 of file dial.c.
References AST_DIAL_OPTION_MAX, ast_hangup(), AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_option_types::disable, free, option_types, ast_dial::options, ast_dial_channel::options, and ast_dial_channel::owner.
Referenced by dial_trunk(), page_exec(), run_station(), sla_hangup_stations(), sla_ring_station(), and sla_stop_ringing_station().
00676 { 00677 int i = 0; 00678 struct ast_dial_channel *channel = NULL; 00679 00680 if (!dial) 00681 return -1; 00682 00683 /* Hangup and deallocate all the dialed channels */ 00684 AST_LIST_TRAVERSE_SAFE_BEGIN(&dial->channels, channel, list) { 00685 /* Disable any enabled options */ 00686 for (i = 0; i < AST_DIAL_OPTION_MAX; i++) { 00687 if (!channel->options[i]) 00688 continue; 00689 if (option_types[i].disable) 00690 option_types[i].disable(channel->options[i]); 00691 channel->options[i] = NULL; 00692 } 00693 /* Hang up channel if need be */ 00694 if (channel->owner) { 00695 ast_hangup(channel->owner); 00696 channel->owner = NULL; 00697 } 00698 /* Free structure */ 00699 AST_LIST_REMOVE_CURRENT(&dial->channels, list); 00700 free(channel); 00701 } 00702 AST_LIST_TRAVERSE_SAFE_END; 00703 00704 /* Disable any enabled options globally */ 00705 for (i = 0; i < AST_DIAL_OPTION_MAX; i++) { 00706 if (!dial->options[i]) 00707 continue; 00708 if (option_types[i].disable) 00709 option_types[i].disable(dial->options[i]); 00710 dial->options[i] = NULL; 00711 } 00712 00713 /* Free structure */ 00714 free(dial); 00715 00716 return 0; 00717 }
void ast_dial_hangup | ( | struct ast_dial * | dial | ) |
Hangup channels.
dial | Dialing structure |
Definition at line 653 of file dial.c.
References ast_hangup(), AST_LIST_TRAVERSE, and ast_dial_channel::owner.
Referenced by ast_dial_run(), and page_exec().
00654 { 00655 struct ast_dial_channel *channel = NULL; 00656 00657 if (!dial) 00658 return; 00659 00660 AST_LIST_TRAVERSE(&dial->channels, channel, list) { 00661 if (channel->owner) { 00662 ast_hangup(channel->owner); 00663 channel->owner = NULL; 00664 } 00665 } 00666 00667 return; 00668 }
enum ast_dial_result ast_dial_join | ( | struct ast_dial * | dial | ) |
Cancel async thread.
dial | Dialing structure |
Definition at line 615 of file dial.c.
References ast_channel_lock, ast_channel_unlock, AST_DIAL_RESULT_FAILED, AST_LIST_FIRST, AST_PTHREADT_NULL, AST_PTHREADT_STOP, ast_softhangup(), AST_SOFTHANGUP_EXPLICIT, and ast_dial::state.
Referenced by dial_trunk(), page_exec(), run_station(), sla_hangup_stations(), sla_ring_station(), and sla_stop_ringing_station().
00616 { 00617 pthread_t thread; 00618 00619 /* If the dial structure is not running in async, return failed */ 00620 if (dial->thread == AST_PTHREADT_NULL) 00621 return AST_DIAL_RESULT_FAILED; 00622 00623 /* Record thread */ 00624 thread = dial->thread; 00625 00626 /* Stop the thread */ 00627 dial->thread = AST_PTHREADT_STOP; 00628 00629 /* If the answered channel is running an application we have to soft hangup it, can't just poke the thread */ 00630 if (AST_LIST_FIRST(&dial->channels)->is_running_app) { 00631 struct ast_channel *chan = AST_LIST_FIRST(&dial->channels)->owner; 00632 ast_channel_lock(chan); 00633 ast_softhangup(chan, AST_SOFTHANGUP_EXPLICIT); 00634 ast_channel_unlock(chan); 00635 } else { 00636 /* Now we signal it with SIGURG so it will break out of it's waitfor */ 00637 pthread_kill(thread, SIGURG); 00638 } 00639 00640 /* Finally wait for the thread to exit */ 00641 pthread_join(thread, NULL); 00642 00643 /* Yay thread is all gone */ 00644 dial->thread = AST_PTHREADT_NULL; 00645 00646 return dial->state; 00647 }
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 809 of file dial.c.
References AST_LIST_EMPTY, AST_LIST_LAST, AST_LIST_TRAVERSE, ast_option_types::disable, ast_dial_channel::num, option_types, and ast_dial_channel::options.
00810 { 00811 struct ast_dial_channel *channel = NULL; 00812 00813 /* Ensure we have required arguments */ 00814 if (!dial || AST_LIST_EMPTY(&dial->channels)) 00815 return -1; 00816 00817 /* Look for channel, we can sort of cheat and predict things - the last channel in the list will probably be what they want */ 00818 if (AST_LIST_LAST(&dial->channels)->num != num) { 00819 AST_LIST_TRAVERSE(&dial->channels, channel, list) { 00820 if (channel->num == num) 00821 break; 00822 } 00823 } else { 00824 channel = AST_LIST_LAST(&dial->channels); 00825 } 00826 00827 /* If none found, return failure */ 00828 if (!channel) 00829 return -1; 00830 00831 /* If the option is not enabled, return failure */ 00832 if (!channel->options[option]) 00833 return -1; 00834 00835 /* Execute callback of option to disable it if it exists */ 00836 if (option_types[option].disable) 00837 option_types[option].disable(channel->options[option]); 00838 00839 /* Finally disable the option on the structure */ 00840 channel->options[option] = NULL; 00841 00842 return 0; 00843 }
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 747 of file dial.c.
References AST_LIST_EMPTY, AST_LIST_LAST, AST_LIST_TRAVERSE, ast_option_types::enable, ast_dial_channel::num, option_types, and ast_dial_channel::options.
00748 { 00749 struct ast_dial_channel *channel = NULL; 00750 00751 /* Ensure we have required arguments */ 00752 if (!dial || AST_LIST_EMPTY(&dial->channels)) 00753 return -1; 00754 00755 /* Look for channel, we can sort of cheat and predict things - the last channel in the list will probably be what they want */ 00756 if (AST_LIST_LAST(&dial->channels)->num != num) { 00757 AST_LIST_TRAVERSE(&dial->channels, channel, list) { 00758 if (channel->num == num) 00759 break; 00760 } 00761 } else { 00762 channel = AST_LIST_LAST(&dial->channels); 00763 } 00764 00765 /* If none found, return failure */ 00766 if (!channel) 00767 return -1; 00768 00769 /* If the option is already enabled, return failure */ 00770 if (channel->options[option]) 00771 return -1; 00772 00773 /* Execute enable callback if it exists, if not simply make sure the value is set */ 00774 if (option_types[option].enable) 00775 channel->options[option] = option_types[option].enable(data); 00776 else 00777 channel->options[option] = (void*)1; 00778 00779 return 0; 00780 }
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 787 of file dial.c.
References ast_option_types::disable, option_types, and ast_dial::options.
00788 { 00789 /* If the option is not enabled, return failure */ 00790 if (!dial->options[option]) 00791 return -1; 00792 00793 /* Execute callback of option to disable if it exists */ 00794 if (option_types[option].disable) 00795 option_types[option].disable(dial->options[option]); 00796 00797 /* Finally disable option on the structure */ 00798 dial->options[option] = NULL; 00799 00800 return 0; 00801 }
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 725 of file dial.c.
References ast_option_types::enable, option_types, and ast_dial::options.
Referenced by page_exec().
00726 { 00727 /* If the option is already enabled, return failure */ 00728 if (dial->options[option]) 00729 return -1; 00730 00731 /* Execute enable callback if it exists, if not simply make sure the value is set */ 00732 if (option_types[option].enable) 00733 dial->options[option] = option_types[option].enable(data); 00734 else 00735 dial->options[option] = (void*)1; 00736 00737 return 0; 00738 }
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 554 of file dial.c.
References ast_dial_hangup(), AST_DIAL_RESULT_FAILED, AST_DIAL_RESULT_INVALID, AST_DIAL_RESULT_TRYING, AST_LIST_EMPTY, ast_log(), ast_pthread_create, async_dial(), begin_dial(), LOG_DEBUG, monitor_dial(), and ast_dial::state.
Referenced by dial_trunk(), page_exec(), and sla_ring_station().
00555 { 00556 enum ast_dial_result res = AST_DIAL_RESULT_TRYING; 00557 00558 /* Ensure required arguments are passed */ 00559 if (!dial || (!chan && !async)) { 00560 ast_log(LOG_DEBUG, "invalid #1\n"); 00561 return AST_DIAL_RESULT_INVALID; 00562 } 00563 00564 /* If there are no channels to dial we can't very well try to dial them */ 00565 if (AST_LIST_EMPTY(&dial->channels)) { 00566 ast_log(LOG_DEBUG, "invalid #2\n"); 00567 return AST_DIAL_RESULT_INVALID; 00568 } 00569 00570 /* Dial each requested channel */ 00571 if (!begin_dial(dial, chan)) 00572 return AST_DIAL_RESULT_FAILED; 00573 00574 /* If we are running async spawn a thread and send it away... otherwise block here */ 00575 if (async) { 00576 dial->state = AST_DIAL_RESULT_TRYING; 00577 /* Try to create a thread */ 00578 if (ast_pthread_create(&dial->thread, NULL, async_dial, dial)) { 00579 /* Failed to create the thread - hangup all dialed channels and return failed */ 00580 ast_dial_hangup(dial); 00581 res = AST_DIAL_RESULT_FAILED; 00582 } 00583 } else { 00584 res = monitor_dial(dial, chan); 00585 } 00586 00587 return res; 00588 }
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 845 of file dial.c.
References ast_dial::state_callback.
Referenced by sla_ring_station().
00846 { 00847 dial->state_callback = callback; 00848 }
enum ast_dial_result ast_dial_state | ( | struct ast_dial * | dial | ) |
Return state of dial.
dial | Dialing structure |
Definition at line 606 of file dial.c.
References ast_dial::state.
Referenced by dial_trunk(), and sla_handle_dial_state_event().
00607 { 00608 return dial->state; 00609 }