Asterisk - The Open Source Telephony Project  18.5.0
app_ivrdemo.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Mark Spencer <[email protected]>
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 <[email protected]>
24  *
25  * \ingroup applications
26  */
27 
28 /*** MODULEINFO
29  <defaultenabled>no</defaultenabled>
30  <support_level>extended</support_level>
31  ***/
32 
33 #include "asterisk.h"
34 
35 #include "asterisk/file.h"
36 #include "asterisk/channel.h"
37 #include "asterisk/pbx.h"
38 #include "asterisk/module.h"
39 #include "asterisk/lock.h"
40 #include "asterisk/app.h"
41 
42 /*** DOCUMENTATION
43  <application name="IVRDemo" language="en_US">
44  <synopsis>
45  IVR Demo Application.
46  </synopsis>
47  <syntax>
48  <parameter name="filename" required="true" />
49  </syntax>
50  <description>
51  <para>This is a skeleton application that shows you the basic structure to create your
52  own asterisk applications and demonstrates the IVR demo.</para>
53  </description>
54  </application>
55  ***/
56 
57 static char *app = "IVRDemo";
58 
59 static int ivr_demo_func(struct ast_channel *chan, void *data)
60 {
61  ast_verbose("IVR Demo, data is %s!\n", (char *) data);
62  return 0;
63 }
64 
65 AST_IVR_DECLARE_MENU(ivr_submenu, "IVR Demo Sub Menu", 0,
66 {
67  { "s", AST_ACTION_BACKGROUND, "demo-abouttotry" },
68  { "s", AST_ACTION_WAITOPTION },
69  { "1", AST_ACTION_PLAYBACK, "digits/1" },
70  { "1", AST_ACTION_PLAYBACK, "digits/1" },
71  { "1", AST_ACTION_RESTART },
72  { "2", AST_ACTION_PLAYLIST, "digits/2;digits/3" },
74  { "4", AST_ACTION_TRANSFER, "demo|s|1" },
75  { "*", AST_ACTION_REPEAT },
76  { "#", AST_ACTION_UPONE },
77  { NULL }
78 });
79 
80 AST_IVR_DECLARE_MENU(ivr_demo, "IVR Demo Main Menu", 0,
81 {
82  { "s", AST_ACTION_BACKGROUND, "demo-congrats" },
83  { "g", AST_ACTION_BACKGROUND, "demo-instruct" },
84  { "g", AST_ACTION_WAITOPTION },
85  { "1", AST_ACTION_PLAYBACK, "digits/1" },
86  { "1", AST_ACTION_RESTART },
87  { "2", AST_ACTION_MENU, &ivr_submenu },
88  { "2", AST_ACTION_RESTART },
89  { "i", AST_ACTION_PLAYBACK, "invalid" },
90  { "i", AST_ACTION_REPEAT, (void *)(unsigned long)2 },
91  { "#", AST_ACTION_EXIT },
92  { NULL },
93 });
94 
95 static int skel_exec(struct ast_channel *chan, const char *data)
96 {
97  int res=0;
98  char *tmp;
99 
100  if (ast_strlen_zero(data)) {
101  ast_log(LOG_WARNING, "skel requires an argument (filename)\n");
102  return -1;
103  }
104 
105  tmp = ast_strdupa(data);
106 
107  /* Do our thing here */
108 
109  if (ast_channel_state(chan) != AST_STATE_UP)
110  res = ast_answer(chan);
111  if (!res)
112  res = ast_ivr_menu_run(chan, &ivr_demo, tmp);
113 
114  return res;
115 }
116 
117 static int unload_module(void)
118 {
120 }
121 
122 static int load_module(void)
123 {
125 }
126 
127 AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "IVR Demo Application");
Main Channel structure associated with a channel.
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
static char * app
Definition: app_ivrdemo.c:57
#define LOG_WARNING
Definition: logger.h:274
static int tmp()
Definition: bt_open.c:389
static struct ast_ivr_menu ivr_submenu
Definition: app_ivrdemo.c:78
ast_channel_state
ast_channel states
Definition: channelstate.h:35
void ast_verbose(const char *fmt,...)
Definition: extconf.c:2207
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
#define NULL
Definition: resample.c:96
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "IVR Demo Application")
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
int ast_ivr_menu_run(struct ast_channel *c, struct ast_ivr_menu *menu, void *cbdata)
Runs an IVR menu.
Definition: main/app.c:2785
General Asterisk PBX channel definitions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
Core PBX routines and definitions.
static int unload_module(void)
Definition: app_ivrdemo.c:117
static int ivr_demo_func(struct ast_channel *chan, void *data)
Definition: app_ivrdemo.c:59
#define AST_IVR_DECLARE_MENU(holder, title, flags, foo...)
static int skel_exec(struct ast_channel *chan, const char *data)
Definition: app_ivrdemo.c:95
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:2814
static int load_module(void)
Definition: app_ivrdemo.c:122
void * data
Definition: pbx.c:248
static struct ast_ivr_menu ivr_demo
Definition: app_ivrdemo.c:93
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Asterisk module definitions.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626