app_stasis.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2012 - 2013, Digium, Inc.
00005  *
00006  * David M. Lee, II <dlee@digium.com>
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 Stasis dialplan application.
00022  *
00023  * \author David M. Lee, II <dlee@digium.com>
00024  */
00025 
00026 /*** MODULEINFO
00027    <depend>res_stasis</depend>
00028    <support_level>core</support_level>
00029  ***/
00030 
00031 #include "asterisk.h"
00032 
00033 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 433891 $")
00034 
00035 #include "asterisk/app.h"
00036 #include "asterisk/module.h"
00037 #include "asterisk/pbx.h"
00038 #include "asterisk/stasis.h"
00039 #include "asterisk/stasis_app_impl.h"
00040 
00041 /*** DOCUMENTATION
00042    <application name="Stasis" language="en_US">
00043       <synopsis>Invoke an external Stasis application.</synopsis>
00044       <syntax>
00045          <parameter name="app_name" required="true">
00046             <para>Name of the application to invoke.</para>
00047          </parameter>
00048          <parameter name="args">
00049             <para>Optional comma-delimited arguments for the
00050             application invocation.</para>
00051          </parameter>
00052       </syntax>
00053       <description>
00054          <para>Invoke a Stasis application.</para>
00055          <para>This application will set the following channel variable upon
00056          completion:</para>
00057          <variablelist>
00058             <variable name="STASISSTATUS">
00059                <para>This indicates the status of the execution of the
00060                Stasis application.</para>
00061                <value name="SUCCESS">
00062                   The channel has exited Stasis without any failures in
00063                   Stasis.
00064                </value>
00065                <value name="FAILED">
00066                   A failure occurred when executing the Stasis
00067                   The app registry is not instantiated; The app
00068                   application. Some (not all) possible reasons for this:
00069                   requested is not registered; The app requested is not
00070                   active; Stasis couldn't send a start message.
00071                </value>
00072             </variable>
00073          </variablelist>
00074       </description>
00075    </application>
00076  ***/
00077 
00078 /*! \brief Maximum number of arguments for the Stasis dialplan application */
00079 #define MAX_ARGS 128
00080 
00081 /*! \brief Dialplan application name */
00082 static const char *stasis = "Stasis";
00083 
00084 /*! /brief Stasis dialplan application callback */
00085 static int app_exec(struct ast_channel *chan, const char *data)
00086 {
00087    char *parse = NULL;
00088    int ret = -1;
00089 
00090    AST_DECLARE_APP_ARGS(args,
00091       AST_APP_ARG(app_name);
00092       AST_APP_ARG(app_argv)[MAX_ARGS];
00093    );
00094 
00095    ast_assert(chan != NULL);
00096    ast_assert(data != NULL);
00097 
00098    pbx_builtin_setvar_helper(chan, "STASISSTATUS", "");
00099 
00100    /* parse the arguments */
00101    parse = ast_strdupa(data);
00102    AST_STANDARD_APP_ARGS(args, parse);
00103 
00104    if (args.argc < 1) {
00105       ast_log(LOG_WARNING, "Stasis app_name argument missing\n");
00106    } else {
00107       ret = stasis_app_exec(chan,
00108                             args.app_name,
00109                             args.argc - 1,
00110                             args.app_argv);
00111    }
00112 
00113    if (ret == -1) {
00114        pbx_builtin_setvar_helper(chan, "STASISSTATUS", "FAILED");
00115    } else {
00116        pbx_builtin_setvar_helper(chan, "STASISSTATUS", "SUCCESS");
00117    }
00118 
00119    return ret;
00120 }
00121 
00122 static int load_module(void)
00123 {
00124    int r = 0;
00125 
00126    stasis_app_ref();
00127    r |= ast_register_application_xml(stasis, app_exec);
00128    return r;
00129 }
00130 
00131 static int unload_module(void)
00132 {
00133    int r = 0;
00134    r |= ast_unregister_application(stasis);
00135    stasis_app_unref();
00136    return r;
00137 }
00138 
00139 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Stasis dialplan application",
00140    .support_level = AST_MODULE_SUPPORT_CORE,
00141    .load = load_module,
00142    .unload = unload_module,
00143    .nonoptreq = "res_stasis",
00144    );

Generated on Thu Apr 16 06:27:12 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6