dial.h File Reference

Dialing API. More...

This graph shows which files directly or indirectly include this file:

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_PREDIAL, AST_DIAL_OPTION_DIAL_REPLACES_SELF, AST_DIAL_OPTION_SELF_DESTROY, 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_channelast_dial_answered (struct ast_dial *dial)
 Return channel that answered.
struct ast_channelast_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, const struct ast_assigned_ids *assignedids)
 Append a channel.
struct ast_dialast_dial_create (void)
 New dialing structure.
int ast_dial_destroy (struct ast_dial *dial)
 Destroys a dialing structure.
struct ast_channelast_dial_get_channel (struct ast_dial *dial, int num)
 Get the dialing channel, if prerun has been executed.
void * ast_dial_get_user_data (struct ast_dial *dial)
 Return the user data on a dial 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.
int ast_dial_prerun (struct ast_dial *dial, struct ast_channel *chan, struct ast_format_cap *cap)
 Request all appended channels, but do not dial.
int ast_dial_reason (struct ast_dial *dial, int num)
 Get the reason an outgoing channel has failed.
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.
void ast_dial_set_user_data (struct ast_dial *dial, void *user_data)
 Set user data on a dial structure.
enum ast_dial_result ast_dial_state (struct ast_dial *dial)
 Return state of dial.
const char * ast_hangup_cause_to_dial_status (int hangup_cause)
 Convert a hangup cause to a publishable dial status.


Detailed Description

Dialing API.

Definition in file dial.h.


Typedef Documentation

typedef void(* ast_dial_state_callback)(struct ast_dial *)

Definition at line 39 of file dial.h.


Enumeration Type Documentation

List of options that are applicable either globally or per dialed channel.

Enumerator:
AST_DIAL_OPTION_RINGING  Always indicate ringing to caller
AST_DIAL_OPTION_ANSWER_EXEC  Execute application upon answer in async mode
AST_DIAL_OPTION_MUSIC  Play music on hold instead of ringing to the calling channel
AST_DIAL_OPTION_DISABLE_CALL_FORWARDING  Disable call forwarding on channels
AST_DIAL_OPTION_PREDIAL  Execute a predial subroutine before dialing
AST_DIAL_OPTION_DIAL_REPLACES_SELF  The dial operation is a replacement for the requester
AST_DIAL_OPTION_SELF_DESTROY  Destroy self at end of ast_dial_run
AST_DIAL_OPTION_MAX  End terminator -- must always remain last

Definition at line 42 of file dial.h.

00042                      {
00043    AST_DIAL_OPTION_RINGING,                 /*!< Always indicate ringing to caller */
00044    AST_DIAL_OPTION_ANSWER_EXEC,             /*!< Execute application upon answer in async mode */
00045    AST_DIAL_OPTION_MUSIC,                   /*!< Play music on hold instead of ringing to the calling channel */
00046    AST_DIAL_OPTION_DISABLE_CALL_FORWARDING, /*!< Disable call forwarding on channels */
00047    AST_DIAL_OPTION_PREDIAL,                 /*!< Execute a predial subroutine before dialing */
00048    AST_DIAL_OPTION_DIAL_REPLACES_SELF,      /*!< The dial operation is a replacement for the requester */
00049    AST_DIAL_OPTION_SELF_DESTROY,            /*!< Destroy self at end of ast_dial_run */
00050    AST_DIAL_OPTION_MAX,                     /*!< End terminator -- must always remain last */
00051 };

List of return codes for dial run API calls.

Enumerator:
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 54 of file dial.h.

00054                      {
00055    AST_DIAL_RESULT_INVALID,     /*!< Invalid options were passed to run function */
00056    AST_DIAL_RESULT_FAILED,      /*!< Attempts to dial failed before reaching critical state */
00057    AST_DIAL_RESULT_TRYING,      /*!< Currently trying to dial */
00058    AST_DIAL_RESULT_RINGING,     /*!< Dial is presently ringing */
00059    AST_DIAL_RESULT_PROGRESS,    /*!< Dial is presently progressing */
00060    AST_DIAL_RESULT_PROCEEDING,  /*!< Dial is presently proceeding */
00061    AST_DIAL_RESULT_ANSWERED,    /*!< A channel was answered */
00062    AST_DIAL_RESULT_TIMEOUT,     /*!< Timeout was tripped, nobody answered */
00063    AST_DIAL_RESULT_HANGUP,      /*!< Caller hung up */
00064    AST_DIAL_RESULT_UNANSWERED,  /*!< Nobody answered */
00065 };


