[asterisk-commits] qwell: branch qwell/pimp_my_dtmf r385888 - in /team/qwell/pimp_my_dtmf: ./ ap...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Apr 16 13:14:45 CDT 2013


Author: qwell
Date: Tue Apr 16 13:14:43 2013
New Revision: 385888

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=385888
Log:
Multiple revisions 385748,385790,385837,385864,385866

........
  r385748 | root | 2013-04-15 12:17:45 -0500 (Mon, 15 Apr 2013) | 50 lines
  
  Multiple revisions 385734,385742-385743
  
  ........
    r385734 | dlee | 2013-04-15 11:22:03 -0500 (Mon, 15 Apr 2013) | 16 lines
    
    DTMF events are now published on a channel's stasis_topic. AMI was
    refactored to use these events rather than producing the events directly
    in channel.c. Finally, the code was added to app_stasis to produce
    DTMF events on the WebSocket.
    
    The AMI events are completely backward compatible, including sending
    events on transmitted DTMF, and sending DTMF start events.
    
    The Stasis-HTTP events are somewhat simplified. Since DTMF start and
    DTMF send events are generally less useful, Stasis-HTTP will only send
    events on received DTMF end.
    
    (closes issue ASTERISK-21282)
    (closes issue ASTERISK-21359)
    Review: https://reviewboard.asterisk.org/r/2439
  ........
    r385742 | dlee | 2013-04-15 11:43:47 -0500 (Mon, 15 Apr 2013) | 20 lines
    
    Moved core logic from app_stasis to res_stasis
    
    After some discussion on asterisk-dev, it was decided that the bulk of
    the logic in app_stasis actually belongs in a resource module instead
    of the application module.
    
    This patch does that, leaves the app specific stuff in app_stasis, and
    fixes up everything else to be consistent with that change.
    
     * Renamed test_app_stasis to test_res_stasis
     * Renamed app_stasis.h to stasis_app.h
       * This is still stasis application support, even though it's no
         longer in an app_ module. The name should never have been tied to
         the type of module, anyways.
     * Now that json isn't a resource module anymore, moved the
       ast_channel_snapshot_to_json function to main/stasis_channels.c,
       where it makes more sense.
    
    Review: https://reviewboard.asterisk.org/r/2430/
  ........
    r385743 | dlee | 2013-04-15 11:47:25 -0500 (Mon, 15 Apr 2013) | 1 line
    
    Avoid unused variable warning when not in devmode
  ........
  
  Merged revisions 385734,385742-385743 from file:///srv/subversion/repos/asterisk/trunk
........
  r385790 | root | 2013-04-15 13:17:38 -0500 (Mon, 15 Apr 2013) | 13 lines
  
  Don't unnecessarily rebuild things on every run of 'make'.
  
  Review: https://reviewboard.asterisk.org/r/2449/
  ........
  
  Merged revisions 385745 from http://svn.asterisk.org/svn/asterisk/branches/1.8
  ........
  
  Merged revisions 385768 from http://svn.asterisk.org/svn/asterisk/branches/11
  ........
  
  Merged revisions 385782 from file:///srv/subversion/repos/asterisk/trunk
........
  r385837 | root | 2013-04-16 09:17:55 -0500 (Tue, 16 Apr 2013) | 5 lines
  
  Fixed a typo
  ........
  
  Merged revisions 385835 from file:///srv/subversion/repos/asterisk/trunk
........
  r385864 | kharwell | 2013-04-16 10:53:45 -0500 (Tue, 16 Apr 2013) | 1 line
  
  Modified the fast fast picture update request handler to always send through the session (using ast_sip_session_send_request instead of ast_sip_send_request)
........
  r385866 | root | 2013-04-16 11:17:46 -0500 (Tue, 16 Apr 2013) | 31 lines
  
  Multiple revisions 385860,385862
  
  ........
    r385860 | kmoore | 2013-04-16 10:33:59 -0500 (Tue, 16 Apr 2013) | 12 lines
    
    Move device state distribution to Stasis-core
    
    In the move from Asterisk's event system to Stasis, this makes
    distributed device state aggregation always-on, removes unnecessary
    task processors where possible, and collapses aggregate and
    non-aggregate states into a single cache for ease of retrieval. This
    also removes an intermediary step in device state aggregation.
    
    Review: https://reviewboard.asterisk.org/r/2389/
    (closes issue ASTERISK-21101)
    Patch-by: Kinsey Moore <kmoore at digium.com>
  ........
    r385862 | kmoore | 2013-04-16 10:48:16 -0500 (Tue, 16 Apr 2013) | 9 lines
    
    Move presence state distribution to Stasis-core
    
    Convert presence state events to Stasis-core messages and remove
    redundant serializers where possible.
    
    Review: https://reviewboard.asterisk.org/r/2410/
    (closes issue ASTERISK-21102)
    Patch-by: Kinsey Moore <kmoore at digium.com>
  ........
  
  Merged revisions 385860,385862 from file:///srv/subversion/repos/asterisk/trunk
........

Merged revisions 385748,385790,385837,385864,385866 from http://svn.asterisk.org/svn/asterisk/team/group/pimp_my_sip

Added:
    team/qwell/pimp_my_dtmf/include/asterisk/stasis_app.h
      - copied unchanged from r385866, team/group/pimp_my_sip/include/asterisk/stasis_app.h
    team/qwell/pimp_my_dtmf/res/res_stasis.c
      - copied unchanged from r385866, team/group/pimp_my_sip/res/res_stasis.c
    team/qwell/pimp_my_dtmf/res/res_stasis.exports.in
      - copied unchanged from r385866, team/group/pimp_my_sip/res/res_stasis.exports.in
    team/qwell/pimp_my_dtmf/tests/test_res_stasis.c
      - copied unchanged from r385866, team/group/pimp_my_sip/tests/test_res_stasis.c
Removed:
    team/qwell/pimp_my_dtmf/apps/app_stasis.exports.in
    team/qwell/pimp_my_dtmf/apps/stasis_json.c
    team/qwell/pimp_my_dtmf/include/asterisk/app_stasis.h
    team/qwell/pimp_my_dtmf/tests/test_app_stasis.c
