744c6755df5f05d86617e0719060f621b6a91b5c
[asterisk/asterisk.git] / apps / app_ivrdemo.c
1 /*
2  * Asterisk -- A telephony toolkit for Linux.
3  *
4  * Skeleton application
5  * 
6  * Copyright (C) 1999, Mark Spencer
7  *
8  * Mark Spencer <markster@linux-support.net>
9  *
10  * This program is free software, distributed under the terms of
11  * the GNU General Public License
12  */
13
14 #include <asterisk/file.h>
15 #include <asterisk/logger.h>
16 #include <asterisk/channel.h>
17 #include <asterisk/pbx.h>
18 #include <asterisk/module.h>
19 #include <asterisk/lock.h>
20 #include <asterisk/app.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <string.h>
24
25 static char *tdesc = "IVR Demo Application";
26 static char *app = "IVRDemo";
27 static char *synopsis = 
28 "  This is a skeleton application that shows you the basic structure to create your\n"
29 "own asterisk applications and demonstrates the IVR demo.\n";
30
31 static int ivr_demo_func(struct ast_channel *chan, void *data)
32 {
33         ast_verbose("IVR Demo, data is %s!\n", (char *)data);
34         return 0;
35 }
36
37 static struct ast_ivr_menu ivr_submenu = {
38         "IVR Demo Sub Menu", 0, {
39         { "s", AST_ACTION_BACKGROUND, "demo-abouttotry" },
40         { "1", AST_ACTION_PLAYBACK, "digits/1" },
41         { "1", AST_ACTION_PLAYBACK, "digits/1" },
42         { "1", AST_ACTION_RESTART },
43         { "2", AST_ACTION_PLAYLIST, "digits/2;digits/3" },
44         { "*", AST_ACTION_REPEAT },
45         { "#", AST_ACTION_UPONE  },
46         { NULL },
47 }};
48
49 static struct ast_ivr_menu ivr_demo = {
50         "IVR Demo Main Menu", 0, {
51         { "s", AST_ACTION_BACKGROUND, "demo-congrats" },
52         { "g", AST_ACTION_BACKGROUND, "demo-instruct" },
53         { "g", AST_ACTION_WAITOPTION },
54         { "1", AST_ACTION_PLAYBACK, "digits/1" },
55         { "1", AST_ACTION_RESTART },
56         { "2", AST_ACTION_MENU, &ivr_submenu },
57         { "2", AST_ACTION_RESTART },
58         { "i", AST_ACTION_PLAYBACK, "invalid" },
59         { "i", AST_ACTION_REPEAT, (void *)2 },
60         { "#", AST_ACTION_EXIT },
61         { NULL },
62 }};
63
64 STANDARD_LOCAL_USER;
65
66 LOCAL_USER_DECL;
67
68 static int skel_exec(struct ast_channel *chan, void *data)
69 {
70         int res=0;
71         struct localuser *u;
72         if (!data) {
73                 ast_log(LOG_WARNING, "skel requires an argument (filename)\n");
74                 return -1;
75         }
76         LOCAL_USER_ADD(u);
77         /* Do our thing here */
78         if (chan->_state != AST_STATE_UP)
79                 res = ast_answer(chan);
80         if (!res)
81                 res = ast_ivr_menu_run(chan, &ivr_demo, data);
82         LOCAL_USER_REMOVE(u);
83         return res;
84 }
85
86 int unload_module(void)
87 {
88         STANDARD_HANGUP_LOCALUSERS;
89         return ast_unregister_application(app);
90 }
91
92 int load_module(void)
93 {
94         return ast_register_application(app, skel_exec, synopsis, tdesc);
95 }
96
97 char *description(void)
98 {
99         return tdesc;
100 }
101
102 int usecount(void)
103 {
104         int res;
105         STANDARD_USECOUNT(res);
106         return res;
107 }
108
109 char *key()
110 {
111         return ASTERISK_GPL_KEY;
112 }