Thu Jul 9 13:40:20 2009

Asterisk developer's documentation


app_skel.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) <Year>, <Your Name Here>
00005  *
00006  * <Your Name Here> <<Your Email Here>>
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 /*! \file
00020  *
00021  * \brief Skeleton application
00022  *
00023  * \author\verbatim <Your Name Here> <<Your Email Here>> \endverbatim
00024  * 
00025  * This is a skeleton for development of an Asterisk application 
00026  * \ingroup applications
00027  */
00028 
00029 /*** MODULEINFO
00030    <defaultenabled>no</defaultenabled>
00031  ***/
00032 
00033 #include "asterisk.h"
00034 
00035 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 89424 $")
00036 
00037 #include "asterisk/file.h"
00038 #include "asterisk/channel.h"
00039 #include "asterisk/pbx.h"
00040 #include "asterisk/module.h"
00041 #include "asterisk/lock.h"
00042 #include "asterisk/app.h"
00043 
00044 static char *app = "Skel";
00045 static char *synopsis = 
00046 "Skeleton application.";
00047 static char *descrip = "This application is a template to build other applications from.\n"
00048  " It shows you the basic structure to create your own Asterisk applications.\n";
00049 
00050 enum {
00051    OPTION_A = (1 << 0),
00052    OPTION_B = (1 << 1),
00053    OPTION_C = (1 << 2),
00054 } option_flags;
00055 
00056 enum {
00057    OPTION_ARG_B = 0,
00058    OPTION_ARG_C = 1,
00059    /* This *must* be the last value in this enum! */
00060    OPTION_ARG_ARRAY_SIZE = 2,
00061 } option_args;
00062 
00063 AST_APP_OPTIONS(app_opts,{
00064    AST_APP_OPTION('a', OPTION_A),
00065    AST_APP_OPTION_ARG('b', OPTION_B, OPTION_ARG_B),
00066    AST_APP_OPTION_ARG('c', OPTION_C, OPTION_ARG_C),
00067 });
00068 
00069 
00070 static int app_exec(struct ast_channel *chan, void *data)
00071 {
00072    int res = 0;
00073    struct ast_flags flags;
00074    char *parse, *opts[OPTION_ARG_ARRAY_SIZE];
00075    AST_DECLARE_APP_ARGS(args,
00076       AST_APP_ARG(dummy);
00077       AST_APP_ARG(options);
00078    );
00079 
00080    if (ast_strlen_zero(data)) {
00081       ast_log(LOG_WARNING, "%s requires an argument (dummy[,options])\n", app);
00082       return -1;
00083    }
00084 
00085    /* Do our thing here */
00086 
00087    /* We need to make a copy of the input string if we are going to modify it! */
00088    parse = ast_strdupa(data);
00089 
00090    AST_STANDARD_APP_ARGS(args, parse);
00091 
00092    if (args.argc == 2)
00093       ast_app_parse_options(app_opts, &flags, opts, args.options);
00094 
00095    if (!ast_strlen_zero(args.dummy)) 
00096       ast_log(LOG_NOTICE, "Dummy value is : %s\n", args.dummy);
00097 
00098    if (ast_test_flag(&flags, OPTION_A))
00099       ast_log(LOG_NOTICE, "Option A is set\n");
00100 
00101    if (ast_test_flag(&flags, OPTION_B))
00102       ast_log(LOG_NOTICE, "Option B is set with : %s\n", opts[OPTION_ARG_B] ? opts[OPTION_ARG_B] : "<unspecified>");
00103 
00104    if (ast_test_flag(&flags, OPTION_C))
00105       ast_log(LOG_NOTICE, "Option C is set with : %s\n", opts[OPTION_ARG_C] ? opts[OPTION_ARG_C] : "<unspecified>");
00106 
00107    return res;
00108 }
00109 
00110 static int unload_module(void)
00111 {
00112    int res;
00113    res = ast_unregister_application(app);
00114    return res; 
00115 }
00116 
00117 static int load_module(void)
00118 {
00119    if (ast_register_application(app, app_exec, synopsis, descrip))
00120       return AST_MODULE_LOAD_DECLINE;
00121 
00122    return AST_MODULE_LOAD_SUCCESS;
00123 }
00124 
00125 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Skeleton (sample) Application");

Generated on Thu Jul 9 13:40:20 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7