Resolve issues in ConfBridge regarding marked, waitmarked, and unmarked users
[asterisk/asterisk.git] / apps / confbridge / conf_state_single.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2012, Terry Wilson
5  *
6  * Terry Wilson <twilson@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  * Please follow coding guidelines
19  * http://svn.digium.com/view/asterisk/trunk/doc/CODING-GUIDELINES
20  */
21
22 /*! \file
23  *
24  * \brief Confbridge state handling for the SINGLE state
25  *
26  * \author\verbatim Terry Wilson <twilson@digium.com> \endverbatim
27  *
28  * \ingroup applications
29  */
30
31 /*** MODULEINFO
32         <support_level>core</support_level>
33  ***/
34
35 #include "include/confbridge.h"
36 #include "include/conf_state.h"
37
38 static void join_unmarked(struct conference_bridge_user *cbu);
39 static void join_marked(struct conference_bridge_user *cbu);
40 static void leave_unmarked(struct conference_bridge_user *cbu);
41 static void transition_to_single(struct conference_bridge_user *cbu);
42
43 struct conference_state STATE_SINGLE = {
44         .name = "SINGLE",
45         .join_unmarked = join_unmarked,
46         .join_waitmarked = conf_default_join_waitmarked,
47         .join_marked = join_marked,
48         .leave_unmarked = leave_unmarked,
49         .leave_waitmarked = conf_default_leave_waitmarked,
50         .entry = transition_to_single,
51 };
52 struct conference_state *CONF_STATE_SINGLE = &STATE_SINGLE;
53
54 static void join_unmarked(struct conference_bridge_user *cbu)
55 {
56         conf_add_user_active(cbu->conference_bridge, cbu);
57         conf_handle_second_active(cbu->conference_bridge);
58
59         conf_change_state(cbu, CONF_STATE_MULTI);
60 }
61
62 static void join_marked(struct conference_bridge_user *cbu)
63 {
64         conf_add_user_marked(cbu->conference_bridge, cbu);
65         conf_handle_second_active(cbu->conference_bridge);
66
67         conf_change_state(cbu, CONF_STATE_MULTI_MARKED);
68 }
69
70 static void leave_unmarked(struct conference_bridge_user *cbu)
71 {
72         conf_remove_user_active(cbu->conference_bridge, cbu);
73
74         if (cbu->conference_bridge->waitingusers) {
75                 conf_change_state(cbu, CONF_STATE_INACTIVE);
76         } else {
77                 conf_change_state(cbu, CONF_STATE_EMPTY);
78         }
79 }
80
81 static void transition_to_single(struct conference_bridge_user *cbu)
82 {
83         conf_mute_only_active(cbu->conference_bridge);
84 }