[asterisk-commits] kmoore: branch kmoore/channel-state-caching r380969 - in /team/kmoore/channel...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Feb 6 10:59:49 CST 2013
Author: kmoore
Date: Wed Feb 6 10:59:45 2013
New Revision: 380969
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=380969
Log:
Make channel state distribution and caching more stasis-like
Add new files stasis.c and stasis.h that will house stasis-related
code. Convert AST_EVENT_CHANNEL_STATE to AST_EVENT_STASIS and make
the cache more Stasis-friendly with a type and a generic key.
Added:
team/kmoore/channel-state-caching/include/asterisk/stasis.h (with props)
team/kmoore/channel-state-caching/main/stasis.c (with props)
Modified:
team/kmoore/channel-state-caching/include/asterisk/event.h
team/kmoore/channel-state-caching/include/asterisk/event_defs.h
team/kmoore/channel-state-caching/main/channel.c
team/kmoore/channel-state-caching/main/event.c
team/kmoore/channel-state-caching/main/manager.c
Modified: team/kmoore/channel-state-caching/include/asterisk/event.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/channel-state-caching/include/asterisk/event.h?view=diff&rev=380969&r1=380968&r2=380969
==============================================================================
--- team/kmoore/channel-state-caching/include/asterisk/event.h (original)
+++ team/kmoore/channel-state-caching/include/asterisk/event.h Wed Feb 6 10:59:45 2013
@@ -950,16 +950,6 @@
*/
size_t ast_event_minimum_length(void);
-/*!
- * \brief Send a channel state-related event.
- *
- * \param chan the channel about which to send information
- *
- * \return zero on success
- * \return non-zero on failure
- */
-int ast_event_queue_channel_state(struct ast_channel *chan);
-
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
Modified: team/kmoore/channel-state-caching/include/asterisk/event_defs.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/channel-state-caching/include/asterisk/event_defs.h?view=diff&rev=380969&r1=380968&r2=380969
==============================================================================
--- team/kmoore/channel-state-caching/include/asterisk/event_defs.h (original)
+++ team/kmoore/channel-state-caching/include/asterisk/event_defs.h Wed Feb 6 10:59:45 2013
@@ -61,7 +61,7 @@
/*! Send out a ping for debugging distributed events */
AST_EVENT_PING = 0x0c,
/*! A channel state snapshot */
- AST_EVENT_CHANNEL_STATE = 0x0d,
+ AST_EVENT_STASIS = 0x0d,
/*! Number of event types. This should be the last event type + 1 */
AST_EVENT_TOTAL = 0x0e,
};
@@ -308,14 +308,28 @@
AST_EVENT_IE_CACHABLE = 0x003d,
/*!
- * \brief Channel state summary
- * Used by: AST_EVENT_CHANNEL_STATE
- * Payload type: RAW
- */
- AST_EVENT_IE_CHANNEL_STATE = 0x003e,
+ * \brief Stasis state message
+ * Used by: AST_EVENT_STASIS
+ * Payload type: RAW_LOCAL
+ */
+ AST_EVENT_IE_STASIS_MESSAGE = 0x003e,
+
+ /*!
+ * \brief Stasis message type
+ * Used by: AST_EVENT_STASIS
+ * Payload type: UINT
+ */
+ AST_EVENT_IE_STASIS_MESSAGE_TYPE = 0x003f,
+
+ /*!
+ * \brief Stasis message key
+ * Used by: AST_EVENT_STASIS
+ * Payload type: UINT
+ */
+ AST_EVENT_IE_STASIS_MESSAGE_KEY = 0x0040,
/*! \brief Must be the last IE value +1 */
- AST_EVENT_IE_TOTAL = 0x003f,
+ AST_EVENT_IE_TOTAL = 0x0041,
};
/*!
Added: team/kmoore/channel-state-caching/include/asterisk/stasis.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/channel-state-caching/include/asterisk/stasis.h?view=auto&rev=380969
==============================================================================
--- team/kmoore/channel-state-caching/include/asterisk/stasis.h (added)
+++ team/kmoore/channel-state-caching/include/asterisk/stasis.h Wed Feb 6 10:59:45 2013
@@ -1,0 +1,51 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * Kinsey Moore <kmoore at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*!
+ * \file
+ * \author Kinsey Moore <kmoore at digium.com>
+ * \brief Stasis Core API
+ */
+
+#ifndef AST_STASIS_H
+#define AST_STASIS_H
+
+#include "asterisk/channel.h"
+
+/*!
+ * \brief Stasis message types
+ */
+enum ast_stasis_message_type {
+ AST_STASIS_TYPE_CHANNEL,
+ AST_STASIS_TYPE_BRIDGE,
+ AST_STASIS_TYPE_MAILBOX,
+ AST_STASIS_TYPE_DEVICE,
+ AST_STASIS_TYPE_PRESENCE,
+};
+
+/*!
+ * \brief Send a channel state-related Stasis event.
+ *
+ * \param chan the channel about which to send information
+ *
+ * \return zero on success
+ * \return non-zero on failure
+ */
+int ast_stasis_queue_channel_state(struct ast_channel *chan);
+
+#endif /* AST_STASIS_H */
Propchange: team/kmoore/channel-state-caching/include/asterisk/stasis.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/kmoore/channel-state-caching/include/asterisk/stasis.h
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/kmoore/channel-state-caching/include/asterisk/stasis.h
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: team/kmoore/channel-state-caching/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/channel-state-caching/main/channel.c?view=diff&rev=380969&r1=380968&r2=380969
==============================================================================
--- team/kmoore/channel-state-caching/main/channel.c (original)
+++ team/kmoore/channel-state-caching/main/channel.c Wed Feb 6 10:59:45 2013
@@ -74,6 +74,7 @@
#include "asterisk/channel_internal.h"
#include "asterisk/features.h"
#include "asterisk/test.h"
+#include "asterisk/stasis.h"
/*** DOCUMENTATION
***/
@@ -1145,7 +1146,7 @@
* a lot of data into this func to do it here!
*/
if (ast_get_channel_tech(tech) || (tech2 && ast_get_channel_tech(tech2))) {
- ast_event_queue_channel_state(tmp);
+ ast_stasis_queue_channel_state(tmp);
}
ast_channel_internal_finalize(tmp);
@@ -2867,7 +2868,7 @@
ast_cc_offer(chan);
- ast_event_queue_channel_state(chan);
+ ast_stasis_queue_channel_state(chan);
if (ast_channel_cdr(chan) && !ast_test_flag(ast_channel_cdr(chan), AST_CDR_FLAG_BRIDGED) &&
!ast_test_flag(ast_channel_cdr(chan), AST_CDR_FLAG_POST_DISABLED) &&
@@ -7379,7 +7380,7 @@
* we override what they are saying the state is and things go amuck. */
ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, (ast_test_flag(ast_channel_flags(chan), AST_FLAG_DISABLE_DEVSTATE_CACHE) ? AST_DEVSTATE_NOT_CACHABLE : AST_DEVSTATE_CACHABLE), name);
- ast_event_queue_channel_state(chan);
+ ast_stasis_queue_channel_state(chan);
return 0;
}
Modified: team/kmoore/channel-state-caching/main/event.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/channel-state-caching/main/event.c?view=diff&rev=380969&r1=380968&r2=380969
==============================================================================
--- team/kmoore/channel-state-caching/main/event.c (original)
+++ team/kmoore/channel-state-caching/main/event.c Wed Feb 6 10:59:45 2013
@@ -145,7 +145,7 @@
static int ast_event_hash_devstate(const void *obj, const int flags);
static int ast_event_hash_devstate_change(const void *obj, const int flags);
static int ast_event_hash_presence_state_change(const void *obj, const int flags);
-static int ast_event_hash_channel_state(const void *obj, const int flags);
+static int ast_event_hash_stasis_message(const void *obj, const int flags);
#ifdef LOW_MEMORY
#define NUM_CACHE_BUCKETS 17
@@ -201,9 +201,9 @@
.hash_fn = ast_event_hash_presence_state_change,
.cache_args = { AST_EVENT_IE_PRESENCE_STATE, },
},
- [AST_EVENT_CHANNEL_STATE] = {
- .hash_fn = ast_event_hash_channel_state,
- .cache_args = { AST_EVENT_IE_CEL_CHANNAME},
+ [AST_EVENT_STASIS] = {
+ .hash_fn = ast_event_hash_stasis_message,
+ .cache_args = { AST_EVENT_IE_STASIS_MESSAGE_KEY, AST_EVENT_IE_STASIS_MESSAGE_TYPE },
},
};
@@ -229,7 +229,7 @@
[AST_EVENT_CEL] = "CEL",
[AST_EVENT_SECURITY] = "Security",
[AST_EVENT_NETWORK_CHANGE] = "NetworkChange",
- [AST_EVENT_CHANNEL_STATE] = "ChannelState",
+ [AST_EVENT_STASIS] = "Stasis",
};
/*!
@@ -295,7 +295,9 @@
[AST_EVENT_IE_USING_PASSWORD] = { AST_EVENT_IE_PLTYPE_UINT, "UsingPassword" },
[AST_EVENT_IE_ATTEMPTED_TRANSPORT] = { AST_EVENT_IE_PLTYPE_STR, "AttemptedTransport" },
[AST_EVENT_IE_CACHABLE] = { AST_EVENT_IE_PLTYPE_UINT, "Cachable" },
- [AST_EVENT_IE_CHANNEL_STATE] = { AST_EVENT_IE_PLTYPE_RAW_LOCAL, "ChannelState" },
+ [AST_EVENT_IE_STASIS_MESSAGE] = { AST_EVENT_IE_PLTYPE_RAW_LOCAL, "StasisMessage" },
+ [AST_EVENT_IE_STASIS_MESSAGE_KEY] = { AST_EVENT_IE_PLTYPE_STR, "StasisMessageKey" },
+ [AST_EVENT_IE_STASIS_MESSAGE_TYPE] = { AST_EVENT_IE_PLTYPE_UINT, "StasisMessageType" },
};
const char *ast_event_get_type_name(const struct ast_event *event)
@@ -1975,18 +1977,20 @@
/*!
* \internal
- * \brief Hash function for AST_EVENT_CHANNEL_STATE
+ * \brief Hash function for AST_EVENT_STASIS
*
* \param[in] obj an ast_event
* \param[in] flags unused
*
* \return hash value
*/
-static int ast_event_hash_channel_state(const void *obj, const int flags)
+static int ast_event_hash_stasis_message(const void *obj, const int flags)
{
const struct ast_event *event = obj;
-
- return ast_str_hash(ast_event_get_ie_str(event, AST_EVENT_IE_CEL_CHANNAME));
+ const char *key = ast_event_get_ie_str(event, AST_EVENT_IE_STASIS_MESSAGE_KEY);
+ unsigned int type = ast_event_get_ie_uint(event, AST_EVENT_IE_STASIS_MESSAGE_TYPE);
+
+ return ast_str_hash_add(key, type);
}
/*!
@@ -2251,30 +2255,3 @@
{
return sizeof(struct ast_event);
}
-
-int ast_event_queue_channel_state(struct ast_channel *chan)
-{
- struct ast_channel_snapshot *snapshot = ast_channel_snapshot_create(chan);
- struct ast_event *newchannel_event;
- if (!snapshot) {
- return -1;
- }
- newchannel_event = ast_event_new(AST_EVENT_CHANNEL_STATE,
- AST_EVENT_IE_CEL_CHANNAME, AST_EVENT_IE_PLTYPE_STR, ast_channel_name(chan),
- AST_EVENT_IE_CHANNEL_STATE, AST_EVENT_IE_PLTYPE_RAW_LOCAL, snapshot, sizeof(*snapshot),
- ast_channel_snapshot_copy, ast_channel_snapshot_cmp, ast_channel_snapshot_destroy,
- AST_EVENT_IE_END);
-
- ast_channel_snapshot_destroy(snapshot, sizeof(*snapshot));
- ast_free(snapshot);
- if (!newchannel_event) {
- return -1;
- }
-
- if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_DISABLE_DEVSTATE_CACHE)) {
- ast_event_queue(newchannel_event);
- } else {
- ast_event_queue_and_cache(newchannel_event);
- }
- return 0;
-}
Modified: team/kmoore/channel-state-caching/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/channel-state-caching/main/manager.c?view=diff&rev=380969&r1=380968&r2=380969
==============================================================================
--- team/kmoore/channel-state-caching/main/manager.c (original)
+++ team/kmoore/channel-state-caching/main/manager.c Wed Feb 6 10:59:45 2013
@@ -91,6 +91,7 @@
#include "asterisk/aoc.h"
#include "asterisk/stringfields.h"
#include "asterisk/presencestate.h"
+#include "asterisk/stasis.h"
/*** DOCUMENTATION
<manager name="Ping" language="en_US">
@@ -7480,7 +7481,7 @@
static void channel_state_cb(const struct ast_event *event, void *userdata)
{
- const struct ast_channel_snapshot *new_snapshot = ast_event_get_ie_raw_local(event, AST_EVENT_IE_CHANNEL_STATE);
+ const struct ast_channel_snapshot *new_snapshot = ast_event_get_ie_raw_local(event, AST_EVENT_IE_STASIS_MESSAGE);
struct ast_channel_snapshot *old_snapshot = NULL, *ao2_snapshot = NULL;
int is_hungup = ast_test_flag(&new_snapshot->flags, AST_FLAG_ZOMBIE) ? 1 : 0;
int find_flags = OBJ_KEY;
@@ -7522,8 +7523,9 @@
if (old_snapshot && is_hungup) {
manager_hangup(new_snapshot);
/* drop the cache for this channel */
- ast_event_drop_cached(AST_EVENT_CHANNEL_STATE,
- AST_EVENT_IE_CEL_CHANNAME, AST_EVENT_IE_PLTYPE_STR, new_snapshot->name,
+ ast_event_drop_cached(AST_EVENT_STASIS,
+ AST_EVENT_IE_STASIS_MESSAGE_KEY, AST_EVENT_IE_PLTYPE_STR, new_snapshot->name,
+ AST_EVENT_IE_STASIS_MESSAGE_TYPE, AST_EVENT_IE_PLTYPE_UINT, AST_STASIS_TYPE_CHANNEL,
AST_EVENT_IE_END);
}
@@ -7670,9 +7672,10 @@
}
if (!channel_state_sub) {
- channel_state_sub = ast_event_subscribe(AST_EVENT_CHANNEL_STATE,
- channel_state_cb, "Manager Channel State Subscription",
- NULL, AST_EVENT_IE_END);
+ channel_state_sub = ast_event_subscribe(AST_EVENT_STASIS,
+ channel_state_cb, "Manager Channel State Subscription", NULL,
+ AST_EVENT_IE_STASIS_MESSAGE_TYPE, AST_EVENT_IE_PLTYPE_UINT, AST_STASIS_TYPE_CHANNEL,
+ AST_EVENT_IE_END);
if (!channel_state_sub) {
ast_log(LOG_NOTICE, "Unable to create channel state subscription.\n");
return -1;
Added: team/kmoore/channel-state-caching/main/stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/channel-state-caching/main/stasis.c?view=auto&rev=380969
==============================================================================
--- team/kmoore/channel-state-caching/main/stasis.c (added)
+++ team/kmoore/channel-state-caching/main/stasis.c Wed Feb 6 10:59:45 2013
@@ -1,0 +1,69 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * Kinsey Moore <kmoore at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Stasis Core Implementation
+ *
+ * \author Kinsey Moore <kmoore at digium.com>
+ */
+
+/*** MODULEINFO
+ <support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/_private.h"
+
+#include "asterisk/event.h"
+#include "asterisk/utils.h"
+#include "asterisk/unaligned.h"
+#include "asterisk/utils.h"
+#include "asterisk/channel.h"
+#include "asterisk/stasis.h"
+
+int ast_stasis_queue_channel_state(struct ast_channel *chan)
+{
+ struct ast_channel_snapshot *snapshot = ast_channel_snapshot_create(chan);
+ struct ast_event *newchannel_event;
+ if (!snapshot) {
+ return -1;
+ }
+ newchannel_event = ast_event_new(AST_EVENT_STASIS,
+ AST_EVENT_IE_STASIS_MESSAGE_KEY, AST_EVENT_IE_PLTYPE_STR, ast_channel_name(chan),
+ AST_EVENT_IE_STASIS_MESSAGE_TYPE, AST_EVENT_IE_PLTYPE_UINT, AST_STASIS_TYPE_CHANNEL,
+ AST_EVENT_IE_STASIS_MESSAGE, AST_EVENT_IE_PLTYPE_RAW_LOCAL, snapshot, sizeof(*snapshot),
+ ast_channel_snapshot_copy, ast_channel_snapshot_cmp, ast_channel_snapshot_destroy,
+ AST_EVENT_IE_END);
+
+ ast_channel_snapshot_destroy(snapshot, sizeof(*snapshot));
+ ast_free(snapshot);
+ if (!newchannel_event) {
+ return -1;
+ }
+
+ if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_DISABLE_DEVSTATE_CACHE)) {
+ ast_event_queue(newchannel_event);
+ } else {
+ ast_event_queue_and_cache(newchannel_event);
+ }
+ return 0;
+}
Propchange: team/kmoore/channel-state-caching/main/stasis.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/kmoore/channel-state-caching/main/stasis.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/kmoore/channel-state-caching/main/stasis.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the asterisk-commits
mailing list