mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-21 09:10:36 +00:00
Cleanup chan_local.c:local_new().
* Remove t and ama local variables. There is no way they could be anything other than default because p->owner can only be NULL at this point. * Rename tmp and tmp2 to owner and chan respectively. * Remove redundant initialization of channel context, exten, priority. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387260 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -1216,75 +1216,64 @@ static struct local_pvt *local_alloc(const char *data, struct ast_format_cap *ca
|
|||||||
/*! \brief Start new local channel */
|
/*! \brief Start new local channel */
|
||||||
static struct ast_channel *local_new(struct local_pvt *p, int state, const char *linkedid, struct ast_callid *callid)
|
static struct ast_channel *local_new(struct local_pvt *p, int state, const char *linkedid, struct ast_callid *callid)
|
||||||
{
|
{
|
||||||
struct ast_channel *tmp = NULL, *tmp2 = NULL;
|
struct ast_channel *owner;
|
||||||
|
struct ast_channel *chan;
|
||||||
struct ast_format fmt;
|
struct ast_format fmt;
|
||||||
int generated_seqno = ast_atomic_fetchadd_int((int *)&name_sequence, +1);
|
int generated_seqno = ast_atomic_fetchadd_int((int *)&name_sequence, +1);
|
||||||
const char *t;
|
|
||||||
int ama;
|
|
||||||
|
|
||||||
/* Allocate two new Asterisk channels */
|
/*
|
||||||
/* safe accountcode */
|
* Allocate two new Asterisk channels
|
||||||
if (p->owner && ast_channel_accountcode(p->owner))
|
*
|
||||||
t = ast_channel_accountcode(p->owner);
|
* Make sure that the ;2 channel gets the same linkedid as ;1.
|
||||||
else
|
* You can't pass linkedid to both allocations since if linkedid
|
||||||
t = "";
|
* isn't set, then each channel will generate its own linkedid.
|
||||||
|
*/
|
||||||
if (p->owner)
|
if (!(owner = ast_channel_alloc(1, state, NULL, NULL, NULL,
|
||||||
ama = ast_channel_amaflags(p->owner);
|
p->exten, p->context, linkedid, 0,
|
||||||
else
|
"Local/%s@%s-%08x;1", p->exten, p->context, generated_seqno))
|
||||||
ama = 0;
|
|| !(chan = ast_channel_alloc(1, AST_STATE_RING, NULL, NULL, NULL,
|
||||||
|
p->exten, p->context, ast_channel_linkedid(owner), 0,
|
||||||
/* Make sure that the ;2 channel gets the same linkedid as ;1. You can't pass linkedid to both
|
"Local/%s@%s-%08x;2", p->exten, p->context, generated_seqno))) {
|
||||||
* allocations since if linkedid isn't set, then each channel will generate its own linkedid. */
|
if (owner) {
|
||||||
if (!(tmp = ast_channel_alloc(1, state, 0, 0, t, p->exten, p->context, linkedid, ama, "Local/%s@%s-%08x;1", p->exten, p->context, generated_seqno))
|
owner = ast_channel_release(owner);
|
||||||
|| !(tmp2 = ast_channel_alloc(1, AST_STATE_RING, 0, 0, t, p->exten, p->context, ast_channel_linkedid(tmp), ama, "Local/%s@%s-%08x;2", p->exten, p->context, generated_seqno))) {
|
|
||||||
if (tmp) {
|
|
||||||
tmp = ast_channel_release(tmp);
|
|
||||||
}
|
}
|
||||||
ast_log(LOG_WARNING, "Unable to allocate channel structure(s)\n");
|
ast_log(LOG_WARNING, "Unable to allocate channel structure(s)\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callid) {
|
if (callid) {
|
||||||
ast_channel_callid_set(tmp, callid);
|
ast_channel_callid_set(owner, callid);
|
||||||
ast_channel_callid_set(tmp2, callid);
|
ast_channel_callid_set(chan, callid);
|
||||||
}
|
}
|
||||||
|
|
||||||
ast_channel_tech_set(tmp, &local_tech);
|
ast_channel_tech_set(owner, &local_tech);
|
||||||
ast_channel_tech_set(tmp2, &local_tech);
|
ast_channel_tech_set(chan, &local_tech);
|
||||||
|
ast_channel_tech_pvt_set(owner, p);
|
||||||
|
ast_channel_tech_pvt_set(chan, p);
|
||||||
|
|
||||||
ast_format_cap_copy(ast_channel_nativeformats(tmp), p->reqcap);
|
ast_format_cap_copy(ast_channel_nativeformats(owner), p->reqcap);
|
||||||
ast_format_cap_copy(ast_channel_nativeformats(tmp2), p->reqcap);
|
ast_format_cap_copy(ast_channel_nativeformats(chan), p->reqcap);
|
||||||
|
|
||||||
/* Determine our read/write format and set it on each channel */
|
/* Determine our read/write format and set it on each channel */
|
||||||
ast_best_codec(p->reqcap, &fmt);
|
ast_best_codec(p->reqcap, &fmt);
|
||||||
ast_format_copy(ast_channel_writeformat(tmp), &fmt);
|
ast_format_copy(ast_channel_writeformat(owner), &fmt);
|
||||||
ast_format_copy(ast_channel_writeformat(tmp2), &fmt);
|
ast_format_copy(ast_channel_writeformat(chan), &fmt);
|
||||||
ast_format_copy(ast_channel_rawwriteformat(tmp), &fmt);
|
ast_format_copy(ast_channel_rawwriteformat(owner), &fmt);
|
||||||
ast_format_copy(ast_channel_rawwriteformat(tmp2), &fmt);
|
ast_format_copy(ast_channel_rawwriteformat(chan), &fmt);
|
||||||
ast_format_copy(ast_channel_readformat(tmp), &fmt);
|
ast_format_copy(ast_channel_readformat(owner), &fmt);
|
||||||
ast_format_copy(ast_channel_readformat(tmp2), &fmt);
|
ast_format_copy(ast_channel_readformat(chan), &fmt);
|
||||||
ast_format_copy(ast_channel_rawreadformat(tmp), &fmt);
|
ast_format_copy(ast_channel_rawreadformat(owner), &fmt);
|
||||||
ast_format_copy(ast_channel_rawreadformat(tmp2), &fmt);
|
ast_format_copy(ast_channel_rawreadformat(chan), &fmt);
|
||||||
|
|
||||||
ast_channel_tech_pvt_set(tmp, p);
|
ast_set_flag(ast_channel_flags(owner), AST_FLAG_DISABLE_DEVSTATE_CACHE);
|
||||||
ast_channel_tech_pvt_set(tmp2, p);
|
ast_set_flag(ast_channel_flags(chan), AST_FLAG_DISABLE_DEVSTATE_CACHE);
|
||||||
|
|
||||||
ast_set_flag(ast_channel_flags(tmp), AST_FLAG_DISABLE_DEVSTATE_CACHE);
|
p->owner = owner;
|
||||||
ast_set_flag(ast_channel_flags(tmp2), AST_FLAG_DISABLE_DEVSTATE_CACHE);
|
p->chan = chan;
|
||||||
|
|
||||||
p->owner = tmp;
|
ast_jb_configure(owner, &p->jb_conf);
|
||||||
p->chan = tmp2;
|
|
||||||
|
|
||||||
ast_channel_context_set(tmp, p->context);
|
return owner;
|
||||||
ast_channel_context_set(tmp2, p->context);
|
|
||||||
ast_channel_exten_set(tmp2, p->exten);
|
|
||||||
ast_channel_priority_set(tmp, 1);
|
|
||||||
ast_channel_priority_set(tmp2, 1);
|
|
||||||
|
|
||||||
ast_jb_configure(tmp, &p->jb_conf);
|
|
||||||
|
|
||||||
return tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! \brief Part of PBX interface */
|
/*! \brief Part of PBX interface */
|
||||||
|
|||||||
Reference in New Issue
Block a user