Modified:
    team/qwell/pimp_my_dtmf/   (props changed)
    team/qwell/pimp_my_dtmf/Makefile
    team/qwell/pimp_my_dtmf/apps/Makefile
    team/qwell/pimp_my_dtmf/apps/app_queue.c
    team/qwell/pimp_my_dtmf/apps/app_stasis.c
    team/qwell/pimp_my_dtmf/channels/chan_gulp.c
    team/qwell/pimp_my_dtmf/funcs/func_presencestate.c
    team/qwell/pimp_my_dtmf/include/asterisk/cli.h
    team/qwell/pimp_my_dtmf/include/asterisk/devicestate.h
    team/qwell/pimp_my_dtmf/include/asterisk/json.h
    team/qwell/pimp_my_dtmf/include/asterisk/presencestate.h
    team/qwell/pimp_my_dtmf/include/asterisk/stasis_channels.h
    team/qwell/pimp_my_dtmf/include/asterisk/strings.h
    team/qwell/pimp_my_dtmf/include/asterisk/xmpp.h
    team/qwell/pimp_my_dtmf/main/asterisk.c
    team/qwell/pimp_my_dtmf/main/ccss.c
    team/qwell/pimp_my_dtmf/main/channel.c
    team/qwell/pimp_my_dtmf/main/devicestate.c
    team/qwell/pimp_my_dtmf/main/json.c
    team/qwell/pimp_my_dtmf/main/manager_channels.c
    team/qwell/pimp_my_dtmf/main/pbx.c
    team/qwell/pimp_my_dtmf/main/presencestate.c
    team/qwell/pimp_my_dtmf/main/stasis_channels.c
    team/qwell/pimp_my_dtmf/res/res_jabber.c
    team/qwell/pimp_my_dtmf/res/res_stasis_websocket.c
    team/qwell/pimp_my_dtmf/res/res_xmpp.c
    team/qwell/pimp_my_dtmf/tests/test_devicestate.c
    team/qwell/pimp_my_dtmf/tests/test_json.c
    team/qwell/pimp_my_dtmf/tests/test_stasis_channels.c

Propchange: team/qwell/pimp_my_dtmf/
------------------------------------------------------------------------------
Binary property 'branch-11-merged' - no diff available.

Propchange: team/qwell/pimp_my_dtmf/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Tue Apr 16 13:14:43 2013
@@ -1,1 +1,1 @@
-/team/group/pimp_my_sip:1-385739 /trunk:1-385317
+/team/group/pimp_my_sip:1-385887 /trunk:1-385317

Modified: team/qwell/pimp_my_dtmf/Makefile
URL: http://svnview.digium.com/svn/asterisk/team/qwell/pimp_my_dtmf/Makefile?view=diff&rev=385888&r1=385887&r2=385888
==============================================================================
--- team/qwell/pimp_my_dtmf/Makefile (original)
+++ team/qwell/pimp_my_dtmf/Makefile Tue Apr 16 13:14:43 2013
@@ -356,7 +356,7 @@
 	+@$(SUBMAKE) $(MOD_SUBDIRS_EMBED_LDFLAGS)
 	+@$(SUBMAKE) $(MOD_SUBDIRS_EMBED_LIBS)
 
-$(SUBDIRS): makeopts cleantest main/version.c include/asterisk/build.h include/asterisk/buildopts.h defaults.h makeopts.embed_rules
+$(SUBDIRS): makeopts .lastclean main/version.c include/asterisk/build.h include/asterisk/buildopts.h defaults.h makeopts.embed_rules
 
 ifeq ($(findstring $(OSARCH), mingw32 cygwin ),)
     # Non-windows:
@@ -382,26 +382,25 @@
 $(OTHER_SUBDIRS): makeopts
 	+ at _ASTCFLAGS="$(OTHER_SUBDIR_CFLAGS) $(_ASTCFLAGS)" ASTCFLAGS="$(ASTCFLAGS)" _ASTLDFLAGS="$(_ASTLDFLAGS)" ASTLDFLAGS="$(ASTLDFLAGS)" $(SUBMAKE) --no-builtin-rules -C $@ SUBDIR=$@ all
 
-defaults.h: makeopts cleantest build_tools/make_defaults_h
+defaults.h: makeopts .lastclean build_tools/make_defaults_h
 	@build_tools/make_defaults_h > $@.tmp
 	@cmp -s $@.tmp $@ || mv $@.tmp $@
 	@rm -f $@.tmp
 
-main/version.c: FORCE cleantest
+main/version.c: FORCE .lastclean
 	@build_tools/make_version_c > $@.tmp
 	@cmp -s $@.tmp $@ || mv $@.tmp $@
 	@rm -f $@.tmp
 
-include/asterisk/buildopts.h: menuselect.makeopts cleantest
+include/asterisk/buildopts.h: menuselect.makeopts .lastclean
 	@build_tools/make_buildopts_h > $@.tmp
 	@cmp -s $@.tmp $@ || mv $@.tmp $@
 	@rm -f $@.tmp
 
-# build.h must depend on cleantest, or parallel make may wipe it out after it's
-# been created. But since build.h contains a timestamp, the cmp trick used above
-# won't work. Just testing for existence is good enough.
-include/asterisk/build.h: cleantest
-	@test -f $@ || build_tools/make_build_h > $@
+# build.h must depend on .lastclean, or parallel make may wipe it out after it's
+# been created.
+include/asterisk/build.h: .lastclean
+	@build_tools/make_build_h > $@
 
 $(SUBDIRS_CLEAN):
 	+@$(SUBMAKE) -C $(@:-clean=) clean
