Applications no longer need to call ast_module_user_add and ast_module_user_remove...
[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 <stdio.h>
37 #include <stdlib.h>
38 #include <unistd.h>
39 #include <string.h>
40
41 #include "asterisk/file.h"
42 #include "asterisk/logger.h"
43 #include "asterisk/channel.h"
44 #include "asterisk/pbx.h"
45 #include "asterisk/module.h"
46 #include "asterisk/lock.h"
47 #include "asterisk/app.h"
48
49 static char *tdesc = "IVR Demo Application";
50 static char *app = "IVRDemo";
51 static char *synopsis = 
52 "  This is a skeleton application that shows you the basic structure to create your\n"
53 "own asterisk applications and demonstrates the IVR demo.\n";
54
55 static int ivr_demo_func(struct ast_channel *chan, void *data)
56 {
57         ast_verbose("IVR Demo, data is %s!\n", (char *)data);
58         return 0;
59 }
60
61 AST_IVR_DECLARE_MENU(ivr_submenu, "IVR Demo Sub Menu", 0, 
62 {
63         { "s", AST_ACTION_BACKGROUND, "demo-abouttotry" },
64         { "s", AST_ACTION_WAITOPTION },
65         { "1", AST_ACTION_PLAYBACK, "digits/1" },
66         { "1", AST_ACTION_PLAYBACK, "digits/1" },
67         { "1", AST_ACTION_RESTART },
68         { "2", AST_ACTION_PLAYLIST, "digits/2;digits/3" },
69         { "3", AST_ACTION_CALLBACK, ivr_demo_func },
70         { "4", AST_ACTION_TRANSFER, "demo|s|1" },
71         { "*", AST_ACTION_REPEAT },
72         { "#", AST_ACTION_UPONE  },
73         { NULL }
74 });
75
76 AST_IVR_DECLARE_MENU(ivr_demo, "IVR Demo Main Menu", 0, 
77 {
78         { "s", AST_ACTION_BACKGROUND, "demo-congrats" },
79         { "g", AST_ACTION_BACKGROUND, "demo-instruct" },
80         { "g", AST_ACTION_WAITOPTION },
81         { "1", AST_ACTION_PLAYBACK, "digits/1" },
82         { "1", AST_ACTION_RESTART },
83         { "2", AST_ACTION_MENU, &ivr_submenu },
84         { "2", AST_ACTION_RESTART },
85         { "i", AST_ACTION_PLAYBACK, "invalid" },
86         { "i", AST_ACTION_REPEAT, (void *)(unsigned long)2 },
87         { "#", AST_ACTION_EXIT },
88         { NULL },
89 });
90
91
92 static int skel_exec(struct ast_channel *chan, void *data)
93 {
94         int res=0;
95         
96         if (ast_strlen_zero(data)) {
97                 ast_log(LOG_WARNING, "skel requires an argument (filename)\n");
98                 return -1;
99         }
100         
101         /* Do our thing here */
102
103         if (chan->_state != AST_STATE_UP)
104                 res = ast_answer(chan);
105         if (!res)
106                 res = ast_ivr_menu_run(chan, &ivr_demo, data);
107         
108         return res;
109 }
110
111 static int unload_module(void)
112 {
113         return ast_unregister_application(app);
114 }
115
116 static int load_module(void)
117 {
118         return ast_register_application(app, skel_exec, tdesc, synopsis);
119 }
120
121 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "IVR Demo Application");