summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@collabora.co.uk>2009-06-30 19:27:53 (GMT)
committerWim Taymans <wim@metal.(none)>2009-06-30 19:27:53 (GMT)
commita4c90c28c77aa0619872701f5042e3c7f4a52222 (patch)
tree70ee0d1b7cfd27635657a16284aad12a71b9eb68
parenta403469a0352576fdfc9d1f8d4ccc4ecfaf72272 (diff)
sessionpool: add function to filter sessions
Add generic function to retrieve/remove sessions.
-rw-r--r--gst/rtsp-server/rtsp-session-pool.c68
-rw-r--r--gst/rtsp-server/rtsp-session-pool.h42
2 files changed, 110 insertions, 0 deletions
diff --git a/gst/rtsp-server/rtsp-session-pool.c b/gst/rtsp-server/rtsp-session-pool.c
index d8702a9..7c68da1 100644
--- a/gst/rtsp-server/rtsp-session-pool.c
+++ b/gst/rtsp-server/rtsp-session-pool.c
@@ -382,6 +382,74 @@ gst_rtsp_session_pool_cleanup (GstRTSPSessionPool *pool)
typedef struct
{
+ GstRTSPSessionPool *pool;
+ GstRTSPSessionFilterFunc func;
+ gpointer user_data;
+ GList *list;
+} FilterData;
+
+static gboolean
+filter_func (gchar *sessionid, GstRTSPSession *sess, FilterData *data)
+{
+ switch (data->func (data->pool, sess, data->user_data)) {
+ case GST_RTSP_FILTER_REMOVE:
+ return TRUE;
+ case GST_RTSP_FILTER_REF:
+ /* keep ref */
+ data->list = g_list_prepend (data->list, g_object_ref (sess));
+ /* fallthrough */
+ default:
+ case GST_RTSP_FILTER_KEEP:
+ return FALSE;
+ }
+}
+
+/**
+ * gst_rtsp_session_pool_filter:
+ * @pool: a #GstRTSPSessionPool
+ * @func: a callback
+ * @user_data: user data passed to @func
+ *
+ * Call @func for each session in @pool. The result value of @func determines
+ * what happens to the session. @func will be called with the session pool
+ * locked so no further actions on @pool can be performed from @func.
+ *
+ * If @func returns #GST_RTSP_FILTER_REMOVE, the session will be removed from
+ * @pool.
+ *
+ * If @func returns #GST_RTSP_FILTER_KEEP, the session will remain in @pool.
+ *
+ * If @func returns #GST_RTSP_FILTER_REF, the session will remain in @pool but
+ * will also be added with an additional ref to the result GList of this
+ * function..
+ *
+ * Returns: a GList with all sessions for which @func returned
+ * #GST_RTSP_FILTER_REF. After usage, each element in the GList should be unreffed
+ * before the list is freed.
+ */
+GList *
+gst_rtsp_session_pool_filter (GstRTSPSessionPool *pool,
+ GstRTSPSessionFilterFunc func, gpointer user_data)
+{
+ FilterData data;
+
+ g_return_val_if_fail (GST_IS_RTSP_SESSION_POOL (pool), NULL);
+ g_return_val_if_fail (func != NULL, NULL);
+
+ data.pool = pool;
+ data.func = func;
+ data.user_data = user_data;
+ data.list = NULL;
+
+ g_mutex_lock (pool->lock);
+ g_hash_table_foreach_remove (pool->sessions, (GHRFunc) filter_func, &data);
+ g_mutex_unlock (pool->lock);
+
+ return data.list;
+}
+
+typedef struct
+{
GSource source;
GstRTSPSessionPool *pool;
gint timeout;
diff --git a/gst/rtsp-server/rtsp-session-pool.h b/gst/rtsp-server/rtsp-session-pool.h
index 7c387cd..475628c 100644
--- a/gst/rtsp-server/rtsp-session-pool.h
+++ b/gst/rtsp-server/rtsp-session-pool.h
@@ -81,6 +81,45 @@ struct _GstRTSPSessionPoolClass {
*/
typedef gboolean (*GstRTSPSessionPoolFunc) (GstRTSPSessionPool *pool, gpointer user_data);
+/**
+ * GstRTSPFilterResult:
+ * @GST_RTSP_FILTER_REMOVE: Remove session
+ * @GST_RTSP_FILTER_KEEP: Keep session in the pool
+ * @GST_RTSP_FILTER_REF: Ref session in the result list
+ *
+ * Possible return values for gst_rtsp_session_pool_filter().
+ */
+typedef enum
+{
+ GST_RTSP_FILTER_REMOVE,
+ GST_RTSP_FILTER_KEEP,
+ GST_RTSP_FILTER_REF,
+} GstRTSPFilterResult;
+
+/**
+ * GstRTSPSessionFilterFunc:
+ * @pool: a #GstRTSPSessionPool object
+ * @session: a #GstRTSPSession in @pool
+ * @user_data: user data that has been given to gst_rtsp_session_pool_filter()
+ *
+ * This function will be called by the gst_rtsp_session_pool_filter(). An
+ * implementation should return a value of #GstRTSPFilterResult.
+ *
+ * When this function returns #GST_RTSP_FILTER_REMOVE, @session will be removed
+ * from @pool.
+ *
+ * A return value of #GST_RTSP_FILTER_KEEP will leave @session untouched in
+ * @pool.
+ *
+ * A value of GST_RTSP_FILTER_REF will add @session to the result #GList of
+ * gst_rtsp_session_pool_filter().
+ *
+ * Returns: a #GstRTSPFilterResult.
+ */
+typedef GstRTSPFilterResult (*GstRTSPSessionFilterFunc) (GstRTSPSessionPool *pool,
+ GstRTSPSession *session,
+ gpointer user_data);
+
GType gst_rtsp_session_pool_get_type (void);
@@ -101,6 +140,9 @@ gboolean gst_rtsp_session_pool_remove (GstRTSPSessionPoo
GstRTSPSession *sess);
/* perform session maintenance */
+GList * gst_rtsp_session_pool_filter (GstRTSPSessionPool *pool,
+ GstRTSPSessionFilterFunc func,
+ gpointer user_data);
guint gst_rtsp_session_pool_cleanup (GstRTSPSessionPool *pool);
GSource * gst_rtsp_session_pool_create_watch (GstRTSPSessionPool *pool);