[asterisk-commits] mjordan: branch mjordan/12-corosync r413035 - in /team/mjordan/12-corosync: i...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sun Apr 27 00:26:29 CDT 2014
Author: mjordan
Date: Sun Apr 27 00:26:20 2014
New Revision: 413035
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=413035
Log:
Clean up documentation, obvious problems on review board
Modified:
team/mjordan/12-corosync/include/asterisk/event.h
team/mjordan/12-corosync/include/asterisk/event_defs.h
team/mjordan/12-corosync/include/asterisk/stasis.h
team/mjordan/12-corosync/main/stasis_message_router.c
team/mjordan/12-corosync/res/res_corosync.c
Modified: team/mjordan/12-corosync/include/asterisk/event.h
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-corosync/include/asterisk/event.h?view=diff&rev=413035&r1=413034&r2=413035
==============================================================================
--- team/mjordan/12-corosync/include/asterisk/event.h (original)
+++ team/mjordan/12-corosync/include/asterisk/event.h Sun Apr 27 00:26:20 2014
@@ -25,33 +25,27 @@
/*!
* \page AstGenericEvents Generic event system
*
- * The purpose of this API is to provide a generic way to share events between
- * Asterisk modules. Code can generate events, and other code can subscribe to
- * them.
+ * Prior to the creation of \ref stasis, the purpose of this API was to provide
+ * a generic way to share events between Asterisk modules. Once there was a need
+ * to disseminate data whose definition was provided by the producers/consumers,
+ * it was no longer possible to use the binary representation in the generic
+ * event system.
+ *
+ * That aside, the generic event system is still useful and used by several
+ * modules in Asterisk.
+ * - CEL uses the \ref ast_event representation to pass information to registered
+ * backends.
+ * - The \file res_corosync module publishes \ref ast_event representations of
+ * information to other Asterisk instances in a cluster.
+ * - Security event represent their event types and data using this system.
+ * - Theoretically, any \ref stasis message can use this system to pass
+ * information around in a binary format.
*
* Events have an associated event type, as well as information elements. The
* information elements are the meta data that go along with each event. For
* example, in the case of message waiting indication, the event type is MWI,
* and each MWI event contains at least three information elements: the
* mailbox, the number of new messages, and the number of old messages.
- *
- * Subscriptions to events consist of an event type and information elements,
- * as well. Subscriptions can be to all events, or a certain subset of events.
- * If an event type is provided, only events of that type will be sent to this
- * subscriber. Furthermore, if information elements are supplied with the
- * subscription, only events that contain the specified information elements
- * with specified values will be sent to the subscriber. For example, when a
- * SIP phone subscribes to MWI for mailbox 1234, then chan_sip can subscribe
- * to internal Asterisk MWI events with the MAILBOX information element with
- * a value of "1234".
- *
- * Another key feature of this event system is the ability to cache events.
- * It is useful for some types of events to be able to remember the last known
- * value. These are usually events that indicate some kind of state change.
- * In the example of MWI, app_voicemail can instruct the event core to cache
- * these events based on the mailbox. So, the last known MWI state of each
- * mailbox will be cached, and other modules can retrieve this information
- * on demand without having to poll the mailbox directly.
*/
#ifndef AST_EVENT_H
@@ -109,9 +103,6 @@
*
* \return Nothing
*
- * \note Events that have been queued should *not* be destroyed by the code that
- * created the event. It will be automatically destroyed after being
- * dispatched to the appropriate subscribers.
*/
void ast_event_destroy(struct ast_event *event);
Modified: team/mjordan/12-corosync/include/asterisk/event_defs.h
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-corosync/include/asterisk/event_defs.h?view=diff&rev=413035&r1=413034&r2=413035
==============================================================================
--- team/mjordan/12-corosync/include/asterisk/event_defs.h (original)
+++ team/mjordan/12-corosync/include/asterisk/event_defs.h Sun Apr 27 00:26:20 2014
@@ -30,7 +30,7 @@
* event should never have a payload of 0. */
AST_EVENT_ALL = 0x00,
/*! This event type is reserved for use by third-party modules to create
- * custom events without having to modify this file.
+ * custom events without having to modify this file.
* \note There are no "custom" IE types, because IEs only have to be
* unique to the event itself, not necessarily across all events. */
AST_EVENT_CUSTOM = 0x01,
@@ -67,32 +67,32 @@
/*! Used to terminate the arguments to event functions */
AST_EVENT_IE_END = -1,
- /*!
+ /*!
* \brief Number of new messages
- * Used by: AST_EVENT_MWI
+ * Used by: AST_EVENT_MWI
* Payload type: UINT
*/
AST_EVENT_IE_NEWMSGS = 0x0001,
- /*!
+ /*!
* \brief Number of
- * Used by: AST_EVENT_MWI
+ * Used by: AST_EVENT_MWI
* Payload type: UINT
*/
AST_EVENT_IE_OLDMSGS = 0x0002,
- /*!
+ /*!
* \brief Mailbox name \verbatim (mailbox[@context]) \endverbatim
* Used by: AST_EVENT_MWI
* Payload type: STR
*/
AST_EVENT_IE_MAILBOX = 0x0003,
- /*!
+ /*!
* \brief Unique ID
* Used by: AST_EVENT_SUB, AST_EVENT_UNSUB
* Payload type: UINT
*/
AST_EVENT_IE_UNIQUEID = 0x0004,
- /*!
- * \brief Event type
+ /*!
+ * \brief Event type
* Used by: AST_EVENT_SUB, AST_EVENT_UNSUB
* Payload type: UINT
*/
@@ -117,139 +117,139 @@
* this IE is a part of.
*/
AST_EVENT_IE_STATE = 0x0008,
- /*!
- * \brief Context IE
- * Used by AST_EVENT_MWI
- * Payload type: str
- */
+ /*!
+ * \brief Context IE
+ * Used by AST_EVENT_MWI
+ * Payload type: str
+ */
AST_EVENT_IE_CONTEXT = 0x0009,
- /*!
+ /*!
* \brief Channel Event Type
* Used by: AST_EVENT_CEL
* Payload type: UINT
*/
AST_EVENT_IE_CEL_EVENT_TYPE = 0x000a,
- /*!
+ /*!
* \brief Channel Event Time (seconds)
* Used by: AST_EVENT_CEL
* Payload type: UINT
*/
AST_EVENT_IE_CEL_EVENT_TIME = 0x000b,
- /*!
+ /*!
* \brief Channel Event Time (micro-seconds)
* Used by: AST_EVENT_CEL
* Payload type: UINT
*/
AST_EVENT_IE_CEL_EVENT_TIME_USEC = 0x000c,
- /*!
+ /*!
* \brief Channel Event User Event Name
* Used by: AST_EVENT_CEL
* Payload type: STR
*/
AST_EVENT_IE_CEL_USEREVENT_NAME = 0x000d,
- /*!
+ /*!
* \brief Channel Event CID name
* Used by: AST_EVENT_CEL
* Payload type: STR
*/
AST_EVENT_IE_CEL_CIDNAME = 0x000e,
- /*!
+ /*!
* \brief Channel Event CID num
* Used by: AST_EVENT_CEL
* Payload type: STR
*/
AST_EVENT_IE_CEL_CIDNUM = 0x000f,
- /*!
+ /*!
* \brief Channel Event extension name
* Used by: AST_EVENT_CEL
* Payload type: STR
*/
AST_EVENT_IE_CEL_EXTEN = 0x0010,
- /*!
+ /*!
* \brief Channel Event context name
* Used by: AST_EVENT_CEL
* Payload type: STR
*/
AST_EVENT_IE_CEL_CONTEXT = 0x0011,
- /*!
+ /*!
* \brief Channel Event channel name
* Used by: AST_EVENT_CEL
* Payload type: STR
*/
AST_EVENT_IE_CEL_CHANNAME = 0x0012,
- /*!
+ /*!
* \brief Channel Event app name
* Used by: AST_EVENT_CEL
* Payload type: STR
*/
AST_EVENT_IE_CEL_APPNAME = 0x0013,
- /*!
+ /*!
* \brief Channel Event app args/data
* Used by: AST_EVENT_CEL
* Payload type: STR
*/
AST_EVENT_IE_CEL_APPDATA = 0x0014,
- /*!
+ /*!
* \brief Channel Event AMA flags
* Used by: AST_EVENT_CEL
* Payload type: UINT
*/
AST_EVENT_IE_CEL_AMAFLAGS = 0x0015,
- /*!
+ /*!
* \brief Channel Event AccountCode
* Used by: AST_EVENT_CEL
* Payload type: STR
*/
AST_EVENT_IE_CEL_ACCTCODE = 0x0016,
- /*!
+ /*!
* \brief Channel Event UniqueID
* Used by: AST_EVENT_CEL
* Payload type: STR
*/
AST_EVENT_IE_CEL_UNIQUEID = 0x0017,
- /*!
+ /*!
* \brief Channel Event Userfield
* Used by: AST_EVENT_CEL
* Payload type: STR
*/
AST_EVENT_IE_CEL_USERFIELD = 0x0018,
- /*!
+ /*!
* \brief Channel Event CID ANI field
* Used by: AST_EVENT_CEL
* Payload type: STR
*/
AST_EVENT_IE_CEL_CIDANI = 0x0019,
- /*!
+ /*!
* \brief Channel Event CID RDNIS field
* Used by: AST_EVENT_CEL
* Payload type: STR
*/
AST_EVENT_IE_CEL_CIDRDNIS = 0x001a,
- /*!
+ /*!
* \brief Channel Event CID dnid
* Used by: AST_EVENT_CEL
* Payload type: STR
*/
AST_EVENT_IE_CEL_CIDDNID = 0x001b,
- /*!
+ /*!
* \brief Channel Event Peer -- for Things involving multiple channels, like BRIDGE
* Used by: AST_EVENT_CEL
* Payload type: STR
*/
AST_EVENT_IE_CEL_PEER = 0x001c,
- /*!
+ /*!
* \brief Channel Event LinkedID
* Used by: AST_EVENT_CEL
* Payload type: STR
*/
AST_EVENT_IE_CEL_LINKEDID = 0x001d,
- /*!
+ /*!
* \brief Channel Event peeraccount
* Used by: AST_EVENT_CEL
* Payload type: STR
*/
AST_EVENT_IE_CEL_PEERACCT = 0x001e,
- /*!
+ /*!
* \brief Channel Event extra data
* Used by: AST_EVENT_CEL
* Payload type: STR
@@ -306,6 +306,9 @@
AST_EVENT_IE_TOTAL = 0x003e,
};
+/*!
+ * \brief Payload types for event information elements
+ */
enum ast_event_ie_pltype {
AST_EVENT_IE_PLTYPE_UNKNOWN = -1,
/*! Just check if it exists, not the value */
Modified: team/mjordan/12-corosync/include/asterisk/stasis.h
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-corosync/include/asterisk/stasis.h?view=diff&rev=413035&r1=413034&r2=413035
==============================================================================
--- team/mjordan/12-corosync/include/asterisk/stasis.h (original)
+++ team/mjordan/12-corosync/include/asterisk/stasis.h Sun Apr 27 00:26:20 2014
@@ -405,6 +405,16 @@
struct ast_manager_event_blob *stasis_message_to_ami(
struct stasis_message *message);
+/*!
+ * \brief Build the \ref AstGenericEvents representation of the message.
+ *
+ * May return \c NULL, to indicate no representation. The returned object should
+ * be disposed of via \ref ast_event_destroy.
+ *
+ * \param message Message to convert to AMI.
+ * \return \c NULL on error.
+ * \return \c NULL if AMI format is not supported.
+ */
struct ast_event *stasis_message_to_event(
struct stasis_message *message);
Modified: team/mjordan/12-corosync/main/stasis_message_router.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-corosync/main/stasis_message_router.c?view=diff&rev=413035&r1=413034&r2=413035
==============================================================================
--- team/mjordan/12-corosync/main/stasis_message_router.c (original)
+++ team/mjordan/12-corosync/main/stasis_message_router.c Sun Apr 27 00:26:20 2014
@@ -175,7 +175,7 @@
if (route == NULL) {
/* Find a regular route */
route = route_table_find(&router->routes, type);
- }
+ }
if (route == NULL && router->default_route.callback) {
/* Maybe the default route, then? */
@@ -282,7 +282,7 @@
if (!message_type) {
/* Cannot route to NULL type. */
return -1;
- }
+ }
ao2_lock(router);
res = route_table_add(&router->routes, message_type, callback, data);
ao2_unlock(router);
Modified: team/mjordan/12-corosync/res/res_corosync.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-corosync/res/res_corosync.c?view=diff&rev=413035&r1=413034&r2=413035
==============================================================================
--- team/mjordan/12-corosync/res/res_corosync.c (original)
+++ team/mjordan/12-corosync/res/res_corosync.c Sun Apr 27 00:26:20 2014
@@ -148,21 +148,21 @@
void (* publish_to_stasis)(struct ast_event *);
} event_types[] = {
[AST_EVENT_MWI] = { .name = "mwi",
- .topic_fn = ast_mwi_topic_all,
- .cache_fn = ast_mwi_state_cache,
- .message_type_fn = ast_mwi_state_type,
- .publish_to_stasis = publish_mwi_to_stasis, },
+ .topic_fn = ast_mwi_topic_all,
+ .cache_fn = ast_mwi_state_cache,
+ .message_type_fn = ast_mwi_state_type,
+ .publish_to_stasis = publish_mwi_to_stasis, },
[AST_EVENT_DEVICE_STATE_CHANGE] = { .name = "device_state",
- .topic_fn = ast_device_state_topic_all,
- .cache_fn = ast_device_state_cache,
- .message_type_fn = ast_device_state_message_type,
- .publish_to_stasis = publish_device_state_to_stasis, },
+ .topic_fn = ast_device_state_topic_all,
+ .cache_fn = ast_device_state_cache,
+ .message_type_fn = ast_device_state_message_type,
+ .publish_to_stasis = publish_device_state_to_stasis, },
[AST_EVENT_PING] = { .name = "ping",
- .publish_default = 1,
- .subscribe_default = 1,
- .topic_fn = corosync_topic,
- .message_type_fn = corosync_ping_message_type,
- .publish_to_stasis = publish_corosync_ping_to_stasis, },
+ .publish_default = 1,
+ .subscribe_default = 1,
+ .topic_fn = corosync_topic,
+ .message_type_fn = corosync_ping_message_type,
+ .publish_to_stasis = publish_corosync_ping_to_stasis, },
};
static struct {
@@ -222,12 +222,11 @@
old_msgs = INT_MAX;
}
- if (ast_publish_mwi_state_full(mailbox,
- context, (int)new_msgs, (int)old_msgs,
- NULL, event_eid)) {
+ if (ast_publish_mwi_state_full(mailbox, context, (int)new_msgs,
+ (int)old_msgs, NULL, event_eid)) {
char eid[16];
ast_eid_to_str(eid, sizeof(eid), event_eid);
- ast_log(AST_LOG_WARNING, "Failed to publish MWI message for %s@%s from %s\n",
+ ast_log(LOG_WARNING, "Failed to publish MWI message for %s@%s from %s\n",
mailbox, context, eid);
}
}
@@ -251,11 +250,10 @@
return;
}
- if (ast_publish_device_state_full(device,
- state, cachable, event_eid)) {
+ if (ast_publish_device_state_full(device, state, cachable, event_eid)) {
char eid[16];
ast_eid_to_str(eid, sizeof(eid), event_eid);
- ast_log(AST_LOG_WARNING, "Failed to publish device state message for %s from %s\n",
+ ast_log(LOG_WARNING, "Failed to publish device state message for %s from %s\n",
device, eid);
}
}
@@ -273,8 +271,6 @@
.cpg_confchg_fn = cpg_confchg_cb,
};
-/*static void ast_event_cb(const struct ast_event *event, void *data);*/
-
#ifdef HAVE_COROSYNC_CFG_STATE_TRACK
static void cfg_state_track_cb(
corosync_cfg_state_notification_buffer_t *notification_buffer,
@@ -315,8 +311,7 @@
ast_rwlock_rdlock(&event_types_lock);
publish_handler = event_types[event_type].publish_to_stasis;
- if (!event_types[event_type].subscribe ||
- !publish_handler) {
+ if (!event_types[event_type].subscribe || !publish_handler) {
/* We are not configured to subscribe to these events or
we have no way to publish it internally. */
ast_rwlock_unlock(&event_types_lock);
@@ -354,10 +349,9 @@
return;
}
- if (ast_eid_cmp(&ast_eid_default,
- ast_event_get_ie_raw(event, AST_EVENT_IE_EID))) {
+ if (ast_eid_cmp(&ast_eid_default, ast_event_get_ie_raw(event, AST_EVENT_IE_EID))) {
/* If the event didn't originate from this server, don't send it back out. */
- ast_free(event);
+ ast_event_destroy(event);
return;
}
@@ -372,6 +366,9 @@
iov.iov_base = (void *)event;
iov.iov_len = ast_event_get_size(event);
+
+ ast_debug(5, "Publishing event %s (%d) to corosync\n",
+ ast_event_get_type_name(event), ast_event_get_type(event));
/* The stasis subscription will only exist if we are configured to publish
* these events, so just send away. */
@@ -750,17 +747,17 @@
}
for (i = 0; i < ARRAY_LEN(event_types); i++) {
- if (event_types[i].publish && !event_types[i].sub && event_types[i].topic_fn) {
+ if (event_types[i].publish && !event_types[i].sub) {
event_types[i].sub = stasis_forward_all(event_types[i].topic_fn(),
corosync_topic());
stasis_message_router_add(stasis_router,
- event_types[i].message_type_fn(),
- stasis_message_cb,
- NULL);
- } else if (!event_types[i].publish && event_types[i].sub && event_types[i].topic_fn) {
+ event_types[i].message_type_fn(),
+ stasis_message_cb,
+ NULL);
+ } else if (!event_types[i].publish && event_types[i].sub) {
event_types[i].sub = stasis_forward_cancel(event_types[i].sub);
stasis_message_router_remove(stasis_router,
- event_types[i].message_type_fn());
+ event_types[i].message_type_fn());
}
}
@@ -809,7 +806,7 @@
if (event_types[i].sub) {
event_types[i].sub = stasis_forward_cancel(event_types[i].sub);
stasis_message_router_remove(stasis_router,
- event_types[i].message_type_fn());
+ event_types[i].message_type_fn());
}
event_types[i].publish = 0;
event_types[i].subscribe = 0;
More information about the asterisk-commits
mailing list