Massive cleanups to applications for LOCAL_USER handling and some other things.
[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 /*
20  *
21  * IVR Demo application
22  * 
23  */
24
25 #include <stdlib.h>
26 #include <unistd.h>
27 #include <string.h>
28
29 #include "asterisk.h"
30
31 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
32
33 #include "asterisk/file.h"
34 #include "asterisk/logger.h"
35 #include "asterisk/channel.h"
36 #include "asterisk/pbx.h"
37 #include "asterisk/module.h"
38 #include "asterisk/lock.h"
39 #include "asterisk/app.h"
40
41 static char *tdesc = "IVR Demo Application";
42 static char *app = "IVRDemo";
43 static char *synopsis = 
44 "  This is a skeleton application that shows you the basic structure to create your\n"
45 "own asterisk applications and demonstrates the IVR demo.\n";
46
47 static int ivr_demo_func(struct ast_channel *chan, void *data)
48 {
49         ast_verbose("IVR Demo, data is %s!\n", (char *)data);
50         return 0;
51 }
52
53 AST_IVR_DECLARE_MENU(ivr_submenu, "IVR Demo Sub Menu", 0, 
54 {
55         { "s", AST_ACTION_BACKGROUND, "demo-abouttotry" },
56         { "s", AST_ACTION_WAITOPTION },
57         { "1", AST_ACTION_PLAYBACK, "digits/1" },
58         { "1", AST_ACTION_PLAYBACK, "digits/1" },
59         { "1", AST_ACTION_RESTART },
60         { "2", AST_ACTION_PLAYLIST, "digits/2;digits/3" },
61         { "3", AST_ACTION_CALLBACK, ivr_demo_func },
62         { "4", AST_ACTION_TRANSFER, "demo|s|1" },
63         { "*", AST_ACTION_REPEAT },
64         { "#", AST_ACTION_UPONE  },
65         { NULL }
66 });
67
68 AST_IVR_DECLARE_MENU(ivr_demo, "IVR Demo Main Menu", 0, 
69 {
70         { "s", AST_ACTION_BACKGROUND, "demo-congrats" },
71         { "g", AST_ACTION_BACKGROUND, "demo-instruct" },
72         { "g", AST_ACTION_WAITOPTION },
73         { "1", AST_ACTION_PLAYBACK, "digits/1" },
74         { "1", AST_ACTION_RESTART },
75         { "2", AST_ACTION_MENU, &ivr_submenu },
76         { "2", AST_ACTION_RESTART },
77         { "i", AST_ACTION_PLAYBACK, "invalid" },
78         { "i", AST_ACTION_REPEAT, (void *)(unsigned long)2 },
79         { "#", AST_ACTION_EXIT },
80         { NULL },
81 });
82
83 STANDARD_LOCAL_USER;
84
85 LOCAL_USER_DECL;
86
87 static int skel_exec(struct ast_channel *chan, void *data)
88 {
89         int res=0;
90         struct localuser *u;
91         
92         if (!data || ast_strlen_zero(data)) {
93                 ast_log(LOG_WARNING, "skel requires an argument (filename)\n");
94                 return -1;
95         }
96         
97         LOCAL_USER_ADD(u);
98
99         /* Do our thing here */
100
101         if (chan->_state != AST_STATE_UP)
102                 res = ast_answer(chan);
103         if (!res)
104                 res = ast_ivr_menu_run(chan, &ivr_demo, data);
105         
106         LOCAL_USER_REMOVE(u);
107
108         return res;
109 }
110
111 int unload_module(void)
112 {
113         int res;
114         
115         res = ast_unregister_application(app);
116
117         STANDARD_HANGUP_LOCALUSERS;
118         
119         return res;
120 }
121
122 int load_module(void)
123 {
124         return ast_register_application(app, skel_exec, tdesc, synopsis);
125 }
126
127 char *description(void)
128 {
129         return tdesc;
130 }
131
132 int usecount(void)
133 {
134         int res;
135         STANDARD_USECOUNT(res);
136         return res;
137 }
138
139 char *key()
140 {
141         return ASTERISK_GPL_KEY;
142 }