@@ -459,7 +458,7 @@
   XML_core_en_US = $(foreach dir,$(MOD_SUBDIRS),$(shell $(GREP) -l "language=\"en_US\"" $(dir)/*.c $(dir)/*.cc 2>/dev/null))
 endif
 
-doc/core-en_US.xml: makeopts cleantest $(XML_core_en_US)
+doc/core-en_US.xml: makeopts .lastclean $(XML_core_en_US)
 	@printf "Building Documentation For: "
 	@echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > $@
 	@echo "<!DOCTYPE docs SYSTEM \"appdocsxml.dtd\">" >> $@
@@ -477,7 +476,7 @@
   XMX_full_en_US = $(foreach dir,$(MOD_SUBDIRS),$(shell $(GREP) -l "language=\"en_US\"" $(dir)/*.c $(dir)/*.cc 2>/dev/null))
 endif
 
-doc/full-en_US.xml: makeopts cleantest $(XML_full_en_US)
+doc/full-en_US.xml: makeopts .lastclean $(XML_full_en_US)
 ifeq ($(PYTHON),:)
 	@echo "--------------------------------------------------------------------------"
 	@echo "---        Please install python to build full documentation           ---"
@@ -848,8 +847,8 @@
 # .cleancount is the global clean count, and .lastclean is the
 # last clean count we had
 
-cleantest:
-	@cmp -s .cleancount .lastclean || $(MAKE) clean
+.lastclean: .cleancount
+	@$(MAKE) clean
 	@[ -f "$(DESTDIR)$(ASTDBDIR)/astdb.sqlite3" ] || [ ! -f "$(DESTDIR)$(ASTDBDIR)/astdb" ] || [ ! -f menuselect.makeopts ] || grep -q MENUSELECT_UTILS=.*astdb2sqlite3 menuselect.makeopts || (sed -i.orig -e's/MENUSELECT_UTILS=\(.*\)/MENUSELECT_UTILS=\1 astdb2sqlite3/' menuselect.makeopts && echo "Updating menuselect.makeopts to include astdb2sqlite3" && echo "Original version backed up to menuselect.makeopts.orig")
 
 $(SUBDIRS_UNINSTALL):
@@ -927,19 +926,19 @@
 		CFLAGS="$(BUILD_CFLAGS)" LDFLAGS="$(BUILD_LDFLAGS)" \
 		$(MAKE) -C menuselect CONFIGURE_SILENT="--silent"
 
-menuselect/menuselect: menuselect/makeopts cleantest
+menuselect/menuselect: menuselect/makeopts .lastclean
 	+$(MAKE_MENUSELECT) menuselect
 
-menuselect/cmenuselect: menuselect/makeopts cleantest
+menuselect/cmenuselect: menuselect/makeopts .lastclean
 	+$(MAKE_MENUSELECT) cmenuselect
 
-menuselect/gmenuselect: menuselect/makeopts cleantest
+menuselect/gmenuselect: menuselect/makeopts .lastclean
 	+$(MAKE_MENUSELECT) gmenuselect
 
-menuselect/nmenuselect: menuselect/makeopts cleantest
+menuselect/nmenuselect: menuselect/makeopts .lastclean
 	+$(MAKE_MENUSELECT) nmenuselect
 
-menuselect/makeopts: makeopts cleantest
+menuselect/makeopts: makeopts .lastclean
 	+$(MAKE_MENUSELECT) makeopts
 
 menuselect-tree: $(foreach dir,$(filter-out main,$(MOD_SUBDIRS)),$(wildcard $(dir)/*.c) $(wildcard $(dir)/*.cc)) build_tools/cflags.xml build_tools/cflags-devmode.xml sounds/sounds.xml build_tools/embed_modules.xml utils/utils.xml agi/agi.xml configure makeopts
@@ -970,7 +969,6 @@
 .PHONY: full
 .PHONY: _full
 .PHONY: prereqs
-.PHONY: cleantest
 .PHONY: uninstall
 .PHONY: _uninstall
 .PHONY: uninstall-all

Modified: team/qwell/pimp_my_dtmf/apps/Makefile
URL: http://svnview.digium.com/svn/asterisk/team/qwell/pimp_my_dtmf/apps/Makefile?view=diff&rev=385888&r1=385887&r2=385888
==============================================================================
--- team/qwell/pimp_my_dtmf/apps/Makefile (original)
+++ team/qwell/pimp_my_dtmf/apps/Makefile Tue Apr 16 13:14:43 2013
@@ -37,5 +37,3 @@
   LIBS+= -lres_features.so -lres_ael_share.so -lres_monitor.so -lres_speech.so
   LIBS+= -lres_smdi.so
 endif
-
-app_stasis.so: stasis_json.o

Modified: team/qwell/pimp_my_dtmf/apps/app_queue.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/pimp_my_dtmf/apps/app_queue.c?view=diff&rev=385888&r1=385887&r2=385888
==============================================================================
--- team/qwell/pimp_my_dtmf/apps/app_queue.c (original)
+++ team/qwell/pimp_my_dtmf/apps/app_queue.c Tue Apr 16 13:14:43 2013
@@ -990,9 +990,6 @@
 	{ QUEUE_AUTOPAUSE_ALL,"all" },
 };
 
-
-static struct ast_taskprocessor *devicestate_tps;
-
 #define DEFAULT_RETRY		5
 #define DEFAULT_TIMEOUT		15
 #define RECHECK			1		/*!< Recheck every second to see we we're at the top yet */
@@ -1037,8 +1034,8 @@
 /*! \brief queues.conf [general] option */
 static int shared_lastcall = 1;
 
-/*! \brief Subscription to device state change events */
-static struct ast_event_sub *device_state_sub;
+/*! \brief Subscription to device state change messages */
+static struct stasis_subscription *device_state_sub;
 
 /*! \brief queues.conf [general] option */
 static int update_cdr = 0;
@@ -1618,12 +1615,6 @@
 	return -1;
 }
 
-struct statechange {
-	AST_LIST_ENTRY(statechange) entry;
-	int state;
-	char dev[0];
-};
-
 /*! \brief set a member's status based on device state of that member's state_interface.
  *
  * Lock interface list find sc, iterate through each queues queue_member list for member to
@@ -1742,10 +1733,10 @@
 }
 
 /*! \brief set a member's status based on device state of that member's interface*/
-static int handle_statechange(void *datap)
-{
-	struct statechange *sc = datap;
+static void device_state_cb(void *unused, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *msg)
+{
 	struct ao2_iterator miter, qiter;
+	struct ast_device_state_message *dev_state;
 	struct member *m;
 	struct call_queue *q;
 	char interface[80], *slash_pos;
@@ -1753,6 +1744,16 @@
 	int found_member;		/* Found this member in this queue */
 	int avail = 0;			/* Found an available member in this queue */
 
+	if (ast_device_state_message_type() != stasis_message_type(msg)) {
+		return;
+	}
+
+	dev_state = stasis_message_data(msg);
+	if (dev_state->eid) {
+		/* ignore non-aggregate states */
+		return;
+	}
+
 	qiter = ao2_iterator_init(queues, 0);
 	while ((q = ao2_t_iterator_next(&qiter, "Iterate over queues"))) {
 		ao2_lock(q);
@@ -1770,9 +1771,9 @@
 					}
 				}
 
-				if (!strcasecmp(interface, sc->dev)) {
+				if (!strcasecmp(interface, dev_state->device)) {
 					found_member = 1;
-					update_status(q, m, sc->state);
+					update_status(q, m, dev_state->state);
 				}
 			}
 
@@ -1804,39 +1805,18 @@
 	ao2_iterator_destroy(&qiter);
 
 	if (found) {
-		ast_debug(1, "Device '%s' changed to state '%d' (%s)\n", sc->dev, sc->state, ast_devstate2str(sc->state));
+		ast_debug(1, "Device '%s' changed to state '%d' (%s)\n",
+			dev_state->device,
+			dev_state->state,
+			ast_devstate2str(dev_state->state));
 	} else {
-		ast_debug(3, "Device '%s' changed to state '%d' (%s) but we don't care because they're not a member of any queue.\n", sc->dev, sc->state, ast_devstate2str(sc->state));
-	}
-
-	ast_free(sc);
-	return 0;
-}
-
-static void device_state_cb(const struct ast_event *event, void *unused)
-{
-	enum ast_device_state state;
-	const char *device;
-	struct statechange *sc;
-	size_t datapsize;
-
-	state = ast_event_get_ie_uint(event, AST_EVENT_IE_STATE);
-	device = ast_event_get_ie_str(event, AST_EVENT_IE_DEVICE);
-
-	if (ast_strlen_zero(device)) {
-		ast_log(LOG_ERROR, "Received invalid event that had no device IE\n");
-		return;
-	}
-	datapsize = sizeof(*sc) + strlen(device) + 1;
-	if (!(sc = ast_calloc(1, datapsize))) {
-		ast_log(LOG_ERROR, "failed to calloc a state change struct\n");
-		return;
-	}
-	sc->state = state;
-	strcpy(sc->dev, device);
-	if (ast_taskprocessor_push(devicestate_tps, handle_statechange, sc) < 0) {
-		ast_free(sc);
-	}
+		ast_debug(3, "Device '%s' changed to state '%d' (%s) but we don't care because they're not a member of any queue.\n",
+			dev_state->device,
+			dev_state->state,
+			ast_devstate2str(dev_state->state));
+	}
+
+	return;
 }
 
 /*! \brief Helper function which converts from extension state to device state values */
