/*
 * Asterisk -- An open source telephony toolkit.
 *
 * Copyright (C) 2008, Digium, Inc.
 *
 * Russell Bryant <russell@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.
 */

/*! \file
 * 
 * \brief Hello World! 
 *
 * \author Russell Bryant <russell@digium.com>
 */ 

#include "asterisk.h"

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

#include "asterisk/module.h"
#include "asterisk/logger.h"
#include "asterisk/cdr.h"
#include "asterisk/cli.h"

static char *handle_cli_echo(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
	switch (cmd) {
	case CLI_INIT:
		e->command = "echo";
		e->usage =
			"Usage: echo <stuff>\n"
			"       Print back the first argument.\n"
			"Examples:\n"
			"       echo foo\n"
			"       echo \"multiple words\"\n"
			"";
		return NULL;
	case CLI_GENERATE:
		return NULL;
	}

	if (a->argc == e->args) {
		ast_cli(a->fd, "You did not provide an argument to echo\n\n");
		return CLI_SHOWUSAGE;
	}

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

	return CLI_SUCCESS;
}

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

	return 0;
}

static struct ast_cli_entry cli_helloworld[] = {
	AST_CLI_DEFINE(handle_cli_echo, "Echo to the CLI"),
};

static int unload_module(void)
{
	ast_log(LOG_NOTICE, "Goodbye World!\n");

	ast_cdr_unregister("HelloWorld");

	ast_cli_unregister_multiple(cli_helloworld, ARRAY_LEN(cli_helloworld));

	return 0;
}

static int load_module(void)
{
	ast_log(LOG_NOTICE, "Hello World!\n");

	ast_cdr_register("HelloWorld", "Hello World CDR Handler", cdr_helloworld);

	ast_cli_register_multiple(cli_helloworld, ARRAY_LEN(cli_helloworld));

	return AST_MODULE_LOAD_SUCCESS;
}

AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Hello World");
