[asterisk-commits] mmichelson: branch mmichelson/direct_media r382810 - in /team/mmichelson/dire...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Mar 11 14:20:33 CDT 2013


Author: mmichelson
Date: Mon Mar 11 14:20:29 2013
New Revision: 382810

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382810
Log:
Add callback parameters to places where they will be required.

This way, session refreshes can have additional headers added by the
caller if desired. Similarly, requests can now have a response callback
to be called when the response comes in. The logic for calling the response
callback does not exist yet, but I'll get to that next.


Modified:
    team/mmichelson/direct_media/channels/chan_gulp.c
    team/mmichelson/direct_media/include/asterisk/res_sip_session.h
    team/mmichelson/direct_media/res/res_sip_session.c

Modified: team/mmichelson/direct_media/channels/chan_gulp.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/direct_media/channels/chan_gulp.c?view=diff&rev=382810&r1=382809&r2=382810
==============================================================================
--- team/mmichelson/direct_media/channels/chan_gulp.c (original)
+++ team/mmichelson/direct_media/channels/chan_gulp.c Mon Mar 11 14:20:29 2013
@@ -144,7 +144,7 @@
 static int send_direct_media_request(void *data)
 {
 	RAII_VAR(struct ast_sip_session *, session, data, ao2_cleanup);
-	return ast_sip_session_refresh(session, session->endpoint->direct_media_method);
+	return ast_sip_session_refresh(session, NULL, NULL, session->endpoint->direct_media_method);
 }
 
 /*! \brief Function called by RTP engine to change where the remote party should send media */

Modified: team/mmichelson/direct_media/include/asterisk/res_sip_session.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/direct_media/include/asterisk/res_sip_session.h?view=diff&rev=382810&r1=382809&r2=382810
==============================================================================
--- team/mmichelson/direct_media/include/asterisk/res_sip_session.h (original)
+++ team/mmichelson/direct_media/include/asterisk/res_sip_session.h Mon Mar 11 14:20:29 2013
@@ -63,11 +63,6 @@
 	struct ast_sockaddr direct_media_addr;
 	/*! \brief Stream is on hold */
 	unsigned int held:1;
-};
-
-struct ast_sip_session_delayed_request {
-	char method[15];
-	AST_LIST_ENTRY(ast_sip_session_delayed_request) next;
 };
 
 /*!
@@ -99,6 +94,16 @@
 	AST_LIST_HEAD_NOLOCK(, ast_sip_session_delayed_request) delayed_requests;
 	/* When we need to reschedule a reinvite, we use this structure to do it */
 	pj_timer_entry rescheduled_reinvite;
+};
+
+typedef int (*request_creation_cb)(struct ast_sip_session *session, pjsip_tx_data *tdata);
+typedef int (*response_cb)(struct ast_sip_session *session, pjsip_rx_data *rdata);
+
+struct ast_sip_session_delayed_request {
+	char method[15];
+	request_creation_cb on_request_creation;
+	response_cb on_response;
+	AST_LIST_ENTRY(ast_sip_session_delayed_request) next;
 };
 
 /*!
@@ -378,7 +383,9 @@
  * \retval 0 Successfully sent refresh
  * \retval -1 Failure to send refresh
  */
-int ast_sip_session_refresh(struct ast_sip_session *session, enum ast_sip_session_refresh_method method);
+int ast_sip_session_refresh(struct ast_sip_session *session,
+		request_creation_cb on_request_creation, response_cb on_response,
+		enum ast_sip_session_refresh_method method);
 
 /*!
  * \brief Send a SIP response
@@ -402,4 +409,18 @@
  */
 void ast_sip_session_send_request(struct ast_sip_session *session, pjsip_tx_data *tdata);
 
+/*!
+ * \brief Send a SIP request and get called back when a response is received
+ *
+ * This will send the request out exactly the same as ast_sip_send_request() does.
+ * The difference is that when a response arrives, the specified callback will be
+ * called into
+ *
+ * \param session The session on which to send the request
+ * \param tdata The request to send
+ * \param on_response Callback to be called when a response is received
+ */
+void ast_sip_session_send_request_with_cb(struct ast_sip_session *session, pjsip_tx_data *tdata,
+		response_cb on_response);
+
 #endif /* _RES_SIP_SESSION_H */

