[asterisk-commits] russell: branch russell/indications r174877 - in /team/russell/indications: a...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Feb 11 10:05:29 CST 2009
Author: russell
Date: Wed Feb 11 10:05:29 2009
New Revision: 174877
URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=174877
Log:
Refcountify ast_tone_zone_sound
Modified:
team/russell/indications/apps/app_disa.c
team/russell/indications/apps/app_playtones.c
team/russell/indications/apps/app_read.c
team/russell/indications/apps/app_readexten.c
team/russell/indications/channels/chan_misdn.c
team/russell/indications/channels/chan_skinny.c
team/russell/indications/channels/chan_unistim.c
team/russell/indications/include/asterisk/indications.h
team/russell/indications/main/app.c
team/russell/indications/main/channel.c
team/russell/indications/main/indications.c
team/russell/indications/main/pbx.c
Modified: team/russell/indications/apps/app_disa.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/indications/apps/app_disa.c?view=diff&rev=174877&r1=174876&r2=174877
==============================================================================
--- team/russell/indications/apps/app_disa.c (original)
+++ team/russell/indications/apps/app_disa.c Wed Feb 11 10:05:29 2009
@@ -124,7 +124,7 @@
static void play_dialtone(struct ast_channel *chan, char *mailbox)
{
- const struct ast_tone_zone_sound *ts = NULL;
+ struct ast_tone_zone_sound *ts = NULL;
if (ast_app_has_voicemail(mailbox, NULL)) {
ts = ast_get_indication_tone(chan->zone, "dialrecall");
@@ -134,6 +134,7 @@
if (ts) {
ast_playtones_start(chan, 0, ts->data, 0);
+ ts = ast_tone_zone_sound_unref(ts);
} else {
ast_tonepair_start(chan, 350, 440, 0, 0);
}
Modified: team/russell/indications/apps/app_playtones.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/indications/apps/app_playtones.c?view=diff&rev=174877&r1=174876&r2=174877
==============================================================================
--- team/russell/indications/apps/app_playtones.c (original)
+++ team/russell/indications/apps/app_playtones.c Wed Feb 11 10:05:29 2009
@@ -85,8 +85,9 @@
ts = ast_get_indication_tone(chan->zone, str);
- if (ts && !ast_strlen_zero(ts->data)) {
+ if (ts) {
res = ast_playtones_start(chan, 0, ts->data, 0);
+ ts = ast_tone_zone_sound_unref(ts);
} else {
res = ast_playtones_start(chan, 0, str, 0);
}
Modified: team/russell/indications/apps/app_read.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/indications/apps/app_read.c?view=diff&rev=174877&r1=174876&r2=174877
==============================================================================
--- team/russell/indications/apps/app_read.c (original)
+++ team/russell/indications/apps/app_read.c Wed Feb 11 10:05:29 2009
@@ -188,7 +188,7 @@
return 0;
}
if (ast_test_flag(&flags, OPT_INDICATION)) {
- if (! ast_strlen_zero(arglist.filename)) {
+ if (!ast_strlen_zero(arglist.filename)) {
ts = ast_get_indication_tone(chan->zone, arglist.filename);
}
}
@@ -258,6 +258,10 @@
}
}
+ if (ts) {
+ ts = ast_tone_zone_sound_unref(ts);
+ }
+
if (ast_check_hangup(chan))
status = "HANGUP";
pbx_builtin_setvar_helper(chan, "READSTATUS", status);
Modified: team/russell/indications/apps/app_readexten.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/indications/apps/app_readexten.c?view=diff&rev=174877&r1=174876&r2=174877
==============================================================================
--- team/russell/indications/apps/app_readexten.c (original)
+++ team/russell/indications/apps/app_readexten.c Wed Feb 11 10:05:29 2009
@@ -251,6 +251,10 @@
}
} while (0);
+ if (ts) {
+ ts = ast_tone_zone_sound_unref(ts);
+ }
+
pbx_builtin_setvar_helper(chan, "READEXTENSTATUS", status);
return status[0] == 'H' ? -1 : 0;
Modified: team/russell/indications/channels/chan_misdn.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/indications/channels/chan_misdn.c?view=diff&rev=174877&r1=174876&r2=174877
==============================================================================
--- team/russell/indications/channels/chan_misdn.c (original)
+++ team/russell/indications/channels/chan_misdn.c Wed Feb 11 10:05:29 2009
@@ -379,7 +379,7 @@
* \brief Tone zone sound used for dialtone generation.
* \note Used as a boolean. Non-NULL to prod generation if enabled.
*/
- const struct ast_tone_zone_sound *ts;
+ struct ast_tone_zone_sound *ts;
/*!
* \brief Enables overlap dialing for the set amount of seconds. (0 = Disabled)
@@ -3405,7 +3405,9 @@
misdn_lib_tone_generator_stop(cl->bc);
ast_playtones_stop(ast);
- cl->ts = NULL;
+ if (cl->ts) {
+ cl->ts = ast_tone_zone_sound_unref((struct ast_tone_zone_sound *) cl->ts);
+ }
return 0;
}
Modified: team/russell/indications/channels/chan_skinny.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/indications/channels/chan_skinny.c?view=diff&rev=174877&r1=174876&r2=174877
==============================================================================
--- team/russell/indications/channels/chan_skinny.c (original)
+++ team/russell/indications/channels/chan_skinny.c Wed Feb 11 10:05:29 2009
@@ -3751,7 +3751,7 @@
{
struct skinny_subchannel *xferor; /* the sub doing the transferring */
struct skinny_subchannel *xferee; /* the sub being transferred */
- const struct ast_tone_zone_sound *ts = NULL;
+ struct ast_tone_zone_sound *ts = NULL;
if (ast_bridged_channel(sub->owner) || ast_bridged_channel(sub->related->owner)) {
if (sub->xferor) {
@@ -3774,8 +3774,10 @@
}
if (xferor->owner->_state == AST_STATE_RING) {
/* play ringing inband */
- ts = ast_get_indication_tone(xferor->owner->zone, "ring");
- ast_playtones_start(xferor->owner, 0, ts->data, 1);
+ if ((ts = ast_get_indication_tone(xferor->owner->zone, "ring"))) {
+ ast_playtones_start(xferor->owner, 0, ts->data, 1);
+ ts = ast_tone_zone_sound_unref(ts);
+ }
}
if (skinnydebug)
ast_debug(1, "Transfer Masquerading %s to %s\n",
@@ -3789,8 +3791,10 @@
ast_queue_control(xferee->owner, AST_CONTROL_UNHOLD);
if (xferor->owner->_state == AST_STATE_RING) {
/* play ringing inband */
- ts = ast_get_indication_tone(xferor->owner->zone, "ring");
- ast_playtones_start(xferor->owner, 0, ts->data, 1);
+ if ((ts = ast_get_indication_tone(xferor->owner->zone, "ring"))) {
+ ast_playtones_start(xferor->owner, 0, ts->data, 1);
+ ts = ast_tone_zone_sound_unref(ts);
+ }
}
if (skinnydebug)
ast_debug(1, "Transfer Masquerading %s to %s\n",
Modified: team/russell/indications/channels/chan_unistim.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/indications/channels/chan_unistim.c?view=diff&rev=174877&r1=174876&r2=174877
==============================================================================
--- team/russell/indications/channels/chan_unistim.c (original)
+++ team/russell/indications/channels/chan_unistim.c Wed Feb 11 10:05:29 2009
@@ -4060,10 +4060,11 @@
static void in_band_indication(struct ast_channel *ast, const struct ast_tone_zone *tz,
const char *indication)
{
- const struct ast_tone_zone_sound *ts = NULL;
+ struct ast_tone_zone_sound *ts = NULL;
if ((ts = ast_get_indication_tone(tz, indication))) {
ast_playtones_start(ast, 0, ts->data, 1);
+ ts = ast_tone_zone_sound_unref(ts);
} else {
ast_log(LOG_WARNING, "Unable to get indication tone for %s\n", indication);
}
Modified: team/russell/indications/include/asterisk/indications.h
URL: http://svn.digium.com/svn-view/asterisk/team/russell/indications/include/asterisk/indications.h?view=diff&rev=174877&r1=174876&r2=174877
==============================================================================
--- team/russell/indications/include/asterisk/indications.h (original)
+++ team/russell/indications/include/asterisk/indications.h Wed Feb 11 10:05:29 2009
@@ -207,4 +207,18 @@
*/
#define ast_tone_zone_ref(tz) ({ ao2_ref(tz, +1); (tz); })
+/*!
+ * \brief Release a reference to an ast_tone_zone_sound
+ *
+ * \return NULL
+ */
+#define ast_tone_zone_sound_unref(ts) ({ ao2_ref(ts, -1); (NULL); })
+
+/*!
+ * \brief Increase the reference count on an ast_tone_zone_sound
+ *
+ * \return The tone zone sound provided as an argument
+ */
+#define ast_tone_zone_sound_ref(ts) ({ ao2_ref(ts, +1); (ts); })
+
#endif /* _ASTERISK_INDICATIONS_H */
Modified: team/russell/indications/main/app.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/indications/main/app.c?view=diff&rev=174877&r1=174876&r2=174877
==============================================================================
--- team/russell/indications/main/app.c (original)
+++ team/russell/indications/main/app.c Wed Feb 11 10:05:29 2009
@@ -87,8 +87,9 @@
timeout = 5;
}
- if ((ts = ast_get_indication_tone(chan->zone, "dial")) && !ast_strlen_zero(ts->data)) {
+ if ((ts = ast_get_indication_tone(chan->zone, "dial"))) {
res = ast_playtones_start(chan, 0, ts->data, 0);
+ ts = ast_tone_zone_sound_unref(ts);
} else {
ast_log(LOG_NOTICE, "Huh....? no dial for indications?\n");
}
Modified: team/russell/indications/main/channel.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/indications/main/channel.c?view=diff&rev=174877&r1=174876&r2=174877
==============================================================================
--- team/russell/indications/main/channel.c (original)
+++ team/russell/indications/main/channel.c Wed Feb 11 10:05:29 2009
@@ -2906,7 +2906,7 @@
/* By using an enum, we'll get compiler warnings for values not handled
* in switch statements. */
enum ast_control_frame_type condition = _condition;
- const struct ast_tone_zone_sound *ts = NULL;
+ struct ast_tone_zone_sound *ts = NULL;
int res = -1;
ast_channel_lock(chan);
@@ -2977,10 +2977,11 @@
break;
}
- if (ts && ts->data[0]) {
+ if (ts) {
/* We have a tone to play, yay. */
ast_debug(1, "Driver for channel '%s' does not support indication %d, emulating it\n", chan->name, condition);
ast_playtones_start(chan, 0, ts->data, 1);
+ ts = ast_tone_zone_sound_unref(ts);
res = 0;
chan->visible_indication = condition;
}
Modified: team/russell/indications/main/indications.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/indications/main/indications.c?view=diff&rev=174877&r1=174876&r2=174877
==============================================================================
--- team/russell/indications/main/indications.c (original)
+++ team/russell/indications/main/indications.c Wed Feb 11 10:05:29 2009
@@ -465,6 +465,8 @@
/* Look through list of tones in the zone searching for the right one */
AST_LIST_TRAVERSE(&zone->tones, ts, entry) {
if (!strcasecmp(ts->name, indication)) {
+ /* Increase ref count for the reference we will return */
+ ts = ast_tone_zone_sound_ref(ts);
break;
}
}
@@ -474,8 +476,10 @@
return ts;
}
-static void ast_tone_zone_sound_destroy(struct ast_tone_zone_sound *ts)
-{
+static void ast_tone_zone_sound_destructor(void *obj)
+{
+ struct ast_tone_zone_sound *ts = obj;
+
/* Deconstify the 'const char *'s so the compiler doesn't complain. (but it's safe) */
if (ts->name) {
ast_free((char *) ts->name);
@@ -486,8 +490,6 @@
ast_free((char *) ts->data);
ts->data = NULL;
}
-
- ast_free(ts);
}
/*! \brief deallocate the passed tone zone */
@@ -497,7 +499,7 @@
struct ast_tone_zone_sound *current;
while ((current = AST_LIST_REMOVE_HEAD(&zone->tones, entry))) {
- ast_tone_zone_sound_destroy(current);
+ current = ast_tone_zone_sound_unref(current);
}
if (zone->ringcadence) {
@@ -559,25 +561,29 @@
{
struct ast_tone_zone_sound *ts;
+ if (ast_strlen_zero(indication) || ast_strlen_zero(tonelist)) {
+ return -1;
+ }
+
AST_LIST_TRAVERSE_SAFE_BEGIN(&zone->tones, ts, entry) {
if (!strcasecmp(indication, ts->name)) {
AST_LIST_REMOVE_CURRENT(entry);
- ast_tone_zone_sound_destroy(ts);
+ ts = ast_tone_zone_sound_unref(ts);
break;
}
}
AST_LIST_TRAVERSE_SAFE_END
- if (!(ts = ast_calloc(1, sizeof(*ts)))) {
+ if (!(ts = ao2_alloc(sizeof(*ts), ast_tone_zone_sound_destructor))) {
return -1;
}
if (!(ts->name = ast_strdup(indication)) || !(ts->data = ast_strdup(tonelist))) {
- ast_tone_zone_sound_destroy(ts);
- return -1;
- }
-
- AST_LIST_INSERT_TAIL(&zone->tones, ts, entry);
+ ts = ast_tone_zone_sound_unref(ts);
+ return -1;
+ }
+
+ AST_LIST_INSERT_TAIL(&zone->tones, ts, entry); /* Inherit reference */
return 0;
}
@@ -593,7 +599,7 @@
AST_LIST_TRAVERSE_SAFE_BEGIN(&zone->tones, ts, entry) {
if (!strcasecmp(indication, ts->name)) {
AST_LIST_REMOVE_CURRENT(entry);
- ast_tone_zone_sound_destroy(ts);
+ ts = ast_tone_zone_sound_unref(ts);
res = 0;
break;
}
@@ -767,6 +773,8 @@
ast_cli(a->fd, "=====================================\n");
}
+ ast_tone_zone_lock(tz);
+
ast_str_set(&buf, 0, "%-7.7s %-15.15s ", tz->country, "<ringcadence>");
for (j = 0; j < tz->nrringcadence; j++) {
ast_str_append(&buf, 0, "%d%s", tz->ringcadence[j],
@@ -779,6 +787,7 @@
ast_cli(a->fd, "%-7.7s %-15.15s %s\n", tz->country, ts->name, ts->data);
}
+ ast_tone_zone_unlock(tz);
tz = ast_tone_zone_unref(tz);
}
@@ -935,7 +944,7 @@
AST_LIST_TRAVERSE_SAFE_BEGIN(&zone->tones, s, entry) {
if (s->killme) {
AST_LIST_REMOVE_CURRENT(entry);
- ast_tone_zone_sound_destroy(s);
+ s = ast_tone_zone_sound_unref(s);
}
}
AST_LIST_TRAVERSE_SAFE_END
Modified: team/russell/indications/main/pbx.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/indications/main/pbx.c?view=diff&rev=174877&r1=174876&r2=174877
==============================================================================
--- team/russell/indications/main/pbx.c (original)
+++ team/russell/indications/main/pbx.c Wed Feb 11 10:05:29 2009
@@ -8540,9 +8540,10 @@
} else if (ast_test_flag(&flags, WAITEXTEN_MOH)) {
ast_indicate_data(chan, AST_CONTROL_HOLD, opts[0], strlen(opts[0]));
} else if (ast_test_flag(&flags, WAITEXTEN_DIALTONE)) {
- const struct ast_tone_zone_sound *ts = ast_get_indication_tone(chan->zone, "dial");
+ struct ast_tone_zone_sound *ts = ast_get_indication_tone(chan->zone, "dial");
if (ts) {
ast_playtones_start(chan, 0, ts->data, 0);
+ ts = ast_tone_zone_sound_unref(ts);
} else {
ast_tonepair_start(chan, 350, 440, 0, 0);
}
More information about the asterisk-commits
mailing list