Merged revisions 280161 via svnmerge from
[asterisk/asterisk.git] / apps / app_ivrdemo.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Mark Spencer <markster@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18
19 /*! \file
20  *
21  * \brief IVR Demo application
22  *
23  * \author Mark Spencer <markster@digium.com>
24  * 
25  * \ingroup applications
26  */
27
28 /*** MODULEINFO
29         <defaultenabled>no</defaultenabled>
30  ***/
31
32 #include "asterisk.h"
33
34 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
35
36 #include "asterisk/file.h"
37 #include "asterisk/channel.h"
38 #include "asterisk/pbx.h"
39 #include "asterisk/module.h"
40 #include "asterisk/lock.h"
41 #include "asterisk/app.h"
42
43 /*** DOCUMENTATION
44         <application name="IVRDemo" language="en_US">
45                 <synopsis>
46                         IVR Demo Application.
47                 </synopsis>
48                 <syntax>
49                         <parameter name="filename" required="true" />
50                 </syntax>
51                 <description>
52                         <para>This is a skeleton application that shows you the basic structure to create your
53                         own asterisk applications and demonstrates the IVR demo.</para>
54                 </description>
55         </application>
56  ***/
57
58 static char *app = "IVRDemo";
59
60 static int ivr_demo_func(struct ast_channel *chan, void *data)
61 {
62         ast_verbose("IVR Demo, data is %s!\n", (char *) data);
63         return 0;
64 }
65
66 AST_IVR_DECLARE_MENU(ivr_submenu, "IVR Demo Sub Menu", 0, 
67 {
68         { "s", AST_ACTION_BACKGROUND, "demo-abouttotry" },
69         { "s", AST_ACTION_WAITOPTION },
70         { "1", AST_ACTION_PLAYBACK, "digits/1" },
71         { "1", AST_ACTION_PLAYBACK, "digits/1" },
72         { "1", AST_ACTION_RESTART },
73         { "2", AST_ACTION_PLAYLIST, "digits/2;digits/3" },
74         { "3", AST_ACTION_CALLBACK, ivr_demo_func },
75         { "4", AST_ACTION_TRANSFER, "demo|s|1" },
76         { "*", AST_ACTION_REPEAT },
77         { "#", AST_ACTION_UPONE  },
78         { NULL }
79 });
80
81 AST_IVR_DECLARE_MENU(ivr_demo, "IVR Demo Main Menu", 0, 
82 {
83         { "s", AST_ACTION_BACKGROUND, "demo-congrats" },
84         { "g", AST_ACTION_BACKGROUND, "demo-instruct" },
85         { "g", AST_ACTION_WAITOPTION },
86         { "1", AST_ACTION_PLAYBACK, "digits/1" },
87         { "1", AST_ACTION_RESTART },
88         { "2", AST_ACTION_MENU, &ivr_submenu },
89         { "2", AST_ACTION_RESTART },
90         { "i", AST_ACTION_PLAYBACK, "invalid" },
91         { "i", AST_ACTION_REPEAT, (void *)(unsigned long)2 },
92         { "#", AST_ACTION_EXIT },
93         { NULL },
94 });
95
96 static int skel_exec(struct ast_channel *chan, const char *data)
97 {
98         int res=0;
99         char *tmp;
100         
101         if (ast_strlen_zero(data)) {
102                 ast_log(LOG_WARNING, "skel requires an argument (filename)\n");
103                 return -1;
104         }
105         
106         tmp = ast_strdupa(data);
107
108         /* Do our thing here */
109
110         if (chan->_state != AST_STATE_UP)
111                 res = ast_answer(chan);
112         if (!res)
113                 res = ast_ivr_menu_run(chan, &ivr_demo, tmp);
114         
115         return res;
116 }
117
118 static int unload_module(void)
119 {
120         return ast_unregister_application(app);
121 }
122
123 static int load_module(void)
124 {
125         return ast_register_application_xml(app, skel_exec);
126 }
127
128 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "IVR Demo Application");