@@ -9876,8 +9856,9 @@
 
 	res |= ast_data_unregister(NULL);
 
-	if (device_state_sub)
-		ast_event_unsubscribe(device_state_sub);
+	if (device_state_sub) {
+		device_state_sub = stasis_unsubscribe(device_state_sub);
+	}
 
 	ast_extension_state_del(0, extension_state_cb);
 
@@ -9887,7 +9868,6 @@
 		queue_t_unref(q, "Done with iterator");
 	}
 	ao2_iterator_destroy(&q_iter);
-	devicestate_tps = ast_taskprocessor_unreference(devicestate_tps);
 	ao2_ref(queues, -1);
 	ast_unload_realtime("queue_members");
 	return res;
@@ -9948,12 +9928,8 @@
 	res |= ast_custom_function_register(&queuewaitingcount_function);
 	res |= ast_custom_function_register(&queuememberpenalty_function);
 
-	if (!(devicestate_tps = ast_taskprocessor_get("app_queue", 0))) {
-		ast_log(LOG_WARNING, "devicestate taskprocessor reference failed - devicestate notifications will not occur\n");
-	}
-
 	/* in the following subscribe call, do I use DEVICE_STATE, or DEVICE_STATE_CHANGE? */
-	if (!(device_state_sub = ast_event_subscribe(AST_EVENT_DEVICE_STATE, device_state_cb, "AppQueue Device state", NULL, AST_EVENT_IE_END))) {
+	if (!(device_state_sub = stasis_subscribe(ast_device_state_topic_all(), device_state_cb, NULL))) {
 		res = -1;
 	}
 

Modified: team/qwell/pimp_my_dtmf/apps/app_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/pimp_my_dtmf/apps/app_stasis.c?view=diff&rev=385888&r1=385887&r2=385888
==============================================================================
--- team/qwell/pimp_my_dtmf/apps/app_stasis.c (original)
+++ team/qwell/pimp_my_dtmf/apps/app_stasis.c Tue Apr 16 13:14:43 2013
@@ -24,6 +24,7 @@
  */
 
 /*** MODULEINFO
+	<depend>res_stasis</depend>
 	<support_level>core</support_level>
  ***/
 
@@ -32,14 +33,9 @@
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include "asterisk/app.h"
-#include "asterisk/app_stasis.h"
-#include "asterisk/astobj2.h"
-#include "asterisk/channel.h"
-#include "asterisk/lock.h"
 #include "asterisk/module.h"
 #include "asterisk/stasis.h"
-#include "asterisk/strings.h"
-#include "asterisk/stasis_channels.h"
+#include "asterisk/stasis_app.h"
 
 /*** DOCUMENTATION
 	<application name="Stasis" language="en_US">
@@ -67,347 +63,10 @@
 /*! \brief Dialplan application name */
 static const char *stasis = "Stasis";
 
-/*!
- * \brief Number of buckets for the Stasis application hash table.  Remember to
- * keep it a prime number!
- */
-#define APPS_NUM_BUCKETS 127
-
-/*!
- * \brief Number of buckets for the Stasis application hash table.  Remember to
- * keep it a prime number!
- */
-#define CONTROLS_NUM_BUCKETS 127
-
-/*!
- * \brief Stasis application container. Please call apps_registry() instead of
- * directly accessing.
- */
-struct ao2_container *__apps_registry;
-
-struct ao2_container *__app_controls;
-
-/*! Ref-counting accessor for the stasis applications container */
-static struct ao2_container *apps_registry(void)
+/*! /brief Stasis dialplan application callback */
+static int app_exec(struct ast_channel *chan, const char *data)
 {
-	ao2_ref(__apps_registry, +1);
-	return __apps_registry;
-}
-
-static struct ao2_container *app_controls(void)
-{
-	ao2_ref(__app_controls, +1);
-	return __app_controls;
-}
-
-struct app {
-	/*! Callback function for this application. */
-	stasis_app_cb handler;
-	/*! Opaque data to hand to callback function. */
-	void *data;
-	/*! Name of the Stasis application */
-	char name[];
-};
-
-static void app_dtor(void *obj)
-{
-	struct app *app = obj;
-
-	ao2_cleanup(app->data);
-	app->data = NULL;
-}
-
-/*! Constructor for \ref app. */
-static struct app *app_create(const char *name, stasis_app_cb handler, void *data)
-{
-	struct app *app;
-	size_t size;
-
-	ast_assert(name != NULL);
-	ast_assert(handler != NULL);
-
-	size = sizeof(*app) + strlen(name) + 1;
-	app = ao2_alloc_options(size, app_dtor, AO2_ALLOC_OPT_LOCK_MUTEX);
-
-	if (!app) {
-		return NULL;
-	}
-
-	strncpy(app->name, name, size - sizeof(*app));
-	app->handler = handler;
-	ao2_ref(data, +1);
-	app->data = data;
-
-	return app;
-}
-
-/*! AO2 hash function for \ref app */
-static int app_hash(const void *obj, const int flags)
-{
-	const struct app *app = obj;
-	const char *name = flags & OBJ_KEY ? obj : app->name;
-
-	return ast_str_hash(name);
-}
-
-/*! AO2 comparison function for \ref app */
-static int app_compare(void *lhs, void *rhs, int flags)
-{
-	const struct app *lhs_app = lhs;
-	const struct app *rhs_app = rhs;
-	const char *rhs_name = flags & OBJ_KEY ? rhs : rhs_app->name;
-
-	if (strcmp(lhs_app->name, rhs_name) == 0) {
-		return CMP_MATCH | CMP_STOP;
-	} else {
-		return 0;
-	}
-}
-
-/*!
- * \brief Send a message to the given application.
- * \param app App to send the message to.
- * \param message Message to send.
- */
-static void app_send(struct app *app, struct ast_json *message)
-{
-	app->handler(app->data, app->name, message);
-}
-
-struct stasis_app_control {
-	/*!
-	 * When set, /c app_stasis should exit and continue in the dialplan.
-	 */
-	int continue_to_dialplan:1;
-	/*! Uniqueid of the associated channel */
-	char channel_id[];
-};
-
-static struct stasis_app_control *control_create(const char *uniqueid)
-{
-	struct stasis_app_control *control;
-	size_t size;
-
-	size = sizeof(*control) + strlen(uniqueid) + 1;
-	control = ao2_alloc(size, NULL);
-	if (!control) {
-		return NULL;
-	}
-
-	strncpy(control->channel_id, uniqueid, size - sizeof(*control));
-
-	return control;
-}
-
-/*! AO2 hash function for \ref stasis_app_control */
-static int control_hash(const void *obj, const int flags)
-{
-	const struct stasis_app_control *control = obj;
-	const char *id = flags & OBJ_KEY ? obj : control->channel_id;
-
-	return ast_str_hash(id);
-}
-
-/*! AO2 comparison function for \ref stasis_app_control */
-static int control_compare(void *lhs, void *rhs, int flags)
-{
-	const struct stasis_app_control *lhs_control = lhs;
-	const struct stasis_app_control *rhs_control = rhs;
-	const char *rhs_name =
-		flags & OBJ_KEY ? rhs : rhs_control->channel_id;
-
-	if (strcmp(lhs_control->channel_id, rhs_name) == 0) {
-		return CMP_MATCH | CMP_STOP;
-	} else {
-		return 0;
-	}
-}
-
-struct stasis_app_control *stasis_app_control_find_by_channel(
-	const struct ast_channel *chan)
-{
-	RAII_VAR(struct ao2_container *, controls, NULL, ao2_cleanup);
-	if (chan == NULL) {
-		return NULL;
-	}
-
-	controls = app_controls();
-	return ao2_find(controls, ast_channel_uniqueid(chan), OBJ_KEY);
-}
-
-/*!
- * \brief Test the \c continue_to_dialplan bit for the given \a app.
- *
- * The bit is also reset for the next call.
- *
- * \param app Application to check the \c continue_to_dialplan bit.
- * \return Zero to remain in \c Stasis
- * \return Non-zero to continue in the dialplan
- */
-static int control_continue_test_and_reset(struct stasis_app_control *control)
-{
-        int r;
-        SCOPED_AO2LOCK(lock, control);
-
-        r = control->continue_to_dialplan;
-        control->continue_to_dialplan = 0;
-        return r;
-}
-
-void stasis_app_control_continue(struct stasis_app_control *control)
-{
-	SCOPED_AO2LOCK(lock, control);
-	control->continue_to_dialplan = 1;
-}
-
-static struct ast_json *app_event_create(
-	const char *event_name,
-	const struct ast_channel_snapshot *snapshot,
-	const struct ast_json *extra_info)
-{
-	RAII_VAR(struct ast_json *, message, NULL, ast_json_unref);
-	RAII_VAR(struct ast_json *, event, NULL, ast_json_unref);
-
-	if (extra_info) {
-		event = ast_json_deep_copy(extra_info);
-	} else {
-		event = ast_json_object_create();
-	}
-
-	if (snapshot) {
-		int ret;
-
-		/* Mustn't already have a channel field */
-		ast_assert(ast_json_object_get(event, "channel") == NULL);
-
-		ret = ast_json_object_set(
-			event,
-			"channel", ast_channel_snapshot_to_json(snapshot));
-		if (ret != 0) {
-			return NULL;
-		}
-	}
-
-	message = ast_json_pack("{s: o}", event_name, ast_json_ref(event));
-
-	return ast_json_ref(message);
-}
-
-static int send_start_msg(struct app *app, struct ast_channel *chan,
-			  int argc, char *argv[])
-{
-	RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref);
-	RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
-
-	struct ast_json *json_args;
-	int i;
-
-	ast_assert(chan != NULL);
-
-	/* Set channel info */
-	snapshot = ast_channel_snapshot_create(chan);
-	if (!snapshot) {
-		return -1;
-	}
-
-	msg = ast_json_pack("{s: {s: [], s: o}}",
-			    "stasis-start",
-			    "args",
-			    "channel", ast_channel_snapshot_to_json(snapshot));
-
-	if (!msg) {
-		return -1;
-	}
-
-	/* Append arguments to args array */
-	json_args = ast_json_object_get(
-		ast_json_object_get(msg, "stasis-start"),
-		"args");
-	ast_assert(json_args != NULL);
-	for (i = 0; i < argc; ++i) {
-		int r = ast_json_array_append(json_args,
-					      ast_json_string_create(argv[i]));
-		if (r != 0) {
-			ast_log(LOG_ERROR, "Error appending start message\n");
-			return -1;
-		}
-	}
-
-	app_send(app, msg);
-	return 0;
-}
-
-static int send_end_msg(struct app *app, struct ast_channel *chan)
-{
-	RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref);
-	RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
-
-	ast_assert(chan != NULL);
-
-	/* Set channel info */
-	snapshot = ast_channel_snapshot_create(chan);
-	if (snapshot == NULL) {
-		return -1;
-	}
-	msg = app_event_create("stasis-end", snapshot, NULL);
-	if (!msg) {
-		return -1;
-	}
-
-	app_send(app, msg);
-	return 0;
-}
-
-static void sub_handler(void *data, struct stasis_subscription *sub,
-			struct stasis_topic *topic,
-			struct stasis_message *message)
-{
-	struct app *app = data;
-	if (ast_channel_snapshot_type() == stasis_message_type(message)) {
-		RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref);
-		struct ast_channel_snapshot *snapshot =
-			stasis_message_data(message);
-
-		msg = app_event_create("channel-state-change", snapshot, NULL);
-		if (!msg) {
-			return;
-		}
-		app_send(app, msg);
-	}
-	if (stasis_subscription_final_message(sub, message)) {
-		ao2_cleanup(data);
-	}
-}
-
-/*!
- * \brief In addition to running ao2_cleanup(), this function also removes the
- * object from the app_controls() container.
- */
-static void control_unlink(struct stasis_app_control *control)
-{
-	RAII_VAR(struct ao2_container *, controls, NULL, ao2_cleanup);
-
-	if (!control) {
-		return;
-	}
-
-	controls = app_controls();
-	ao2_unlink_flags(controls, control,
-			 OBJ_POINTER | OBJ_UNLINK | OBJ_NODATA);
-	ao2_cleanup(control);
-}
-
-/*! /brief Stasis dialplan application callback */
-static int app_stasis_exec(struct ast_channel *chan, const char *data)
-{
-	RAII_VAR(struct ao2_container *, apps, apps_registry(), ao2_cleanup);
-	RAII_VAR(struct app *, app, NULL, ao2_cleanup);
-	RAII_VAR(struct stasis_app_control *, control, NULL, control_unlink);
-	RAII_VAR(struct stasis_subscription *, subscription, NULL,
-		 stasis_unsubscribe);
-	int res = 0;
 	char *parse = NULL;
-	int hungup = 0;
 
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(app_name);
@@ -426,164 +85,21 @@
 		return -1;
 	}
 
