summaryrefslogtreecommitdiff
path: root/apps/app_cdr.c
diff options
context:
space:
mode:
authorMatthew Jordan <mjordan@digium.com>2014-01-12 22:13:12 +0000
committerMatthew Jordan <mjordan@digium.com>2014-01-12 22:13:12 +0000
commit373965dbff734b96132f61741838d6797c4a1876 (patch)
treedd6da807b85c32aa86f9bf7ac86b1b62152558c0 /apps/app_cdr.c
parentf8aaf585a39d496479eb8a4e55f2e327d02b37ca (diff)
CDRs: Synchronize dialplan applications that manipulate CDRs with the engine
In https://reviewboard.asterisk.org/r/3057/, applications and functions that manipulate CDRs were made to interact over Stasis. This was done to synchronize manipulations of CDRs from the dialplan with the updates the engine itself receives over the message bus. This change rested on a faulty premise: that messages published to the CDR topic or to a topic that forwards to the CDR topic are synchronized with the messages handled by the CDR topic subscription in the CDR engine. This is not the case. There is no ordering guaranteed for two messages published to the same topic; ordering is only guaranteed if a message is published to the same subscriber. Stasis was modified in r405311 to allow a publisher to synchronize on the subscriber. This patch uses that API to synchronize the CDR publishers with the CDR engine message router, which maintains the overall topic subscription. (closes issue ASTERISK-22884) Reported by: Matt Jordan Review: https://reviewboard.asterisk.org/r/3099/ ........ Merged revisions 405312 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@405314 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'apps/app_cdr.c')
-rw-r--r--apps/app_cdr.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/apps/app_cdr.c b/apps/app_cdr.c
index 2793846f9..bf4961a53 100644
--- a/apps/app_cdr.c
+++ b/apps/app_cdr.c
@@ -37,6 +37,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/module.h"
#include "asterisk/app.h"
#include "asterisk/stasis.h"
+#include "asterisk/stasis_message_router.h"
/*** DOCUMENTATION
<application name="NoCDR" language="en_US">
@@ -167,25 +168,22 @@ static void appcdr_callback(void *data, struct stasis_subscription *sub, struct
static int publish_app_cdr_message(struct ast_channel *chan, struct app_cdr_message_payload *payload)
{
RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
- RAII_VAR(struct stasis_subscription *, subscription, NULL, ao2_cleanup);
+ RAII_VAR(struct stasis_message_router *, router, ast_cdr_message_router(), ao2_cleanup);
- message = stasis_message_create(appcdr_message_type(), payload);
- if (!message) {
- ast_log(AST_LOG_WARNING, "Failed to manipulate CDR for channel %s: unable to create message\n",
- payload->channel_name);
+ if (!router) {
+ ast_log(AST_LOG_WARNING, "Failed to manipulate CDR for channel %s: no message router\n",
+ ast_channel_name(chan));
return -1;
}
- subscription = stasis_subscribe(ast_channel_topic(chan), appcdr_callback, NULL);
- if (!subscription) {
- ast_log(AST_LOG_WARNING, "Failed to manipulate CDR for channel %s: unable to create subscription\n",
+ message = stasis_message_create(appcdr_message_type(), payload);
+ if (!message) {
+ ast_log(AST_LOG_WARNING, "Failed to manipulate CDR for channel %s: unable to create message\n",
payload->channel_name);
return -1;
}
+ stasis_message_router_publish_sync(router, message);
- stasis_publish(ast_channel_topic(chan), message);
-
- subscription = stasis_unsubscribe_and_join(subscription);
return 0;
}
@@ -236,6 +234,11 @@ static int nocdr_exec(struct ast_channel *chan, const char *data)
static int unload_module(void)
{
+ RAII_VAR(struct stasis_message_router *, router, ast_cdr_message_router(), ao2_cleanup);
+
+ if (router) {
+ stasis_message_router_remove(router, appcdr_message_type());
+ }
STASIS_MESSAGE_TYPE_CLEANUP(appcdr_message_type);
ast_unregister_application(nocdr_app);
ast_unregister_application(resetcdr_app);
@@ -244,11 +247,18 @@ static int unload_module(void)
static int load_module(void)
{
+ RAII_VAR(struct stasis_message_router *, router, ast_cdr_message_router(), ao2_cleanup);
int res = 0;
+ if (!router) {
+ return AST_MODULE_LOAD_FAILURE;
+ }
+
res |= STASIS_MESSAGE_TYPE_INIT(appcdr_message_type);
res |= ast_register_application_xml(nocdr_app, nocdr_exec);
res |= ast_register_application_xml(resetcdr_app, resetcdr_exec);
+ res |= stasis_message_router_add(router, appcdr_message_type(),
+ appcdr_callback, NULL);
if (res) {
return AST_MODULE_LOAD_FAILURE;