Function Documentation

struct ast_channel* ast_dial_answered ( struct ast_dial dial  )  [read]

Return channel that answered.

Note:
Returns the Asterisk channel that answered
Parameters:
dial Dialing structure

Definition at line 963 of file dial.c.

References AST_DIAL_RESULT_ANSWERED, AST_LIST_FIRST, ast_dial::channels, NULL, and ast_dial::state.

Referenced by ari_originate_dial(), dial_trunk(), page_state_callback(), pbx_outgoing_exec(), and sla_handle_dial_state_event().

00964 {
00965    if (!dial)
00966       return NULL;
00967 
00968    return ((dial->state == AST_DIAL_RESULT_ANSWERED) ? AST_LIST_FIRST(&dial->channels)->owner : NULL);
00969 }

struct ast_channel* ast_dial_answered_steal ( struct ast_dial dial  )  [read]

Steal the channel that answered.

Note:
Returns the Asterisk channel that answered and removes it from the dialing structure
Parameters:
dial Dialing structure

Definition at line 975 of file dial.c.

References AST_DIAL_RESULT_ANSWERED, AST_LIST_FIRST, ast_dial::channels, NULL, and ast_dial::state.

Referenced by app_control_dial(), ari_originate_dial(), do_notify(), pbx_outgoing_exec(), and recall_callback().

00976 {
00977    struct ast_channel *chan = NULL;
00978 
00979    if (!dial)
00980       return NULL;
00981 
00982    if (dial->state == AST_DIAL_RESULT_ANSWERED) {
00983       chan = AST_LIST_FIRST(&dial->channels)->owner;
00984       AST_LIST_FIRST(&dial->channels)->owner = NULL;
00985    }
00986 
00987    return chan;
00988 }

int ast_dial_append ( struct ast_dial dial,
const char *  tech,
const char *  device,
const struct ast_assigned_ids assignedids 
)

Append a channel.

Note:
Appends a channel to a dialing structure
Returns:
Returns channel reference number on success, -1 on failure

Definition at line 254 of file dial.c.

References ast_dial_channel::assignedid1, ast_dial_channel::assignedid2, ast_atomic_fetchadd_int(), ast_calloc, AST_LIST_INSERT_TAIL, ast_strdup, ast_strlen_zero, ast_dial::channels, ast_dial_channel::device, ast_dial_channel::list, NULL, ast_dial::num, ast_dial_channel::num, ast_dial_channel::tech, ast_dial_channel::timeout, ast_assigned_ids::uniqueid, and ast_assigned_ids::uniqueid2.

Referenced by app_control_dial(), ari_channels_handle_originate_with_id(), dial_trunk(), do_notify(), page_exec(), pbx_outgoing_attempt(), recalling_enter(), and sla_ring_station().

00255 {
00256    struct ast_dial_channel *channel = NULL;
00257 
00258    /* Make sure we have required arguments */
00259    if (!dial || !tech || !device)
00260       return -1;
00261 
00262    /* Allocate new memory for dialed channel structure */
00263    if (!(channel = ast_calloc(1, sizeof(*channel))))
00264       return -1;
00265 
00266    /* Record technology and device for when we actually dial */
00267    channel->tech = ast_strdup(tech);
00268    channel->device = ast_strdup(device);
00269 
00270    /* Store the assigned id */
00271    if (assignedids && !ast_strlen_zero(assignedids->uniqueid)) {
00272       channel->assignedid1 = ast_strdup(assignedids->uniqueid);
00273 
00274       if (!ast_strlen_zero(assignedids->uniqueid2)) {
00275          channel->assignedid2 = ast_strdup(assignedids->uniqueid2);
00276       }
00277    }
00278 
00279    /* Grab reference number from dial structure */
00280    channel->num = ast_atomic_fetchadd_int(&dial->num, +1);
00281 
00282    /* No timeout exists... yet */
00283    channel->timeout = -1;
00284 
00285    /* Insert into channels list */
00286    AST_LIST_INSERT_TAIL(&dial->channels, channel, list);
00287 
00288    return channel->num;
00289 }

