Building module in asterisk part 3


/*
 * 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/cli.h"

static char *handle_cli_cprint(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
	switch(cmd){

		case CLI_INIT:
			e->command = "cprint";
			e->usage =
				"Usage : cprint <stuff>\n"
				"	Print back the argument.\n"
				"Examples:\n"
				"	cprint foo\n"
				"	cprint \"foo bar\"\n"
				"";
			return NULL;

		case CLI_GENERATE:

			return NULL;


	}

	if(a->argc == e->args)
	{

		ast_cli(a->fd,"You didn't provide an argument to sprintn command!\n");
		return CLI_SHOWUSAGE;
	}

	ast_cli(a->fd,"%s\n",a->argv[1]);

	return CLI_SUCCESS;

}

static struct ast_cli_entry cli_testcprint[] = {
AST_CLI_DEFINE(handle_cli_cprint, "print to the CLI"),
};



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

static int load_module(void)
{
	ast_cli_register_multiple(cli_testcprint, ARRAY_LEN(cli_testcprint));
	ast_log(LOG_NOTICE, "Hello foobar ! I am loaded ! - Thanks Shishir\n");
	return AST_MODULE_LOAD_SUCCESS;
}


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

, , , , ,

Comments are closed.