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