diff --git a/apps/app_dial.c b/apps/app_dial.c index 74f41c06dce2ac8dd660a4ae853d18ad3531446e..d3d37216aa5ca47c689d0fb99345a048de3bc2b7 100644 --- a/apps/app_dial.c +++ b/apps/app_dial.c @@ -972,6 +972,7 @@ static void do_forward(struct chanlist *o, struct cause_args *num, ast_channel_appl_set(c, "AppDial"); ast_channel_data_set(c, "(Outgoing Line)"); + ast_publish_channel_state(c); ast_channel_unlock(in); if (single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) { @@ -2453,6 +2454,8 @@ static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast ast_channel_appl_set(tc, "AppDial"); ast_channel_data_set(tc, "(Outgoing Line)"); + ast_publish_channel_state(tc); + memset(ast_channel_whentohangup(tc), 0, sizeof(*ast_channel_whentohangup(tc))); /* Determine CallerID to store in outgoing channel. */ diff --git a/include/asterisk/stasis_channels.h b/include/asterisk/stasis_channels.h index e361fc680efeb3aaa977e48794443fcd4302fc5a..5ead93d3a5b1b05c4aea27fb0498d3ca967a191e 100644 --- a/include/asterisk/stasis_channels.h +++ b/include/asterisk/stasis_channels.h @@ -297,6 +297,15 @@ void ast_channel_publish_dial(struct ast_channel *caller, const char *dialstring, const char *dialstatus); +/*! + * \since 12 + * \brief Publish in the \ref ast_channel_topic a \ref ast_channel_snapshot + * message indicating a change in channel state + * + * \param chan The channel whose state has changed + */ +void ast_publish_channel_state(struct ast_channel *chan); + /*! @} */ /*! diff --git a/main/channel.c b/main/channel.c index d63aeb2ba73a3d65b23ae7e85f52a1f5b8b7fcd7..0b2dedd637a33768f81084804bd7e1f447ab195a 100644 --- a/main/channel.c +++ b/main/channel.c @@ -816,26 +816,6 @@ int ast_str2cause(const char *name) return -1; } -static void publish_channel_state(struct ast_channel *chan) -{ - RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup); - RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup); - - snapshot = ast_channel_snapshot_create(chan); - if (!snapshot) { - ast_log(LOG_ERROR, "Allocation error\n"); - return; - } - - message = stasis_message_create(ast_channel_snapshot_type(), snapshot); - if (!message) { - return; - } - - ast_assert(ast_channel_topic(chan) != NULL); - stasis_publish(ast_channel_topic(chan), message); -} - static void publish_cache_clear(struct ast_channel *chan) { RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup); @@ -1176,7 +1156,7 @@ __ast_channel_alloc_ap(int needqueue, int state, const char *cid_num, const char * a lot of data into this func to do it here! */ if (ast_get_channel_tech(tech) || (tech2 && ast_get_channel_tech(tech2))) { - publish_channel_state(tmp); + ast_publish_channel_state(tmp); } ast_channel_internal_finalize(tmp); @@ -2885,7 +2865,7 @@ int ast_hangup(struct ast_channel *chan) ast_cc_offer(chan); - publish_channel_state(chan); + ast_publish_channel_state(chan); publish_cache_clear(chan); if (ast_channel_cdr(chan) && !ast_test_flag(ast_channel_cdr(chan), AST_CDR_FLAG_BRIDGED) && @@ -7144,7 +7124,7 @@ void ast_do_masquerade(struct ast_channel *original) ast_channel_redirecting_set(original, ast_channel_redirecting(clonechan)); ast_channel_redirecting_set(clonechan, &exchange.redirecting); - publish_channel_state(original); + ast_publish_channel_state(original); /* Restore original timing file descriptor */ ast_channel_set_fd(original, AST_TIMING_FD, ast_channel_timingfd(original)); @@ -7310,7 +7290,7 @@ void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char ast_cdr_setcid(ast_channel_cdr(chan), chan); } - publish_channel_state(chan); + ast_publish_channel_state(chan); ast_channel_unlock(chan); } @@ -7336,7 +7316,7 @@ void ast_channel_set_caller_event(struct ast_channel *chan, const struct ast_par ast_channel_lock(chan); ast_party_caller_set(ast_channel_caller(chan), caller, update); - publish_channel_state(chan); + ast_publish_channel_state(chan); if (ast_channel_cdr(chan)) { ast_cdr_setcid(ast_channel_cdr(chan), chan); } @@ -7363,7 +7343,7 @@ int ast_setstate(struct ast_channel *chan, enum ast_channel_state state) * we override what they are saying the state is and things go amuck. */ ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, (ast_test_flag(ast_channel_flags(chan), AST_FLAG_DISABLE_DEVSTATE_CACHE) ? AST_DEVSTATE_NOT_CACHABLE : AST_DEVSTATE_CACHABLE), name); - publish_channel_state(chan); + ast_publish_channel_state(chan); return 0; } diff --git a/main/dial.c b/main/dial.c index f8b0c97874cb49a10d8333c277562cedcc5756c7..da02f7a2367aecf7d713fb2c171dd6f3de8cc7dd 100644 --- a/main/dial.c +++ b/main/dial.c @@ -287,6 +287,7 @@ static int begin_dial_channel(struct ast_dial_channel *channel, struct ast_chann ast_channel_appl_set(channel->owner, "AppDial2"); ast_channel_data_set(channel->owner, "(Outgoing Line)"); + ast_publish_channel_state(channel->owner); memset(ast_channel_whentohangup(channel->owner), 0, sizeof(*ast_channel_whentohangup(channel->owner))); /* Inherit everything from he who spawned this dial */ diff --git a/main/stasis_channels.c b/main/stasis_channels.c index acae819394fe185332ba8924f69aac2cbe670beb..3df52d0b3702235a634939731bf434a0fe1d234b 100644 --- a/main/stasis_channels.c +++ b/main/stasis_channels.c @@ -417,6 +417,30 @@ void ast_channel_publish_varset(struct ast_channel *chan, const char *name, cons publish_message_for_channel_topics(msg, chan); } +void ast_publish_channel_state(struct ast_channel *chan) +{ + RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup); + RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup); + + ast_assert(chan != NULL); + if (!chan) { + return; + } + + snapshot = ast_channel_snapshot_create(chan); + if (!snapshot) { + return; + } + + message = stasis_message_create(ast_channel_snapshot_type(), snapshot); + if (!message) { + return; + } + + ast_assert(ast_channel_topic(chan) != NULL); + stasis_publish(ast_channel_topic(chan), message); +} + struct ast_json *ast_channel_snapshot_to_json(const struct ast_channel_snapshot *snapshot) { RAII_VAR(struct ast_json *, json_chan, NULL, ast_json_unref);