Debian Codegraph @

apps/confbridge/conf_state_multi_marked.c

raw symbols SCIP
1 /*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2012, Terry Wilson
5 *
6 * Terry Wilson <[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 Confbridge state handling for the MULTI_MARKED state
22 *
23 * \author\verbatim Terry Wilson <[email protected]> \endverbatim
24 *
25 * \ingroup applications
26 */
27
28 /*** MODULEINFO
29 <support_level>core</support_level>
30 ***/
31
32 #include "asterisk.h"
33 #include "asterisk/utils.h"
34 #include "asterisk/linkedlists.h"
35 #include "include/confbridge.h"
36 #include "asterisk/musiconhold.h"
37 #include "include/conf_state.h"
38 #include "asterisk/pbx.h"
39
40 static void join_active(struct confbridge_user *user);
41 static void join_marked(struct confbridge_user *user);
42 static void leave_active(struct confbridge_user *user);
43 static void leave_marked(struct confbridge_user *user);
44 static void transition_to_marked(struct confbridge_user *user);
45
46 static struct confbridge_state STATE_MULTI_MARKED = {
47 .name = "MULTI_MARKED",
48 .join_unmarked = join_active,
49 .join_waitmarked = join_active,
50 .join_marked = join_marked,
51 .leave_unmarked = leave_active,
52 .leave_waitmarked = leave_active,
53 .leave_marked = leave_marked,
54 .entry = transition_to_marked,
55 };
56 struct confbridge_state *CONF_STATE_MULTI_MARKED = &STATE_MULTI_MARKED;
57
58 static void join_active(struct confbridge_user *user)
59 {
60 conf_add_user_active(user->conference, user);
61 conf_update_user_mute(user);
62 }
63
64 static void join_marked(struct confbridge_user *user)
65 {
66 conf_add_user_marked(user->conference, user);
67 conf_update_user_mute(user);
68 }
69
70 static void leave_active(struct confbridge_user *user)
71 {
72 conf_remove_user_active(user->conference, user);
73 if (user->conference->activeusers == 1) {
74 conf_change_state(user, CONF_STATE_SINGLE_MARKED);
75 }
76 }
77
78 static void leave_marked(struct confbridge_user *user)
79 {
80 struct confbridge_user *user_iter;
81 int need_prompt = 0;
82
83 conf_remove_user_marked(user->conference, user);
84
85 /* If all marked users have left, or we're set to kick if any marked user leaves, then boot everyone */
86 AST_LIST_TRAVERSE_SAFE_BEGIN(&user->conference->active_list, user_iter, list) {
87 if (user->conference->markedusers > 0 && !ast_test_flag(&user_iter->u_profile, USER_OPT_ENDMARKEDANY)) {
88 continue;
89 }
90 /* Kick ENDMARKED cbu_iters */
91 if ((ast_test_flag(&user_iter->u_profile, USER_OPT_ENDMARKED) || ast_test_flag(&user_iter->u_profile, USER_OPT_ENDMARKEDANY)) && !user_iter->kicked) {
92 if (ast_test_flag(&user_iter->u_profile, USER_OPT_WAITMARKED)
93 && (!ast_test_flag(&user_iter->u_profile, USER_OPT_MARKEDUSER) || ast_test_flag(&user_iter->u_profile, USER_OPT_ENDMARKEDANY))) {
94 AST_LIST_REMOVE_CURRENT(list);
95 user_iter->conference->activeusers--;
96 AST_LIST_INSERT_TAIL(&user_iter->conference->waiting_list, user_iter, list);
97 user_iter->conference->waitingusers++;
98 }
99 user_iter->kicked = 1;
100 pbx_builtin_setvar_helper(user_iter->chan, "CONFBRIDGE_RESULT", "ENDMARKED");
101 ast_bridge_remove(user_iter->conference->bridge, user_iter->chan);
102 } else if (ast_test_flag(&user_iter->u_profile, USER_OPT_WAITMARKED)
103 && !ast_test_flag(&user_iter->u_profile, USER_OPT_MARKEDUSER)) {
104 need_prompt = 1;
105
106 AST_LIST_REMOVE_CURRENT(list);
107 user_iter->conference->activeusers--;
108 AST_LIST_INSERT_TAIL(&user_iter->conference->waiting_list, user_iter, list);
109 user_iter->conference->waitingusers++;
110 } else {
111 /* User is neither wait_marked nor end_marked nor end_marked_any; however, they
112 * should still hear the prompt.
113 */
114 need_prompt = 1;
115 }
116 }
117 AST_LIST_TRAVERSE_SAFE_END;
118
119 switch (user->conference->activeusers) {
120 case 0:
121 /* Implies markedusers == 0 */
122 switch (user->conference->waitingusers) {
123 case 0:
124 conf_change_state(user, CONF_STATE_EMPTY);
125 break;
126 default:
127 conf_change_state(user, CONF_STATE_INACTIVE);
128 break;
129 }
130 break;
131 case 1:
132 switch (user->conference->markedusers) {
133 case 0:
134 conf_change_state(user, CONF_STATE_SINGLE);
135 break;
136 case 1:
137 /* XXX I seem to remember doing this for a reason, but right now it escapes me
138 * how we could possibly ever have a waiting user while we have a marked user */
139 switch (user->conference->waitingusers) {
140 case 0:
141 conf_change_state(user, CONF_STATE_SINGLE_MARKED);
142 break;
143 case 1:
144 break; /* Stay in marked */
145 }
146 break;
147 }
148 break;
149 default:
150 switch (user->conference->markedusers) {
151 case 0:
152 conf_change_state(user, CONF_STATE_MULTI);
153 break;
154 default:
155 break; /* Stay in marked */
156 }
157 }
158
159 if (need_prompt) {
160 /* Play back the audio prompt saying the leader has left the conference */
161 if (!ast_test_flag(&user->u_profile, USER_OPT_QUIET)) {
162 async_play_sound_file(user->conference,
163 conf_get_sound(CONF_SOUND_LEADER_HAS_LEFT, user->conference->b_profile.sounds),
164 NULL);
165 }
166
167 AST_LIST_TRAVERSE(&user->conference->waiting_list, user_iter, list) {
168 if (user_iter->kicked) {
169 continue;
170 }
171
172 if (ast_test_flag(&user_iter->u_profile, USER_OPT_MUSICONHOLD)) {
173 conf_moh_start(user_iter);
174 }
175
176 conf_update_user_mute(user_iter);
177 }
178 }
179 }
180
181 static int post_join_play_begin(struct confbridge_user *user)
182 {
183 int res;
184
185 ast_autoservice_start(user->chan);
186 res = play_sound_file(user->conference,
187 conf_get_sound(CONF_SOUND_BEGIN, user->conference->b_profile.sounds));
188 ast_autoservice_stop(user->chan);
189 return res;
190 }
191
192 static void transition_to_marked(struct confbridge_user *user)
193 {
194 struct confbridge_user *user_iter;
195 int waitmarked_moved = 0;
196
197 /* Move all waiting users to active, stopping MOH and unmuting if necessary */
198 AST_LIST_TRAVERSE_SAFE_BEGIN(&user->conference->waiting_list, user_iter, list) {
199 AST_LIST_REMOVE_CURRENT(list);
200 user->conference->waitingusers--;
201 AST_LIST_INSERT_TAIL(&user->conference->active_list, user_iter, list);
202 user->conference->activeusers++;
203 if (user_iter->playing_moh) {
204 conf_moh_stop(user_iter);
205 }
206 conf_update_user_mute(user_iter);
207 waitmarked_moved++;
208 }
209 AST_LIST_TRAVERSE_SAFE_END;
210
211 /* Play the audio file stating that the conference is beginning */
212 if (user->conference->markedusers == 1
213 && ast_test_flag(&user->u_profile, USER_OPT_MARKEDUSER)
214 && !ast_test_flag(&user->u_profile, USER_OPT_QUIET)
215 && waitmarked_moved) {
216 conf_add_post_join_action(user, post_join_play_begin);
217 }
218 }