Building module in asterisk Part 2


For me previous tutorial “Building module in asterisk P.1” add a new funciton cdr_foobar and register it while loading a module and unregister it while unloading the module.

/*
 * Asterisk -- An open source telephony toolkit.
 *
 * Copyright (C) 1999 - 2012, Digium, Inc.
 *
 * Mark Spencer <markster@digium.com>
 *
 * See http://www.asterisk.org for more information about
 * the Asterisk project. Please do not directly contact
 * any of the maintainers of this project for assistance;
 * the project provides a web site, mailing lists and IRC
 * channels for your use.
 *
 * This program is free software, distributed under the terms of
 * the GNU General Public License Version 2. See the LICENSE file
 * at the top of the source tree.
 */

/*
*
*
* Sample module example for tutorial purpose  
* shishir.pokharel@gmail.com
*
*
*
*
*
*/


#include "asterisk.h"


ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328259 $")

//#include "asterisk/channel.h"
#include "asterisk/module.h"
#include "asterisk/cdr.h"

static int cdr_foobar(struct ast_cdr *cdr)
{
    ast_log(LOG_NOTICE, "Foobar got a CDR for channel '%s'.  "
        "Source: '%s', Dest: '%s', Duration: %ldn",
        cdr->channel, cdr->src, cdr->dst, cdr->duration);

    return 0;
}

static int unload_module(void)
{
	ast_cdr_unregister("foobar");
	ast_log(LOG_NOTICE, "Hello foobar ! I am unloaded ! - Thanks Shishir");
	return 0;
}

static int load_module(void)
{
	ast_cdr_register("foobar", "foobar CDR Handler", cdr_foobar);
	ast_log(LOG_NOTICE, "Hello foobar ! I am loaded ! - Thanks Shishir");
	return AST_MODULE_LOAD_SUCCESS;
}


AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Test - module to check load and unload");

, , , ,

Comments are closed.