[svn-commits] russell: branch russell/ais r78284 - /team/russell/ais/res/res_ais.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Aug 6 17:26:36 CDT 2007


Author: russell
Date: Mon Aug  6 17:26:35 2007
New Revision: 78284

URL: http://svn.digium.com/view/asterisk?view=rev&rev=78284
Log:
And now, add the code for receiving events from the cluster and passing them
into Asterisk.  In theory, this module now supports distributed MWI.
Now, it's time to test it out to find out what is broken.  :)

Modified:
    team/russell/ais/res/res_ais.c

Modified: team/russell/ais/res/res_ais.c
URL: http://svn.digium.com/view/asterisk/team/russell/ais/res/res_ais.c?view=diff&rev=78284&r1=78283&r2=78284
==============================================================================
--- team/russell/ais/res/res_ais.c (original)
+++ team/russell/ais/res/res_ais.c Mon Aug  6 17:26:35 2007
@@ -112,10 +112,10 @@
 	.saClmClusterTrackCallback   = clm_track_cb,
 };
 
-void evt_channel_open_cb(SaInvocationT invocation, SaEvtChannelHandleT channelHandle,
+void evt_channel_open_cb(SaInvocationT invocation, SaEvtChannelHandleT channel_handle,
 	SaAisErrorT error);
-void evt_event_deliver_cb(SaEvtSubscriptionIdT subscriptionId,
-	const SaEvtEventHandleT eventHandle, const SaSizeT eventDataSize);
+void evt_event_deliver_cb(SaEvtSubscriptionIdT subscription_id,
+	const SaEvtEventHandleT event_handle, const SaSizeT event_datalen);
 
 static const SaEvtCallbacksT evt_callbacks = {
 	.saEvtChannelOpenCallback  = evt_channel_open_cb,
@@ -178,16 +178,66 @@
 
 }
 
-void evt_channel_open_cb(SaInvocationT invocation, SaEvtChannelHandleT channelHandle,
+void evt_channel_open_cb(SaInvocationT invocation, SaEvtChannelHandleT channel_handle,
 	SaAisErrorT error)
 {
 
 }
 
-void evt_event_deliver_cb(SaEvtSubscriptionIdT subscriptionId,
-	const SaEvtEventHandleT eventHandle, const SaSizeT eventDataSize)
-{
-
+static void queue_event(struct ast_event *ast_event)
+{
+	/*! 
+	 * \todo This hack macks me sad.  I need to come up with a better way to
+	 *       figure out whether an event should be cached or not, and what
+	 *       parameters to cache on.
+	 *
+	 *       As long as the types of events that are supported is limited,
+	 *       this isn't *terrible*, I guess.  Perhaps we should just define
+	 *       caching rules in the core, and make the configurable, and not
+	 *       have it be the job of the event publishers.
+	 */
+
+	if (ast_event_get_type(ast_event) == AST_EVENT_MWI) {
+		ast_event_queue_and_cache(ast_event,
+			AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR,
+			AST_EVENT_IE_END);
+	} else {
+		ast_event_queue(ast_event);
+	}
+}
+
+void evt_event_deliver_cb(SaEvtSubscriptionIdT sub_id,
+	const SaEvtEventHandleT event_handle, const SaSizeT event_datalen)
+{
+	/* It is important to note that this works because we *know* that this
+	 * function will only be called by a single thread, the dispatch_thread.
+	 * If this module gets changed such that this is no longer the case, this
+	 * should get changed to a thread-local buffer, instead. */
+	static unsigned char buf[4096];
+	struct ast_event *event_dup, *event = (struct ast_event *) buf;
+	SaAisErrorT res;
+	SaSizeT len = sizeof(buf);
+
+	if (event_datalen > len) {
+		ast_log(LOG_ERROR, "Event received with size %u, which is too big\n"
+			"for the allocated size %u. Change the code to increase the size.\n",
+			(unsigned int) event_datalen, (unsigned int) len);
+		return;
+	}
+
+	res = saEvtEventDataGet(event_handle, event, &len);
+	if (res != SA_AIS_OK) {
+		ast_log(LOG_ERROR, "Error retrieving event payload: %s\n", 
+			ais_err2str(res));
+		return;
+	}
+
+	if (!(event_dup = ast_malloc(len)))
+		return;
+	
+	memcpy(event_dup, event, len);
+
+	queue_event(event_dup);
 }
 
 static const char *type_to_filter_str(enum ast_event_type type)




More information about the svn-commits mailing list