Wed Jan 8 2020 09:49:39

Asterisk developer's documentation


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 <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  <support_level>extended</support_level>
31  ***/
32 
33 #include "asterisk.h"
34 
35 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
36 
37 #include "asterisk/file.h"
38 #include "asterisk/channel.h"
39 #include "asterisk/pbx.h"
40 #include "asterisk/module.h"
41 #include "asterisk/lock.h"
42 #include "asterisk/app.h"
43 
44 /*** DOCUMENTATION
45  <application name="IVRDemo" language="en_US">
46  <synopsis>
47  IVR Demo Application.
48  </synopsis>
49  <syntax>
50  <parameter name="filename" required="true" />
51  </syntax>
52  <description>
53  <para>This is a skeleton application that shows you the basic structure to create your
54  own asterisk applications and demonstrates the IVR demo.</para>
55  </description>
56  </application>
57  ***/
58 
59 static char *app = "IVRDemo";
60 
61 static int ivr_demo_func(struct ast_channel *chan, void *data)
62 {
63  ast_verbose("IVR Demo, data is %s!\n", (char *) data);
64  return 0;
65 }
66 
67 AST_IVR_DECLARE_MENU(ivr_submenu, "IVR Demo Sub Menu", 0,
68 {
69  { "s", AST_ACTION_BACKGROUND, "demo-abouttotry" },
70  { "s", AST_ACTION_WAITOPTION },
71  { "1", AST_ACTION_PLAYBACK, "digits/1" },
72  { "1", AST_ACTION_PLAYBACK, "digits/1" },
73  { "1", AST_ACTION_RESTART },
74  { "2", AST_ACTION_PLAYLIST, "digits/2;digits/3" },
76  { "4", AST_ACTION_TRANSFER, "demo|s|1" },
77  { "*", AST_ACTION_REPEAT },
78  { "#", AST_ACTION_UPONE },
79  { NULL }
80 });
81 
82 AST_IVR_DECLARE_MENU(ivr_demo, "IVR Demo Main Menu", 0,
83 {
84  { "s", AST_ACTION_BACKGROUND, "demo-congrats" },
85  { "g", AST_ACTION_BACKGROUND, "demo-instruct" },
86  { "g", AST_ACTION_WAITOPTION },
87  { "1", AST_ACTION_PLAYBACK, "digits/1" },
88  { "1", AST_ACTION_RESTART },
89  { "2", AST_ACTION_MENU, &ivr_submenu },
90  { "2", AST_ACTION_RESTART },
91  { "i", AST_ACTION_PLAYBACK, "invalid" },
92  { "i", AST_ACTION_REPEAT, (void *)(unsigned long)2 },
93  { "#", AST_ACTION_EXIT },
94  { NULL },
95 });
96 
97 static int skel_exec(struct ast_channel *chan, const char *data)
98 {
99  int res=0;
100  char *tmp;
101 
102  if (ast_strlen_zero(data)) {
103  ast_log(LOG_WARNING, "skel requires an argument (filename)\n");
104  return -1;
105  }
106 
107  tmp = ast_strdupa(data);
108 
109  /* Do our thing here */
110 
111  if (chan->_state != AST_STATE_UP)
112  res = ast_answer(chan);
113  if (!res)
114  res = ast_ivr_menu_run(chan, &ivr_demo, tmp);
115 
116  return res;
117 }
118 
119 static int unload_module(void)
120 {
121  return ast_unregister_application(app);
122 }
123 
124 static int load_module(void)
125 {
127 }
128 
Main Channel structure associated with a channel.
Definition: channel.h:742
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:396
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
static char * app
Definition: app_ivrdemo.c:59
#define LOG_WARNING
Definition: logger.h:144
void ast_verbose(const char *fmt,...)
Definition: logger.c:1568
#define AST_IVR_DECLARE_MENU(holder, title, flags, foo...)
Definition: app.h:83
static struct ast_ivr_menu ivr_submenu
Definition: app_ivrdemo.c:80
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
General Asterisk PBX channel definitions.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
Core PBX routines and definitions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
static int unload_module(void)
Definition: app_ivrdemo.c:119
static int ivr_demo_func(struct ast_channel *chan, void *data)
Definition: app_ivrdemo.c:61
enum ast_channel_state _state
Definition: channel.h:839
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int ast_ivr_menu_run(struct ast_channel *c, struct ast_ivr_menu *menu, void *cbdata)
Runs an IVR menu.
Definition: app.c:1980
static int skel_exec(struct ast_channel *chan, const char *data)
Definition: app_ivrdemo.c:97
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:3086
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
static int load_module(void)
Definition: app_ivrdemo.c:124
static struct ast_ivr_menu ivr_demo
Definition: app_ivrdemo.c:95
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
Asterisk module definitions.
union ast_frame::@172 data
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180