struct ast_dial* ast_dial_create ( void   )  [read]

New dialing structure.

Note:
Create a dialing structure
Returns:
Returns a calloc'd ast_dial structure, NULL on failure

Definition at line 226 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, NULL, ast_dial::thread, and ast_dial::timeout.

Referenced by app_control_dial(), ari_channels_handle_originate_with_id(), dial_trunk(), do_notify(), page_exec(), pbx_outgoing_attempt(), recalling_enter(), and sla_ring_station().

00227 {
00228    struct ast_dial *dial = NULL;
00229 
00230    /* Allocate new memory for structure */
00231    if (!(dial = ast_calloc(1, sizeof(*dial))))
00232       return NULL;
00233 
00234    /* Initialize list of channels */
00235    AST_LIST_HEAD_INIT(&dial->channels);
00236 
00237    /* Initialize thread to NULL */
00238    dial->thread = AST_PTHREADT_NULL;
00239 
00240    /* No timeout exists... yet */
00241    dial->timeout = -1;
00242    dial->actual_timeout = -1;
00243 
00244    /* Can't forget about the lock */
00245    ast_mutex_init(&dial->lock);
00246 
00247    return dial;
00248 }

int ast_dial_destroy ( struct ast_dial dial  ) 

Destroys a dialing structure.

