Sat Aug 6 00:39:21 2011

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 <Your Name Here> <<Your Email Here>>
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: 135847 $")
00036 
00037 #include <stdio.h>
00038 #include <stdlib.h>
00039 #include <unistd.h>
00040 #include <string.h>
00041 
00042 #include "asterisk/file.h"
00043 #include "asterisk/logger.h"
00044 #include "asterisk/channel.h"
00045 #include "asterisk/pbx.h"
00046 #include "asterisk/module.h"
00047 #include "asterisk/lock.h"
00048 #include "asterisk/app.h"
00049 
00050 static char *app = "Skel";
00051 static char *synopsis = 
00052 "Skeleton application.";
00053 static char *descrip = "This application is a template to build other applications from.\n"
00054  " It shows you the basic structure to create your own Asterisk applications.\n";
00055 
00056 enum {
00057    OPTION_A = (1 << 0),
00058    OPTION_B = (1 << 1),
00059    OPTION_C = (1 << 2),
00060 } option_flags;
00061 
00062 enum {
00063    OPTION_ARG_B = 0,
00064    OPTION_ARG_C = 1,
00065    /* This *must* be the last value in this enum! */
00066    OPTION_ARG_ARRAY_SIZE = 2,
00067 } option_args;
00068 
00069 AST_APP_OPTIONS(app_opts,{
00070    AST_APP_OPTION('a', OPTION_A),
00071    AST_APP_OPTION_ARG('b', OPTION_B, OPTION_ARG_B),
00072    AST_APP_OPTION_ARG('c', OPTION_C, OPTION_ARG_C),
00073 });
00074 
00075 
00076 static int app_exec(struct ast_channel *chan, void *data)
00077 {
00078    int res = 0;
00079    struct ast_flags flags;
00080    struct ast_module_user *u;
00081    char *parse, *opts[OPTION_ARG_ARRAY_SIZE];
00082    AST_DECLARE_APP_ARGS(args,
00083       AST_APP_ARG(dummy);
00084       AST_APP_ARG(options);
00085    );
00086 
00087    if (ast_strlen_zero(data)) {
00088       ast_log(LOG_WARNING, "%s requires an argument (dummy|[options])\n", app);
00089       return -1;
00090    }
00091 
00092    u = ast_module_user_add(chan);
00093 
00094    /* Do our thing here */
00095 
00096    /* We need to make a copy of the input string if we are going to modify it! */
00097    parse = ast_strdupa(data);
00098 
00099    AST_STANDARD_APP_ARGS(args, parse);
00100 
00101    if (args.argc == 2)
00102       ast_app_parse_options(app_opts, &flags, opts, args.options);
00103 
00104    if (!ast_strlen_zero(args.dummy)) 
00105       ast_log(LOG_NOTICE, "Dummy value is : %s\n", args.dummy);
00106 
00107    if (ast_test_flag(&flags, OPTION_A))
00108       ast_log(LOG_NOTICE, "Option A is set\n");
00109 
00110    if (ast_test_flag(&flags, OPTION_B))
00111       ast_log(LOG_NOTICE, "Option B is set with : %s\n", opts[OPTION_ARG_B] ? opts[OPTION_ARG_B] : "<unspecified>");
00112 
00113    if (ast_test_flag(&flags, OPTION_C))
00114       ast_log(LOG_NOTICE, "Option C is set with : %s\n", opts[OPTION_ARG_C] ? opts[OPTION_ARG_C] : "<unspecified>");
00115 
00116    ast_module_user_remove(u);
00117 
00118    return res;
00119 }
00120 
00121 static int unload_module(void)
00122 {
00123    int res;
00124    res = ast_unregister_application(app);
00125    return res; 
00126 }
00127 
00128 static int load_module(void)
00129 {
00130    return ast_register_application(app, app_exec, synopsis, descrip);
00131 }
00132 
00133 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Skeleton (sample) Application");

Generated on Sat Aug 6 00:39:21 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7