Mon Jun 27 16:50:49 2011

Asterisk developer's documentation


autochan.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2009, Digium, Inc.
00005  *
00006  * Mark Michelson <mmichelson@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*!
00020  * \file
00021  * \brief "smart" channels
00022  *
00023  * \author Mark Michelson <mmichelson@digium.com>
00024  */
00025 
00026 #include "asterisk.h"
00027 
00028 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 190423 $")
00029 
00030 #include "asterisk/autochan.h"
00031 #include "asterisk/utils.h"
00032 #include "asterisk/linkedlists.h"
00033 #include "asterisk/options.h"
00034 #include "asterisk/channel.h"
00035 
00036 struct ast_autochan *ast_autochan_setup(struct ast_channel *chan)
00037 {
00038    struct ast_autochan *autochan;
00039 
00040    if (!chan) {
00041       return NULL;
00042    }
00043 
00044    if (!(autochan = ast_calloc(1, sizeof(*autochan)))) {
00045       return NULL;
00046    }
00047 
00048    autochan->chan = ast_channel_ref(chan);
00049 
00050    ast_channel_lock(autochan->chan);
00051    AST_LIST_INSERT_TAIL(&autochan->chan->autochans, autochan, list);
00052    ast_channel_unlock(autochan->chan);
00053 
00054    ast_debug(1, "Created autochan %p to hold channel %s (%p)\n", autochan, chan->name, chan);
00055 
00056    return autochan;
00057 }
00058 
00059 void ast_autochan_destroy(struct ast_autochan *autochan)
00060 {
00061    struct ast_autochan *autochan_iter;
00062 
00063    ast_channel_lock(autochan->chan);
00064    AST_LIST_TRAVERSE_SAFE_BEGIN(&autochan->chan->autochans, autochan_iter, list) {
00065       if (autochan_iter == autochan) {
00066          AST_LIST_REMOVE_CURRENT(list);
00067          ast_debug(1, "Removed autochan %p from the list, about to free it\n", autochan);
00068          break;
00069       }
00070    }
00071    AST_LIST_TRAVERSE_SAFE_END;
00072    ast_channel_unlock(autochan->chan);
00073 
00074    autochan->chan = ast_channel_unref(autochan->chan);
00075 
00076    ast_free(autochan);
00077 }
00078 
00079 void ast_autochan_new_channel(struct ast_channel *old_chan, struct ast_channel *new_chan)
00080 {
00081    struct ast_autochan *autochan;
00082 
00083    AST_LIST_APPEND_LIST(&new_chan->autochans, &old_chan->autochans, list);
00084 
00085    AST_LIST_TRAVERSE(&new_chan->autochans, autochan, list) {
00086       if (autochan->chan == old_chan) {
00087          autochan->chan = ast_channel_unref(old_chan);
00088          autochan->chan = ast_channel_ref(new_chan);
00089 
00090          ast_debug(1, "Autochan %p used to hold channel %s (%p) but now holds channel %s (%p)\n",
00091                autochan, old_chan->name, old_chan, new_chan->name, new_chan);
00092       }
00093    }
00094 }

Generated on Mon Jun 27 16:50:49 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7