diff options
author | Terry Wilson <twilson@digium.com> | 2012-01-09 22:15:50 +0000 |
---|---|---|
committer | Terry Wilson <twilson@digium.com> | 2012-01-09 22:15:50 +0000 |
commit | 04da92c3799e546fa4d84bdaeebd499fb64aea7a (patch) | |
tree | 9617b8b2d6d06f96ba27c0baefc5b93eb9e3bc5b /res/res_musiconhold.c | |
parent | 64d1b247c407de2af029392a6c32a99bf11c7ded (diff) |
Replace direct access to channel name with accessor functions
There are many benefits to making the ast_channel an opaque handle, from
increasing maintainability to presenting ways to kill masquerades. This patch
kicks things off by taking things a field at a time, renaming the field to
'__do_not_use_${fieldname}' and then writing setters/getters and converting the
existing code to using them. When all fields are done, we can move ast_channel
to a C file from channel.h and lop off the '__do_not_use_'.
This patch sets up main/channel_interal_api.c to be the only file that actually
accesses the ast_channel's fields directly. The intent would be for any API
functions in channel.c to use the accessor functions. No more monkeying around
with channel internals. We should use our own APIs.
The interesting changes in this patch are the addition of
channel_internal_api.c, the moving of the AST_DATA stuff from channel.c to
channel_internal_api.c (note: the AST_DATA stuff will have to be reworked to
use accessor functions when ast_channel is really opaque), and some re-working
of the way channel iterators/callbacks are handled so as to avoid creating fake
ast_channels on the stack to pass in matching data by directly accessing fields
(since "name" is a stringfield and the fake channel doesn't init the
stringfields, you can't use the ast_channel_name_set() function). I went with
ast_channel_name(chan) for a getter, and ast_channel_name_set(chan, name) for a
setter.
The majority of the grunt-work for this change was done by writing a semantic
patch using Coccinelle ( http://coccinelle.lip6.fr/ ).
Review: https://reviewboard.asterisk.org/r/1655/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@350223 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_musiconhold.c')
-rw-r--r-- | res/res_musiconhold.c | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c index 21a2c97e8..0b04c9d39 100644 --- a/res/res_musiconhold.c +++ b/res/res_musiconhold.c @@ -268,11 +268,11 @@ static void moh_files_release(struct ast_channel *chan, void *data) chan->stream = NULL; } - ast_verb(3, "Stopped music on hold on %s\n", chan->name); + ast_verb(3, "Stopped music on hold on %s\n", ast_channel_name(chan)); ast_format_clear(&state->mohwfmt); /* make sure to clear this format before restoring the original format. */ if (state->origwfmt.id && ast_set_write_format(chan, &state->origwfmt)) { - ast_log(LOG_WARNING, "Unable to restore channel '%s' to format '%s'\n", chan->name, ast_getformatname(&state->origwfmt)); + ast_log(LOG_WARNING, "Unable to restore channel '%s' to format '%s'\n", ast_channel_name(chan), ast_getformatname(&state->origwfmt)); } state->save_pos = state->pos; @@ -338,7 +338,7 @@ static int ast_moh_files_next(struct ast_channel *chan) /* Record the pointer to the filename for position resuming later */ ast_copy_string(state->save_pos_filename, state->class->filearray[state->pos], sizeof(state->save_pos_filename)); - ast_debug(1, "%s Opened file %d '%s'\n", chan->name, state->pos, state->class->filearray[state->pos]); + ast_debug(1, "%s Opened file %d '%s'\n", ast_channel_name(chan), state->pos, state->class->filearray[state->pos]); if (state->samples) { size_t loc; @@ -413,7 +413,7 @@ static int moh_files_generator(struct ast_channel *chan, void *data, int len, in res = ast_write(chan, f); ast_frfree(f); if (res < 0) { - ast_log(LOG_WARNING, "Failed to write frame to '%s': %s\n", chan->name, strerror(errno)); + ast_log(LOG_WARNING, "Failed to write frame to '%s': %s\n", ast_channel_name(chan), strerror(errno)); return -1; } } else { @@ -463,7 +463,7 @@ static void *moh_files_alloc(struct ast_channel *chan, void *params) ast_copy_string(state->name, class->name, sizeof(state->name)); state->save_total = class->total_files; - ast_verb(3, "Started music on hold, class '%s', on %s\n", class->name, chan->name); + ast_verb(3, "Started music on hold, class '%s', on %s\n", class->name, ast_channel_name(chan)); return chan->music_state; } @@ -782,7 +782,7 @@ static int play_moh_exec(struct ast_channel *chan, const char *data) class = S_OR(args.class, NULL); if (ast_moh_start(chan, class, NULL)) { - ast_log(LOG_WARNING, "Unable to start music on hold class '%s' on channel %s\n", class, chan->name); + ast_log(LOG_WARNING, "Unable to start music on hold class '%s' on channel %s\n", class, ast_channel_name(chan)); return 0; } @@ -812,7 +812,7 @@ static int wait_moh_exec(struct ast_channel *chan, const char *data) return -1; } if (ast_moh_start(chan, NULL, NULL)) { - ast_log(LOG_WARNING, "Unable to start music on hold for %d seconds on channel %s\n", atoi(data), chan->name); + ast_log(LOG_WARNING, "Unable to start music on hold for %d seconds on channel %s\n", atoi(data), ast_channel_name(chan)); return 0; } res = ast_safe_sleep(chan, atoi(data) * 1000); @@ -851,7 +851,7 @@ static int start_moh_exec(struct ast_channel *chan, const char *data) class = S_OR(args.class, NULL); if (ast_moh_start(chan, class, NULL)) - ast_log(LOG_WARNING, "Unable to start music on hold class '%s' on channel %s\n", class, chan->name); + ast_log(LOG_WARNING, "Unable to start music on hold class '%s' on channel %s\n", class, ast_channel_name(chan)); return 0; } @@ -948,10 +948,10 @@ static void moh_release(struct ast_channel *chan, void *data) } if (oldwfmt.id && ast_set_write_format(chan, &oldwfmt)) { ast_log(LOG_WARNING, "Unable to restore channel '%s' to format %s\n", - chan->name, ast_getformatname(&oldwfmt)); + ast_channel_name(chan), ast_getformatname(&oldwfmt)); } - ast_verb(3, "Stopped music on hold on %s\n", chan->name); + ast_verb(3, "Stopped music on hold on %s\n", ast_channel_name(chan)); } } @@ -980,13 +980,13 @@ static void *moh_alloc(struct ast_channel *chan, void *params) if ((res = mohalloc(class))) { ast_format_copy(&res->origwfmt, &chan->writeformat); if (ast_set_write_format(chan, &class->format)) { - ast_log(LOG_WARNING, "Unable to set channel '%s' to format '%s'\n", chan->name, ast_codec2str(&class->format)); + ast_log(LOG_WARNING, "Unable to set channel '%s' to format '%s'\n", ast_channel_name(chan), ast_codec2str(&class->format)); moh_release(NULL, res); res = NULL; } else { state->class = mohclass_ref(class, "Placing reference into state container"); } - ast_verb(3, "Started music on hold, class '%s', on channel '%s'\n", class->name, chan->name); + ast_verb(3, "Started music on hold, class '%s', on channel '%s'\n", class->name, ast_channel_name(chan)); } return res; } @@ -1000,7 +1000,7 @@ static int moh_generate(struct ast_channel *chan, void *data, int len, int sampl len = ast_codec_get_len(&moh->parent->format, samples); if (len > sizeof(buf) - AST_FRIENDLY_OFFSET) { - ast_log(LOG_WARNING, "Only doing %d of %d requested bytes on %s\n", (int)sizeof(buf), len, chan->name); + ast_log(LOG_WARNING, "Only doing %d of %d requested bytes on %s\n", (int)sizeof(buf), len, ast_channel_name(chan)); len = sizeof(buf) - AST_FRIENDLY_OFFSET; } res = read(moh->pipe[0], buf + AST_FRIENDLY_OFFSET/2, len); @@ -1012,7 +1012,7 @@ static int moh_generate(struct ast_channel *chan, void *data, int len, int sampl moh->f.samples = ast_codec_get_samples(&moh->f); if (ast_write(chan, &moh->f) < 0) { - ast_log(LOG_WARNING, "Failed to write frame to '%s': %s\n", chan->name, strerror(errno)); + ast_log(LOG_WARNING, "Failed to write frame to '%s': %s\n", ast_channel_name(chan), strerror(errno)); return -1; } @@ -1542,7 +1542,7 @@ static int local_ast_moh_start(struct ast_channel *chan, const char *mclass, con "Channel: %s\r\n" "UniqueID: %s\r\n" "Class: %s\r\n", - chan->name, chan->uniqueid, + ast_channel_name(chan), chan->uniqueid, mohclass->name); ast_set_flag(chan, AST_FLAG_MOH); @@ -1575,7 +1575,7 @@ static void local_ast_moh_stop(struct ast_channel *chan) "State: Stop\r\n" "Channel: %s\r\n" "UniqueID: %s\r\n", - chan->name, chan->uniqueid); + ast_channel_name(chan), chan->uniqueid); ast_channel_unlock(chan); } |