[svn-commits] russell: branch russell/chan_refcount r82325 - /team/russell/chan_refcount/res/
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Thu Sep 13 10:44:22 CDT 2007
Author: russell
Date: Thu Sep 13 10:44:22 2007
New Revision: 82325
URL: http://svn.digium.com/view/asterisk?view=rev&rev=82325
Log:
Convert res_monitor to new ast_channel_get function
Modified:
team/russell/chan_refcount/res/res_monitor.c
Modified: team/russell/chan_refcount/res/res_monitor.c
URL: http://svn.digium.com/view/asterisk/team/russell/chan_refcount/res/res_monitor.c?view=diff&rev=82325&r1=82324&r2=82325
==============================================================================
--- team/russell/chan_refcount/res/res_monitor.c (original)
+++ team/russell/chan_refcount/res/res_monitor.c Thu Sep 13 10:44:22 2007
@@ -541,23 +541,25 @@
const char *format = astman_get_header(m, "Format");
const char *mix = astman_get_header(m, "Mix");
char *d;
+ int res = 0;
if (ast_strlen_zero(name)) {
astman_send_error(s, m, "No channel specified");
return 0;
}
- c = ast_get_channel_by_name_locked(name);
- if (!c) {
+
+ if (!(c = ast_channel_get_by_name(name))) {
astman_send_error(s, m, "No such channel");
return 0;
}
+
+ ast_channel_lock(c);
if (ast_strlen_zero(fname)) {
/* No filename base specified, default to channel name as per CLI */
if (!(fname = ast_strdup(c->name))) {
- astman_send_error(s, m, "Could not start monitoring channel");
- ast_channel_unlock(c);
- return 0;
+ res = -1;
+ goto return_cleanup;
}
/* Channels have the format technology/channel_name - have to replace that / */
if ((d = strchr(fname, '/')))
@@ -566,18 +568,23 @@
if (ast_monitor_start(c, format, fname, 1, X_REC_IN | X_REC_OUT)) {
if (ast_monitor_change_fname(c, fname, 1)) {
- astman_send_error(s, m, "Could not start monitoring channel");
- ast_channel_unlock(c);
- return 0;
- }
- }
-
- if (ast_true(mix)) {
+ res = -1;
+ goto return_cleanup;
+ }
+ }
+
+ if (ast_true(mix))
ast_monitor_setjoinfiles(c, 1);
- }
-
+
+return_cleanup:
ast_channel_unlock(c);
- astman_send_ack(s, m, "Started monitoring channel");
+ ast_channel_unref(c);
+
+ if (res)
+ astman_send_error(s, m, "Could not start monitoring channel");
+ else
+ astman_send_ack(s, m, "Started monitoring channel");
+
return 0;
}
@@ -592,22 +599,28 @@
struct ast_channel *c = NULL;
const char *name = astman_get_header(m, "Channel");
int res;
+
if (ast_strlen_zero(name)) {
astman_send_error(s, m, "No channel specified");
return 0;
}
- c = ast_get_channel_by_name_locked(name);
- if (!c) {
+
+ if (!(c = ast_channel_get_by_name(name))) {
astman_send_error(s, m, "No such channel");
return 0;
}
+
+ ast_channel_lock(c);
res = ast_monitor_stop(c, 1);
ast_channel_unlock(c);
- if (res) {
+
+ ast_channel_unref(c);
+
+ if (res)
astman_send_error(s, m, "Could not stop monitoring channel");
- return 0;
- }
- astman_send_ack(s, m, "Stopped monitoring channel");
+ else
+ astman_send_ack(s, m, "Stopped monitoring channel");
+
return 0;
}
@@ -625,26 +638,34 @@
struct ast_channel *c = NULL;
const char *name = astman_get_header(m, "Channel");
const char *fname = astman_get_header(m, "File");
+ int res;
+
if (ast_strlen_zero(name)) {
astman_send_error(s, m, "No channel specified");
return 0;
}
+
if (ast_strlen_zero(fname)) {
astman_send_error(s, m, "No filename specified");
return 0;
}
- c = ast_get_channel_by_name_locked(name);
- if (!c) {
+
+ if (!(c = ast_channel_get_by_name(name))) {
astman_send_error(s, m, "No such channel");
return 0;
}
- if (ast_monitor_change_fname(c, fname, 1)) {
+
+ ast_channel_lock(c);
+ res = ast_monitor_change_fname(c, fname, 1);
+ ast_channel_unlock(c);
+
+ ast_channel_unref(c);
+
+ if (res)
astman_send_error(s, m, "Could not change monitored filename of channel");
- ast_channel_unlock(c);
- return 0;
- }
- ast_channel_unlock(c);
- astman_send_ack(s, m, "Changed monitor filename");
+ else
+ astman_send_ack(s, m, "Changed monitor filename");
+
return 0;
}
@@ -670,19 +691,21 @@
return -1;
}
- c = ast_get_channel_by_name_locked(name);
- if (!c) {
+ if (!(c = ast_channel_get_by_name(name))) {
astman_send_error(s, m, "No such channel");
return -1;
}
- if (action == MONITOR_ACTION_PAUSE)
- ast_monitor_pause(c);
- else
- ast_monitor_unpause(c);
-
+ ast_channel_lock(c);
+ (action == MONITOR_ACTION_PAUSE) ? ast_monitor_pause(c) : ast_monitor_unpause(c);
ast_channel_unlock(c);
- astman_send_ack(s, m, (action == MONITOR_ACTION_PAUSE ? "Paused monitoring of the channel" : "Unpaused monitoring of the channel"));
+
+ ast_channel_unref(c);
+
+ astman_send_ack(s, m,
+ (action == MONITOR_ACTION_PAUSE ? "Paused monitoring of the channel" :
+ "Unpaused monitoring of the channel"));
+
return 0;
}
More information about the svn-commits
mailing list