-	app = ao2_find(apps, args.app_name, OBJ_KEY);
-	if (!app) {
-		ast_log(LOG_ERROR,
-			"Stasis app '%s' not registered\n", args.app_name);
-		return -1;
-	}
-
-	{
-		RAII_VAR(struct ao2_container *, controls, NULL, ao2_cleanup);
-
-		controls = app_controls();
-		control = control_create(ast_channel_uniqueid(chan));
-		if (!control) {
-			ast_log(LOG_ERROR, "Allocated failed\n");
-			return -1;
-		}
-		ao2_link(controls, control);
-	}
-
-	subscription =
-		stasis_subscribe(ast_channel_topic(chan), sub_handler, app);
-	if (subscription == NULL) {
-		ast_log(LOG_ERROR, "Error subscribing app %s to channel %s\n",
-			args.app_name, ast_channel_name(chan));
-		return -1;
-	}
-	ao2_ref(app, +1); /* subscription now has a reference */
-
-	res = send_start_msg(app, chan, args.argc - 1, args.app_argv);
-	if (res != 0) {
-		ast_log(LOG_ERROR,
-			"Error sending start message to %s\n", args.app_name);
-		return res;
-	}
-
-	while (!hungup && !control_continue_test_and_reset(control) && ast_waitfor(chan, -1) > -1) {
-		RAII_VAR(struct ast_frame *, f, ast_read(chan), ast_frame_dtor);
-		if (!f) {
-			ast_debug(3, "%s: No more frames. Must be done, I guess.\n",
-				  ast_channel_uniqueid(chan));
-			break;
-		}
-
-		switch (f->frametype) {
-		case AST_FRAME_CONTROL:
-			if (f->subclass.integer == AST_CONTROL_HANGUP) {
-				ast_debug(3, "%s: Received hangup\n",
-					  ast_channel_uniqueid(chan));
-				hungup = 1;
-			}
-			break;
-		default:
-			/* Not handled; discard */
-			break;
-		}
-	}
-
-	res = send_end_msg(app, chan);
-	if (res != 0) {
-		ast_log(LOG_ERROR,
-			"Error sending end message to %s\n", args.app_name);
-		return res;
-	}
-
-	return res;
-}
-
-int stasis_app_send(const char *app_name, struct ast_json *message)
-{
-	RAII_VAR(struct ao2_container *, apps, apps_registry(), ao2_cleanup);
-	RAII_VAR(struct app *, app, NULL, ao2_cleanup);
-
-	app = ao2_find(apps, app_name, OBJ_KEY);
-
-	if (!app) {
-		/* XXX We can do a better job handling late binding, queueing up
-		 * the call for a few seconds to wait for the app to register.
-		 */
-		ast_log(LOG_WARNING,
-			"Stasis app '%s' not registered\n", app_name);
-		return -1;
-	}
-
-	app_send(app, message);
-	return 0;
-}
-
-int stasis_app_register(const char *app_name, stasis_app_cb handler, void *data)
-{
-	RAII_VAR(struct ao2_container *, apps, apps_registry(), ao2_cleanup);
-	RAII_VAR(struct app *, app, NULL, ao2_cleanup);
-
-	SCOPED_LOCK(apps_lock, apps, ao2_lock, ao2_unlock);
-
-	app = ao2_find(apps, app_name, OBJ_KEY | OBJ_NOLOCK);
-
-	if (app) {
-		RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref);
-		SCOPED_LOCK(app_lock, app, ao2_lock, ao2_unlock);
-
-		msg = app_event_create("application-replaced", NULL, NULL);
-		app->handler(app->data, app_name, msg);
-
-		app->handler = handler;
-		ao2_cleanup(app->data);
-		ao2_ref(data, +1);
-		app->data = data;
-	} else {
-		app = app_create(app_name, handler, data);
-		if (app) {
-			ao2_link_flags(apps, app, OBJ_NOLOCK);
-		} else {
-			return -1;
-		}
-	}
-
-	return 0;
-}
-
-void stasis_app_unregister(const char *app_name)
-{
-	RAII_VAR(struct ao2_container *, apps, NULL, ao2_cleanup);
-
-	if (app_name) {
-		apps = apps_registry();
-		ao2_cleanup(ao2_find(apps, app_name, OBJ_KEY | OBJ_UNLINK));
-	}
+	return stasis_app_exec(
+		chan, args.app_name, args.argc - 1, args.app_argv);
 }
 
 static int load_module(void)
 {
 	int r = 0;
 
-	__apps_registry =
-		ao2_container_alloc(APPS_NUM_BUCKETS, app_hash, app_compare);
-	if (__apps_registry == NULL) {
-		return AST_MODULE_LOAD_FAILURE;
-	}
-
-	__app_controls = ao2_container_alloc(CONTROLS_NUM_BUCKETS,
-					     control_hash, control_compare);
-	if (__app_controls == NULL) {
-		return AST_MODULE_LOAD_FAILURE;
-	}
-
-	r |= ast_register_application_xml(stasis, app_stasis_exec);
+	r |= ast_register_application_xml(stasis, app_exec);
 	return r;
 }
 
 static int unload_module(void)
 {
 	int r = 0;
-
-	ao2_cleanup(__apps_registry);
-	__apps_registry = NULL;
-
-	ao2_cleanup(__app_controls);
-	__app_controls = NULL;
 
 	r |= ast_unregister_application(stasis);
 	return r;

Modified: team/qwell/pimp_my_dtmf/channels/chan_gulp.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/pimp_my_dtmf/channels/chan_gulp.c?view=diff&rev=385888&r1=385887&r2=385888
==============================================================================
--- team/qwell/pimp_my_dtmf/channels/chan_gulp.c (original)
+++ team/qwell/pimp_my_dtmf/channels/chan_gulp.c Tue Apr 16 13:14:43 2013
@@ -694,10 +694,7 @@
 		ast_log(LOG_ERROR, "Could not add body to text video update INFO request\n");
 		return -1;
 	}
