diff options
author | Wim Taymans <wim.taymans@collabora.co.uk> | 2009-06-30 21:27:53 +0200 |
---|---|---|
committer | Wim Taymans <wim@metal.(none)> | 2009-06-30 21:27:53 +0200 |
commit | a4c90c28c77aa0619872701f5042e3c7f4a52222 (patch) | |
tree | 70ee0d1b7cfd27635657a16284aad12a71b9eb68 | |
parent | a403469a0352576fdfc9d1f8d4ccc4ecfaf72272 (diff) |
sessionpool: add function to filter sessions
Add generic function to retrieve/remove sessions.
-rw-r--r-- | gst/rtsp-server/rtsp-session-pool.c | 68 | ||||
-rw-r--r-- | gst/rtsp-server/rtsp-session-pool.h | 42 |
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) | |||
382 | 382 | ||
383 | typedef struct | 383 | typedef struct |
384 | { | 384 | { |
385 | GstRTSPSessionPool *pool; | ||
386 | GstRTSPSessionFilterFunc func; | ||
387 | gpointer user_data; | ||
388 | GList *list; | ||
389 | } FilterData; | ||
390 | |||
391 | static gboolean | ||
392 | filter_func (gchar *sessionid, GstRTSPSession *sess, FilterData *data) | ||
393 | { | ||
394 | switch (data->func (data->pool, sess, data->user_data)) { | ||
395 | case GST_RTSP_FILTER_REMOVE: | ||
396 | return TRUE; | ||
397 | case GST_RTSP_FILTER_REF: | ||
398 | /* keep ref */ | ||
399 | data->list = g_list_prepend (data->list, g_object_ref (sess)); | ||
400 | /* fallthrough */ | ||
401 | default: | ||
402 | case GST_RTSP_FILTER_KEEP: | ||
403 | return FALSE; | ||
404 | } | ||
405 | } | ||
406 | |||
407 | /** | ||
408 | * gst_rtsp_session_pool_filter: | ||
409 | * @pool: a #GstRTSPSessionPool | ||
410 | * @func: a callback | ||
411 | * @user_data: user data passed to @func | ||
412 | * | ||
413 | * Call @func for each session in @pool. The result value of @func determines | ||
414 | * what happens to the session. @func will be called with the session pool | ||
415 | * locked so no further actions on @pool can be performed from @func. | ||
416 | * | ||
417 | * If @func returns #GST_RTSP_FILTER_REMOVE, the session will be removed from | ||
418 | * @pool. | ||
419 | * | ||
420 | * If @func returns #GST_RTSP_FILTER_KEEP, the session will remain in @pool. | ||
421 | * | ||
422 | * If @func returns #GST_RTSP_FILTER_REF, the session will remain in @pool but | ||
423 | * will also be added with an additional ref to the result GList of this | ||
424 | * function.. | ||
425 | * | ||
426 | * Returns: a GList with all sessions for which @func returned | ||
427 | * #GST_RTSP_FILTER_REF. After usage, each element in the GList should be unreffed | ||
428 | * before the list is freed. | ||
429 | */ | ||
430 | GList * | ||
431 | gst_rtsp_session_pool_filter (GstRTSPSessionPool *pool, | ||
432 | GstRTSPSessionFilterFunc func, gpointer user_data) | ||
433 | { | ||
434 | FilterData data; | ||
435 | |||
436 | g_return_val_if_fail (GST_IS_RTSP_SESSION_POOL (pool), NULL); | ||
437 | g_return_val_if_fail (func != NULL, NULL); | ||
438 | |||
439 | data.pool = pool; | ||
440 | data.func = func; | ||
441 | data.user_data = user_data; | ||
442 | data.list = NULL; | ||
443 | |||
444 | g_mutex_lock (pool->lock); | ||
445 | g_hash_table_foreach_remove (pool->sessions, (GHRFunc) filter_func, &data); | ||
446 | g_mutex_unlock (pool->lock); | ||
447 | |||
448 | return data.list; | ||
449 | } | ||
450 | |||
451 | typedef struct | ||
452 | { | ||
385 | GSource source; | 453 | GSource source; |
386 | GstRTSPSessionPool *pool; | 454 | GstRTSPSessionPool *pool; |
387 | gint timeout; | 455 | 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 { | |||
81 | */ | 81 | */ |
82 | typedef gboolean (*GstRTSPSessionPoolFunc) (GstRTSPSessionPool *pool, gpointer user_data); | 82 | typedef gboolean (*GstRTSPSessionPoolFunc) (GstRTSPSessionPool *pool, gpointer user_data); |
83 | 83 | ||
84 | /** | ||
85 | * GstRTSPFilterResult: | ||
86 | * @GST_RTSP_FILTER_REMOVE: Remove session | ||
87 | * @GST_RTSP_FILTER_KEEP: Keep session in the pool | ||
88 | * @GST_RTSP_FILTER_REF: Ref session in the result list | ||
89 | * | ||
90 | * Possible return values for gst_rtsp_session_pool_filter(). | ||
91 | */ | ||
92 | typedef enum | ||
93 | { | ||
94 | GST_RTSP_FILTER_REMOVE, | ||
95 | GST_RTSP_FILTER_KEEP, | ||
96 | GST_RTSP_FILTER_REF, | ||
97 | } GstRTSPFilterResult; | ||
98 | |||
99 | /** | ||
100 | * GstRTSPSessionFilterFunc: | ||
101 | * @pool: a #GstRTSPSessionPool object | ||
102 | * @session: a #GstRTSPSession in @pool | ||
103 | * @user_data: user data that has been given to gst_rtsp_session_pool_filter() | ||
104 | * | ||
105 | * This function will be called by the gst_rtsp_session_pool_filter(). An | ||
106 | * implementation should return a value of #GstRTSPFilterResult. | ||
107 | * | ||
108 | * When this function returns #GST_RTSP_FILTER_REMOVE, @session will be removed | ||
109 | * from @pool. | ||
110 | * | ||
111 | * A return value of #GST_RTSP_FILTER_KEEP will leave @session untouched in | ||
112 | * @pool. | ||
113 | * | ||
114 | * A value of GST_RTSP_FILTER_REF will add @session to the result #GList of | ||
115 | * gst_rtsp_session_pool_filter(). | ||
116 | * | ||
117 | * Returns: a #GstRTSPFilterResult. | ||
118 | */ | ||
119 | typedef GstRTSPFilterResult (*GstRTSPSessionFilterFunc) (GstRTSPSessionPool *pool, | ||
120 | GstRTSPSession *session, | ||
121 | gpointer user_data); | ||
122 | |||
84 | 123 | ||
85 | GType gst_rtsp_session_pool_get_type (void); | 124 | GType gst_rtsp_session_pool_get_type (void); |
86 | 125 | ||
@@ -101,6 +140,9 @@ gboolean gst_rtsp_session_pool_remove (GstRTSPSessionPoo | |||
101 | GstRTSPSession *sess); | 140 | GstRTSPSession *sess); |
102 | 141 | ||
103 | /* perform session maintenance */ | 142 | /* perform session maintenance */ |
143 | GList * gst_rtsp_session_pool_filter (GstRTSPSessionPool *pool, | ||
144 | GstRTSPSessionFilterFunc func, | ||
145 | gpointer user_data); | ||
104 | guint gst_rtsp_session_pool_cleanup (GstRTSPSessionPool *pool); | 146 | guint gst_rtsp_session_pool_cleanup (GstRTSPSessionPool *pool); |
105 | GSource * gst_rtsp_session_pool_create_watch (GstRTSPSessionPool *pool); | 147 | GSource * gst_rtsp_session_pool_create_watch (GstRTSPSessionPool *pool); |
106 | 148 | ||