Modified: team/mmichelson/direct_media/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/direct_media/res/res_sip_session.c?view=diff&rev=382810&r1=382809&r2=382810
==============================================================================
--- team/mmichelson/direct_media/res/res_sip_session.c (original)
+++ team/mmichelson/direct_media/res/res_sip_session.c Mon Mar 11 14:20:29 2013
@@ -364,12 +364,17 @@
 	ast_debug(3, "Sending delayed %s request to %s\n", delay->method, ast_sorcery_object_get_id(session->endpoint));
 
 	if (!strcmp(delay->method, "INVITE")) {
-		ast_sip_session_refresh(session, AST_SIP_SESSION_REFRESH_METHOD_INVITE);
+		ast_sip_session_refresh(session, delay->on_request_creation,
+				delay->on_response, AST_SIP_SESSION_REFRESH_METHOD_INVITE);
 	} else if (!strcmp(delay->method, "UPDATE")) {
-		ast_sip_session_refresh(session, AST_SIP_SESSION_REFRESH_METHOD_UPDATE);
+		ast_sip_session_refresh(session, delay->on_request_creation,
+				delay->on_response, AST_SIP_SESSION_REFRESH_METHOD_UPDATE);
 	} else if (!strcmp(delay->method, "BYE")) {
 		pjsip_tx_data *tdata;
 		pjsip_inv_end_session(session->inv_session, 500, 0, &tdata);
+		if (delay->on_request_creation) {
+			delay->on_request_creation(session, tdata);
+		}
 		ast_sip_session_send_request(session, tdata);
 	}
 	ast_free(delay);
@@ -391,18 +396,23 @@
 	ast_sip_push_task(session->serializer, send_delayed_request, session);
 }
 
-static int delay_request(struct ast_sip_session *session, const char *method)
+static int delay_request(struct ast_sip_session *session, request_creation_cb on_request,
+		response_cb on_response, const char *method)
 {
 	struct ast_sip_session_delayed_request *delay = ast_calloc(1, sizeof(*delay));
 	if (!delay) {
 		return -1;
 	}
 	ast_copy_string(delay->method, method, sizeof(delay->method));
+	delay->on_request_creation = on_request;
+	delay->on_response = on_response;
 	AST_LIST_INSERT_TAIL(&session->delayed_requests, delay, next);
 	return 0;
 }
 
-int ast_sip_session_refresh(struct ast_sip_session *session, enum ast_sip_session_refresh_method method)
+int ast_sip_session_refresh(struct ast_sip_session *session,
+		request_creation_cb on_request_creation, response_cb on_response,
+		enum ast_sip_session_refresh_method method)
 {
 	pjsip_inv_session *inv_session = session->inv_session;
 	pjmedia_sdp_session *new_sdp;
@@ -420,7 +430,7 @@
 		/* We can't send a reinvite yet, so delay it */
 		ast_debug(3, "Delaying sending reinvite to %s because of outstanding transaction...\n",
 				S_OR(ast_sorcery_object_get_id(session->endpoint), "outbound"));
-		return delay_request(session, "INVITE");
+		return delay_request(session, on_request_creation, on_response, "INVITE");
 	}
 
 	if (pjmedia_sdp_neg_was_answer_remote(inv_session->neg)) {
@@ -438,7 +448,12 @@
 		ast_log(LOG_WARNING, "Failed to create UPDATE properly.\n");
 		return -1;
 	}
-	ast_sip_session_send_request(session, tdata);
+	if (on_request_creation) {
+		if (on_request_creation(session, tdata)) {
+			return -1;
+		}
+	}
+	ast_sip_session_send_request_with_cb(session, tdata, on_response);
 	return 0;
 }
 
@@ -449,7 +464,8 @@
 	return;
 }
 
-void ast_sip_session_send_request(struct ast_sip_session *session, pjsip_tx_data *tdata)
+void ast_sip_session_send_request_with_cb(struct ast_sip_session *session, pjsip_tx_data *tdata,
+		response_cb on_response)
 {
 	pjsip_inv_session *inv_session = session->inv_session;
 
@@ -464,12 +480,17 @@
 		ast_copy_pj_str(method, &tdata->msg->line.req.method.name, sizeof(method));
 		ast_debug(3, "Delaying sending %s request to %s due to outstanding transaction\n",
 				method, S_OR(ast_sorcery_object_get_id(session->endpoint), "outbound"));
-		delay_request(session, method);
+		delay_request(session, NULL, on_response, method);
 		return;
 	}
 	handle_outgoing_request(session, tdata);
 	pjsip_inv_send_msg(session->inv_session, tdata);
 	return;
+}
+
+void ast_sip_session_send_request(struct ast_sip_session *session, pjsip_tx_data *tdata)
+{
+	ast_sip_session_send_request_with_cb(session, tdata, NULL);
 }
 
 static pj_status_t session_load(pjsip_endpoint *endpt);
@@ -980,7 +1001,8 @@
 {
 	struct ast_sip_session *session = data;
 
-	ast_sip_session_refresh(session, AST_SIP_SESSION_REFRESH_METHOD_INVITE);
+	/* XXX Address the callbacks here!! */
+	ast_sip_session_refresh(session, NULL, NULL, AST_SIP_SESSION_REFRESH_METHOD_INVITE);
 	ao2_ref(session, -1);
 	return 0;
 }




More information about the asterisk-commits mailing list