-	if (ast_sip_send_request(tdata, session->inv_session->dlg, session->endpoint)) {
-		ast_log(LOG_ERROR, "Could not send text video update INFO request\n");
-		return -1;
-	}
+	ast_sip_session_send_request(session, tdata);
 
 	return 0;
 }

Modified: team/qwell/pimp_my_dtmf/funcs/func_presencestate.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/pimp_my_dtmf/funcs/func_presencestate.c?view=diff&rev=385888&r1=385887&r2=385888
==============================================================================
--- team/qwell/pimp_my_dtmf/funcs/func_presencestate.c (original)
+++ team/qwell/pimp_my_dtmf/funcs/func_presencestate.c Tue Apr 16 13:14:43 2013
@@ -645,21 +645,20 @@
 }
 
 struct test_cb_data {
-	enum ast_presence_state presence;
-	const char *provider;
-	const char *subtype;
-	const char *message;
+	struct ast_presence_state_message *presence_state;
 	/* That's right. I'm using a semaphore */
 	sem_t sem;
 };
 
-static void test_cb(const struct ast_event *event, void *userdata)
+static void test_cb(void *userdata, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *msg)
 {
 	struct test_cb_data *cb_data = userdata;
-	cb_data->presence = ast_event_get_ie_uint(event, AST_EVENT_IE_PRESENCE_STATE);
-	cb_data->provider = ast_strdup(ast_event_get_ie_str(event, AST_EVENT_IE_PRESENCE_PROVIDER));
-	cb_data->subtype = ast_strdup(ast_event_get_ie_str(event, AST_EVENT_IE_PRESENCE_SUBTYPE));
-	cb_data->message = ast_strdup(ast_event_get_ie_str(event, AST_EVENT_IE_PRESENCE_MESSAGE));
+	if (stasis_message_type(msg) != ast_presence_state_message_type()) {
+		return;
+	}
+	cb_data->presence_state = stasis_message_data(msg);
+	ao2_ref(cb_data->presence_state, +1);
+
 	sem_post(&cb_data->sem);
 }
 
