Wed Jan 27 20:02:02 2016

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  * Please follow coding guidelines 
00019  * http://svn.digium.com/view/asterisk/trunk/doc/CODING-GUIDELINES
00020  */
00021 
00022 /*! \file
00023  *
00024  * \brief Skeleton application
00025  *
00026  * \author\verbatim <Your Name Here> <<Your Email Here>> \endverbatim
00027  * 
00028  * This is a skeleton for development of an Asterisk application 
00029  * \ingroup applications
00030  */
00031 
00032 /*** MODULEINFO
00033    <defaultenabled>no</defaultenabled>
00034    <support_level>core</support_level>
00035  ***/
00036 
00037 #include "asterisk.h"
00038 
00039 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
00040 
00041 #include "asterisk/file.h"
00042 #include "asterisk/channel.h"
00043 #include "asterisk/pbx.h"
00044 #include "asterisk/module.h"
00045 #include "asterisk/lock.h"
00046 #include "asterisk/app.h"
00047 
00048 /*** DOCUMENTATION
00049    <application name="Skel" language="en_US">
00050       <synopsis>
00051          Simple one line explaination.
00052       </synopsis>
00053       <syntax>
00054          <parameter name="dummy" required="true"/>
00055          <parameter name="options">
00056             <optionlist>
00057                <option name="a">
00058                   <para>Option A.</para>
00059                </option>
00060                <option name="b">
00061                   <para>Option B.</para>
00062                </option>
00063                <option name="c">
00064                   <para>Option C.</para>
00065                </option>
00066             </optionlist>
00067          </parameter>
00068       </syntax>
00069       <description>
00070       <para>This application is a template to build other applications from. 
00071       It shows you the basic structure to create your own Asterisk applications.</para>
00072       </description>
00073    </application>
00074  ***/
00075 
00076 static char *app = "Skel";
00077 
00078 enum option_flags {
00079    OPTION_A = (1 << 0),
00080    OPTION_B = (1 << 1),
00081    OPTION_C = (1 << 2),
00082 };
00083 
00084 enum option_args {
00085    OPTION_ARG_B = 0,
00086    OPTION_ARG_C = 1,
00087    /* This *must* be the last value in this enum! */
00088    OPTION_ARG_ARRAY_SIZE = 2,
00089 };
00090 
00091 AST_APP_OPTIONS(app_opts,{
00092    AST_APP_OPTION('a', OPTION_A),
00093    AST_APP_OPTION_ARG('b', OPTION_B, OPTION_ARG_B),
00094    AST_APP_OPTION_ARG('c', OPTION_C, OPTION_ARG_C),
00095 });
00096 
00097 
00098 static int app_exec(struct ast_channel *chan, const char *data)
00099 {
00100    int res = 0;
00101    struct ast_flags flags;
00102    char *parse, *opts[OPTION_ARG_ARRAY_SIZE];
00103    AST_DECLARE_APP_ARGS(args,
00104       AST_APP_ARG(dummy);
00105       AST_APP_ARG(options);
00106    );
00107 
00108    if (ast_strlen_zero(data)) {
00109       ast_log(LOG_WARNING, "%s requires an argument (dummy[,options])\n", app);
00110       return -1;
00111    }
00112 
00113    /* Do our thing here */
00114 
00115    /* We need to make a copy of the input string if we are going to modify it! */
00116    parse = ast_strdupa(data);
00117 
00118    AST_STANDARD_APP_ARGS(args, parse);
00119 
00120    if (args.argc == 2) {
00121       ast_app_parse_options(app_opts, &flags, opts, args.options);
00122    }
00123 
00124    if (!ast_strlen_zero(args.dummy)) {
00125       ast_log(LOG_NOTICE, "Dummy value is : %s\n", args.dummy);
00126    }
00127 
00128    if (ast_test_flag(&flags, OPTION_A)) {
00129       ast_log(LOG_NOTICE, "Option A is set\n");
00130    }
00131 
00132    if (ast_test_flag(&flags, OPTION_B)) {
00133       ast_log(LOG_NOTICE, "Option B is set with : %s\n", opts[OPTION_ARG_B] ? opts[OPTION_ARG_B] : "<unspecified>");
00134    }
00135 
00136    if (ast_test_flag(&flags, OPTION_C)) {
00137       ast_log(LOG_NOTICE, "Option C is set with : %s\n", opts[OPTION_ARG_C] ? opts[OPTION_ARG_C] : "<unspecified>");
00138    }
00139 
00140    return res;
00141 }
00142 
00143 static int unload_module(void)
00144 {
00145    return ast_unregister_application(app);
00146 }
00147 
00148 static int load_module(void)
00149 {
00150    return ast_register_application_xml(app, app_exec) ? 
00151       AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
00152 }
00153 
00154 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Skeleton (sample) Application");

Generated on 27 Jan 2016 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1