Note:
Cancels dialing and destroys (free's) the given ast_dial structure
Parameters:
dial Dialing structure to free
Returns:
Returns 0 on success, -1 on failure
Note:
Destroys (free's) the given ast_dial structure
Parameters:
dial Dialing structure to free
Returns:
Returns 0 on success, -1 on failure

Definition at line 1073 of file dial.c.

References ast_dial_channel::assignedid1, ast_dial_channel::assignedid2, 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, NULL, ast_dial::options, ast_dial_channel::options, ast_dial_channel::owner, and ast_dial_channel::tech.

Referenced by app_control_dial(), ari_channels_handle_originate_with_id(), ari_originate_dial(), dial_trunk(), do_notify(), monitor_dial(), page_exec(), pbx_outgoing_destroy(), recalling_exit(), run_station(), sla_handle_dial_state_event(), sla_hangup_stations(), sla_ring_station(), and sla_stop_ringing_station().

01074 {
01075    int i = 0;
01076    struct ast_dial_channel *channel = NULL;
01077 
01078    if (!dial)
01079       return -1;
01080 
01081    /* Hangup and deallocate all the dialed channels */
01082    AST_LIST_LOCK(&dial->channels);
01083    AST_LIST_TRAVERSE_SAFE_BEGIN(&dial->channels, channel, list) {
01084       /* Disable any enabled options */
01085       for (i = 0; i < AST_DIAL_OPTION_MAX; i++) {
01086          if (!channel->options[i])
01087             continue;
01088          if (option_types[i].disable)
01089             option_types[i].disable(channel->options[i]);
01090          channel->options[i] = NULL;
01091       }
01092 
01093       /* Hang up channel if need be */
01094       ast_hangup(channel->owner);
01095       channel->owner = NULL;
01096 
01097       /* Free structure */
01098       ast_free(channel->tech);
01099       ast_free(channel->device);
01100       ast_free(channel->assignedid1);
01101       ast_free(channel->assignedid2);
01102 
01103       AST_LIST_REMOVE_CURRENT(list);
01104       ast_free(channel);
01105    }
01106    AST_LIST_TRAVERSE_SAFE_END;
01107    AST_LIST_UNLOCK(&dial->channels);
01108 
01109    /* Disable any enabled options globally */
01110    for (i = 0; i < AST_DIAL_OPTION_MAX; i++) {
01111       if (!dial->options[i])
01112          continue;
01113       if (option_types[i].disable)
01114          option_types[i].disable(dial->options[i]);
01115       dial->options[i] = NULL;
01116    }
01117 
01118    /* Lock be gone! */
01119    ast_mutex_destroy(&dial->lock);
01120 
01121    /* Free structure */
01122    ast_free(dial);
01123 
01124    return 0;
01125 }

struct ast_channel* ast_dial_get_channel ( struct ast_dial dial,
int  num 
) [read]

Get the dialing channel, if prerun has been executed.

Parameters:
dial Dial structure
num Channel number to get channel of
Returns:
Pointer to channel, without reference

Definition at line 1264 of file dial.c.

References AST_LIST_EMPTY, ast_dial::channels, find_dial_channel(), NULL, and ast_dial_channel::owner.

Referenced by ari_channels_handle_originate_with_id(), pbx_outgoing_attempt(), pbx_outgoing_state_callback(), and recalling_enter().

01265 {
01266    struct ast_dial_channel *channel;
01267 
01268    if (!dial || AST_LIST_EMPTY(&dial->channels) || !(channel = find_dial_channel(dial, num))) {
01269       return NULL;
01270    }
01271 
01272    return channel->owner;
01273 }

void* ast_dial_get_user_data ( struct ast_dial dial  ) 

Return the user data on a dial structure.

Parameters:
dial The dial structure
Returns:
A pointer to the user data

Definition at line 1285 of file dial.c.

References ast_dial::user_data.

Referenced by ari_originate_dial(), page_state_callback(), and recall_callback().

01286 {
01287    return dial->user_data;
01288 }

void ast_dial_hangup ( struct ast_dial dial  ) 

Hangup channels.

Note:
Hangup all active channels
Parameters:
dial Dialing structure

Definition at line 1051 of file dial.c.

References ast_hangup(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_dial::channels, ast_dial_channel::list, NULL, and ast_dial_channel::owner.

Referenced by ast_dial_run(), and page_exec().

01052 {
01053    struct ast_dial_channel *channel = NULL;
01054 
01055    if (!dial)
01056       return;
01057 
01058    AST_LIST_LOCK(&dial->channels);
01059    AST_LIST_TRAVERSE(&dial->channels, channel, list) {
01060       ast_hangup(channel->owner);
01061       channel->owner = NULL;
01062    }
01063    AST_LIST_UNLOCK(&dial->channels);
01064 
01065    return;
01066 }

enum ast_dial_result ast_dial_join ( struct ast_dial dial  ) 

Cancel async thread.

Note:
Cancel a running async thread
Parameters:
dial Dialing structure

Definition at line 1003 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, NULL, ast_dial::state, and ast_dial::thread.

Referenced by dial_trunk(), page_exec(), recalling_exit(), run_station(), sla_handle_dial_state_event(), sla_hangup_stations(), sla_ring_station(), and sla_stop_ringing_station().

01004 {
01005    pthread_t thread;
01006 
01007    /* If the dial structure is not running in async, return failed */
01008    if (dial->thread == AST_PTHREADT_NULL)
01009       return AST_DIAL_RESULT_FAILED;
01010 
01011    /* Record thread */
01012    thread = dial->thread;
01013 
01014    /* Boom, commence locking */
01015    ast_mutex_lock(&dial->lock);
01016 
01017    /* Stop the thread */
01018    dial->thread = AST_PTHREADT_STOP;
01019 
01020    /* If the answered channel is running an application we have to soft hangup it, can't just poke the thread */
01021    AST_LIST_LOCK(&dial->channels);
01022    if (AST_LIST_FIRST(&dial->channels)->is_running_app) {
01023       struct ast_channel *chan = AST_LIST_FIRST(&dial->channels)->owner;
01024       if (chan) {
01025          ast_channel_lock(chan);
01026          ast_softhangup(chan, AST_SOFTHANGUP_EXPLICIT);
01027          ast_channel_unlock(chan);
01028       }
01029    } else {
01030       /* Now we signal it with SIGURG so it will break out of it's waitfor */
01031       pthread_kill(thread, SIGURG);
01032    }
01033    AST_LIST_UNLOCK(&dial->channels);
01034 
01035    /* Yay done with it */
01036    ast_mutex_unlock(&dial->lock);
01037 
01038    /* Finally wait for the thread to exit */
01039    pthread_join(thread, NULL);
01040 
01041    /* Yay thread is all gone */
01042    dial->thread = AST_PTHREADT_NULL;
01043 
01044    return dial->state;
01045 }

int ast_dial_option_disable ( struct ast_dial dial,
int  num,
enum ast_dial_option  option 
)

Disables an option per channel.

Parameters:
dial Dial structure
num Channel number to disable option on
option Option to disable
Returns:
Returns 0 on success, -1 on failure

Definition at line 1228 of file dial.c.

References AST_LIST_EMPTY, ast_dial::channels, ast_option_types::disable, find_dial_channel(), NULL, and ast_dial_channel::options.

01229 {
01230    struct ast_dial_channel *channel = NULL;
01231 
01232    /* Ensure we have required arguments */
01233    if (!dial || AST_LIST_EMPTY(&dial->channels))
01234       return -1;
01235 
01236    if (!(channel = find_dial_channel(dial, num)))
01237       return -1;
01238 
01239    /* If the option is not enabled, return failure */
01240    if (!channel->options[option])
01241       return -1;
01242 
01243    /* Execute callback of option to disable it if it exists */
01244    if (option_types[option].disable)
01245       option_types[option].disable(channel->options[option]);
01246 
01247    /* Finally disable the option on the structure */
01248    channel->options[option] = NULL;
01249 
01250    return 0;
01251 }

int ast_dial_option_enable ( struct ast_dial dial,
int  num,
enum ast_dial_option  option,
void *  data 
)

Enables an option per channel.

Parameters:
dial Dial structure
num Channel number to enable option on
option Option to enable
data Data to pass to this option (not always needed)
Returns:
Returns 0 on success, -1 on failure

Definition at line 1176 of file dial.c.

References AST_LIST_EMPTY, ast_dial::channels, ast_option_types::enable, find_dial_channel(), NULL, and ast_dial_channel::options.

01177 {
01178    struct ast_dial_channel *channel = NULL;
01179 
01180    /* Ensure we have required arguments */
01181    if (!dial || AST_LIST_EMPTY(&dial->channels))
01182       return -1;
01183 
01184    if (!(channel = find_dial_channel(dial, num)))
01185       return -1;
01186 
01187    /* If the option is already enabled, return failure */
01188    if (channel->options[option])
01189       return -1;
01190 
01191    /* Execute enable callback if it exists, if not simply make sure the value is set */
01192    if (option_types[option].enable)
01193       channel->options[option] = option_types[option].enable(data);
01194    else
01195       channel->options[option] = (void*)1;
01196 
01197    return 0;
01198 }

int ast_dial_option_global_disable ( struct ast_dial dial,
enum ast_dial_option  option 
)

Disables an option globally.

Parameters:
dial Dial structure to disable option on
option Option to disable
Returns:
Returns 0 on success, -1 on failure

Definition at line 1205 of file dial.c.

References ast_option_types::disable, NULL, and ast_dial::options.

01206 {
01207    /* If the option is not enabled, return failure */
01208    if (!dial->options[option]) {
01209       return -1;
01210    }
01211 
01212    /* Execute callback of option to disable if it exists */
01213    if (option_types[option].disable)
01214       option_types[option].disable(dial->options[option]);
01215 
01216    /* Finally disable option on the structure */
01217    dial->options[option] = NULL;
01218 
01219    return 0;
01220 }

int ast_dial_option_global_enable ( struct ast_dial dial,
enum ast_dial_option  option,
void *  data 
)

Enables an option globally.

Parameters:
dial Dial structure to enable option on
option Option to enable
data Data to pass to this option (not always needed)
Returns:
Returns 0 on success, -1 on failure

Definition at line 1133 of file dial.c.

References ast_option_types::enable, and ast_dial::options.

Referenced by do_notify(), and page_exec().

01134 {
01135    /* If the option is already enabled, return failure */
01136    if (dial->options[option])
01137       return -1;
01138 
01139    /* Execute enable callback if it exists, if not simply make sure the value is set */
01140    if (option_types[option].enable)
01141       dial->options[option] = option_types[option].enable(data);
01142    else
01143       dial->options[option] = (void*)1;
01144 
01145    return 0;
01146 }

int ast_dial_prerun ( struct ast_dial dial,
struct ast_channel chan,
struct ast_format_cap cap 
)

Request all appended channels, but do not dial.

Parameters:
dial Dialing structure
chan Optional dialing channel
cap Optional requested capabilities
Return values:
-1 failure 0 success

Definition at line 379 of file dial.c.

References AST_DIAL_OPTION_PREDIAL, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_replace_subargument_delimiter(), ast_strlen_zero, begin_dial_prerun(), ast_dial::channels, ast_dial_channel::list, and ast_dial::options.

Referenced by ari_channels_handle_originate_with_id(), pbx_outgoing_attempt(), and recalling_enter().

00380 {
00381    struct ast_dial_channel *channel;
00382    int res = -1;
00383    char *predial_string = dial->options[AST_DIAL_OPTION_PREDIAL];
00384 
00385    if (!ast_strlen_zero(predial_string)) {
00386       ast_replace_subargument_delimiter(predial_string);
00387    }
00388 
00389    AST_LIST_LOCK(&dial->channels);
00390    AST_LIST_TRAVERSE(&dial->channels, channel, list) {
00391       if ((res = begin_dial_prerun(channel, chan, cap, predial_string))) {
00392          break;
00393       }
00394    }
00395    AST_LIST_UNLOCK(&dial->channels);
00396 
00397    return res;
00398 }

int ast_dial_reason ( struct ast_dial dial,
int  num 
)

Get the reason an outgoing channel has failed.

Parameters:
dial Dial structure
num Channel number to get the reason from
Returns:
Numerical cause code

Definition at line 1253 of file dial.c.

References AST_LIST_EMPTY, ast_dial_channel::cause, ast_dial::channels, and find_dial_channel().

Referenced by pbx_outgoing_attempt().

01254 {
01255    struct ast_dial_channel *channel;
01256 
01257    if (!dial || AST_LIST_EMPTY(&dial->channels) || !(channel = find_dial_channel(dial, num))) {
01258       return -1;
01259    }
01260 
01261    return channel->cause;
01262 }

enum ast_dial_result ast_dial_run ( struct ast_dial dial,
struct ast_channel chan,
int  async 
)

Execute dialing synchronously or asynchronously.

Note:
Dials channels in a dial structure.
Returns:
Returns dial result code. (TRYING/INVALID/FAILED/ANSWERED/TIMEOUT/UNANSWERED).

Definition at line 921 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, ast_read_threadstorage_callid(), async_dial(), begin_dial(), ast_dial::callid, ast_dial::channels, monitor_dial(), NULL, ast_dial::state, and ast_dial::thread.

Referenced by app_control_dial(), ari_originate_dial(), dial_trunk(), do_notify(), page_exec(), pbx_outgoing_exec(), recalling_enter(), and sla_ring_station().

00922 {
00923    enum ast_dial_result res = AST_DIAL_RESULT_TRYING;
00924 
00925    /* Ensure required arguments are passed */
00926    if (!dial) {
00927       ast_debug(1, "invalid #1\n");
00928       return AST_DIAL_RESULT_INVALID;
00929    }
00930 
00931    /* If there are no channels to dial we can't very well try to dial them */
00932    if (AST_LIST_EMPTY(&dial->channels)) {
00933       ast_debug(1, "invalid #2\n");
00934       return AST_DIAL_RESULT_INVALID;
00935    }
00936 
00937    /* Dial each requested channel */
00938    if (!begin_dial(dial, chan, async))
00939       return AST_DIAL_RESULT_FAILED;
00940 
00941    /* If we are running async spawn a thread and send it away... otherwise block here */
00942    if (async) {
00943       /* reference be released at dial destruction if it isn't NULL */
00944       dial->callid = ast_read_threadstorage_callid();
00945       dial->state = AST_DIAL_RESULT_TRYING;
00946       /* Try to create a thread */
00947       if (ast_pthread_create(&dial->thread, NULL, async_dial, dial)) {
00948          /* Failed to create the thread - hangup all dialed channels and return failed */
00949          ast_dial_hangup(dial);
00950          res = AST_DIAL_RESULT_FAILED;
00951       }
00952    } else {
00953       res = monitor_dial(dial, chan);
00954    }
00955 
00956    return res;
00957 }

void ast_dial_set_global_timeout ( struct ast_dial dial,
int  timeout 
)

Set the maximum time (globally) allowed for trying to ring phones.

Parameters:
dial The dial structure to apply the time limit to
timeout Maximum time allowed in milliseconds
Returns:
nothing
Parameters:
dial The dial structure to apply the time limit to
timeout Maximum time allowed
Returns:
nothing

Definition at line 1295 of file dial.c.

References ast_dial::actual_timeout, and ast_dial::timeout.

Referenced by app_control_dial(), ari_channels_handle_originate_with_id(), do_notify(), page_exec(), and pbx_outgoing_attempt().

01296 {
01297    dial->timeout = timeout;
01298 
01299    if (dial->timeout > 0 && (dial->actual_timeout > dial->timeout || dial->actual_timeout == -1))
01300       dial->actual_timeout = dial->timeout;
01301 
01302    return;
01303 }

void ast_dial_set_state_callback ( struct ast_dial dial,
ast_dial_state_callback  callback 
)

Set a callback for state changes.

Parameters:
dial The dial structure to watch for state changes
callback the callback
Returns:
nothing

Definition at line 1275 of file dial.c.

References ast_dial::state_callback.

Referenced by page_exec(), pbx_outgoing_attempt(), recalling_enter(), and sla_ring_station().

01276 {
01277    dial->state_callback = callback;
01278 }

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.

Parameters:
dial The dial structure the channel belongs to
num Channel number to set timeout on
timeout Maximum time allowed in milliseconds
Returns:
nothing
Parameters:
dial The dial structure the channel belongs to
num Channel number to set timeout on
timeout Maximum time allowed
Returns:
nothing

Definition at line 1311 of file dial.c.

References ast_dial::actual_timeout, find_dial_channel(), NULL, and ast_dial_channel::timeout.

01312 {
01313    struct ast_dial_channel *channel = NULL;
01314 
01315    if (!(channel = find_dial_channel(dial, num)))
01316       return;
01317 
01318    channel->timeout = timeout;
01319 
01320    if (channel->timeout > 0 && (dial->actual_timeout > channel->timeout || dial->actual_timeout == -1))
01321       dial->actual_timeout = channel->timeout;
01322 
01323    return;
01324 }

void ast_dial_set_user_data ( struct ast_dial dial,
void *  user_data 
)

Set user data on a dial structure.

Parameters:
dial The dial structure to set a user data pointer on
user_data The user data pointer
Returns:
nothing

Definition at line 1280 of file dial.c.

References ast_dial::user_data.

Referenced by ari_channels_handle_originate_with_id(), page_exec(), and recalling_enter().

01281 {
01282    dial->user_data = user_data;
01283 }

enum ast_dial_result ast_dial_state ( struct ast_dial dial  ) 

Return state of dial.

Note:
Returns the state of the dial attempt
Parameters:
dial Dialing structure

Definition at line 994 of file dial.c.

References ast_dial::state.

Referenced by dial_trunk(), page_state_callback(), pbx_outgoing_state_callback(), recall_callback(), and sla_handle_dial_state_event().

00995 {
00996    return dial->state;
00997 }

const char* ast_hangup_cause_to_dial_status ( int  hangup_cause  ) 

Convert a hangup cause to a publishable dial status.

Since:
12

Definition at line 726 of file dial.c.

References AST_CAUSE_BUSY, AST_CAUSE_CONGESTION, AST_CAUSE_NO_ANSWER, AST_CAUSE_NO_ROUTE_DESTINATION, and AST_CAUSE_UNREGISTERED.

Referenced by monitor_dial(), try_calling(), and wait_for_answer().

00727 {
00728    switch(hangup_cause) {
00729    case AST_CAUSE_BUSY:
00730       return "BUSY";
00731    case AST_CAUSE_CONGESTION:
00732       return "CONGESTION";
00733    case AST_CAUSE_NO_ROUTE_DESTINATION:
00734    case AST_CAUSE_UNREGISTERED:
00735       return "CHANUNAVAIL";
00736    case AST_CAUSE_NO_ANSWER:
00737    default:
00738       return "NOANSWER";
00739    }
00740 }


Generated on Thu Apr 16 06:30:39 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6