@@ -670,7 +669,7 @@
  */
 AST_TEST_DEFINE(test_presence_state_change)
 {
-	struct ast_event_sub *test_sub;
+	struct stasis_subscription *test_sub;
 	struct test_cb_data *cb_data;
 
 	switch (cmd) {
@@ -690,8 +689,7 @@
 		return AST_TEST_FAIL;
 	}
 
-	if (!(test_sub = ast_event_subscribe(AST_EVENT_PRESENCE_STATE,
-			test_cb, "Test presence state callbacks", cb_data, AST_EVENT_IE_END))) {
+	if (!(test_sub = stasis_subscribe(ast_presence_state_topic_all(), test_cb, cb_data))) {
 		return AST_TEST_FAIL;
 	}
 
@@ -701,16 +699,16 @@
 
 	presence_write(NULL, "PRESENCESTATE", "CustomPresence:TestPresenceStateChange", "away,down the hall,Quarterly financial meeting");
 	sem_wait(&cb_data->sem);
-	if (cb_data->presence != AST_PRESENCE_AWAY ||
-			strcmp(cb_data->provider, "CustomPresence:TestPresenceStateChange") ||
-			strcmp(cb_data->subtype, "down the hall") ||
-			strcmp(cb_data->message, "Quarterly financial meeting")) {
+	if (cb_data->presence_state->state != AST_PRESENCE_AWAY ||
+			strcmp(cb_data->presence_state->provider, "CustomPresence:TestPresenceStateChange") ||
+			strcmp(cb_data->presence_state->subtype, "down the hall") ||
+			strcmp(cb_data->presence_state->message, "Quarterly financial meeting")) {
 		return AST_TEST_FAIL;
 	}
 
-	ast_free((char *)cb_data->provider);
-	ast_free((char *)cb_data->subtype);
-	ast_free((char *)cb_data->message);
+	test_sub = stasis_unsubscribe(test_sub);
+
+	ao2_cleanup(cb_data->presence_state);
 	ast_free((char *)cb_data);
 
 	ast_db_del("CustomPresence", "TestPresenceStateChange");

Modified: team/qwell/pimp_my_dtmf/include/asterisk/cli.h
URL: http://svnview.digium.com/svn/asterisk/team/qwell/pimp_my_dtmf/include/asterisk/cli.h?view=diff&rev=385888&r1=385887&r2=385888
==============================================================================
--- team/qwell/pimp_my_dtmf/include/asterisk/cli.h (original)
+++ team/qwell/pimp_my_dtmf/include/asterisk/cli.h Tue Apr 16 13:14:43 2013
@@ -28,6 +28,7 @@
 #endif
 
 #include "asterisk/linkedlists.h"
+#include "asterisk/strings.h"
 
 void ast_cli(int fd, const char *fmt, ...)
 	__attribute__((format(printf, 2, 3)));
@@ -57,12 +58,17 @@
  */
 #define ESS(x) ((x) == 1 ? "" : "s")
 
-/*! \brief return Yes or No depending on the argument.
- * This is used in many places in CLI command, having a function to generate
- * this helps maintaining a consistent output (and possibly emitting the
- * output in other languages, at some point).
- */
-#define AST_CLI_YESNO(x) (x) ? "Yes" : "No"
+/*!
+ * \brief Return Yes or No depending on the argument.
+ *
+ * Note that this should probably still be used for CLI commands instead of
+ * AST_YESNO(), in the off chance we someday want to translate the CLI.
+ *
+ * \param x Boolean value
+ * \return "Yes" if x is true (non-zero)
+ * \return "No" if x is false (zero)
+ */
+#define AST_CLI_YESNO(x) AST_YESNO(x)
 
 /*! \brief return On or Off depending on the argument.
  * This is used in many places in CLI command, having a function to generate

Modified: team/qwell/pimp_my_dtmf/include/asterisk/devicestate.h
URL: http://svnview.digium.com/svn/asterisk/team/qwell/pimp_my_dtmf/include/asterisk/devicestate.h?view=diff&rev=385888&r1=385887&r2=385888
==============================================================================
--- team/qwell/pimp_my_dtmf/include/asterisk/devicestate.h (original)
+++ team/qwell/pimp_my_dtmf/include/asterisk/devicestate.h Tue Apr 16 13:14:43 2013
@@ -38,6 +38,7 @@
 #define _ASTERISK_DEVICESTATE_H
 
 #include "asterisk/channelstate.h"
+#include "asterisk/utils.h"
 
 #if defined(__cplusplus) || defined(c_plusplus)
 extern "C" {
@@ -270,19 +271,87 @@
 };
 
 /*!
- * \brief Enable distributed device state processing.
- *
- * \details
- * By default, Asterisk assumes that device state change events will only be
- * originating from one instance.  If a module gets loaded and configured such
- * that multiple instances of Asterisk will be sharing device state, this
- * function should be called to enable distributed device state processing.
- * It is off by default to save on unnecessary processing.
- *
- * \retval 0 success
- * \retval -1 failure
- */
-int ast_enable_distributed_devstate(void);
+ * \brief The structure that contains device state
+ * \since 12
+ */
+struct ast_device_state_message {
+	AST_DECLARE_STRING_FIELDS(
+		AST_STRING_FIELD(cache_id);	/*!< A unique ID used for hashing */
+		AST_STRING_FIELD(device);	/*!< The name of the device */
+	);
+	enum ast_device_state state;		/*!< The state of the device */
+	struct ast_eid *eid;			/*!< The EID of the server where this message originated, NULL EID means aggregate state */
+	enum ast_devstate_cache cachable;	/*!< Flag designating the cachability of this device state */
+};
+
+/*!
+ * \brief Get the Stasis topic for device state messages
+ * \retval The topic for device state messages
+ * \retval NULL if it has not been allocated
+ * \since 12
+ */
+struct stasis_topic *ast_device_state_topic_all(void);
+
+/*!
+ * \brief Get the Stasis topic for device state messages for a specific device
+ * \param uniqueid The device for which to get the topic
+ * \retval The topic structure for MWI messages for a given device
+ * \retval NULL if it failed to be found or allocated
+ * \since 12
+ */
+struct stasis_topic *ast_device_state_topic(const char *device);
+
+/*!
+ * \brief Get the Stasis caching topic for device state messages
+ * \retval The caching topic for device state messages
+ * \retval NULL if it has not been allocated
+ * \since 12
+ */

[... 2705 lines stripped ...]



More information about the asterisk-commits mailing list