From a3522af4f8af10e8f352ca5d88cb7815c04ed35c Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 20 Jan 2009 19:41:53 +0100 Subject: [PATCH] Allow custom session pools to override the session id allocation algorithms Add some comments. --- gst/rtsp-server/rtsp-session-pool.c | 32 +++++++++++++++++++++++++++++--- gst/rtsp-server/rtsp-session-pool.h | 11 +++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/gst/rtsp-server/rtsp-session-pool.c b/gst/rtsp-server/rtsp-session-pool.c index a58be9d..968d241 100644 --- a/gst/rtsp-server/rtsp-session-pool.c +++ b/gst/rtsp-server/rtsp-session-pool.c @@ -23,6 +23,7 @@ static void gst_rtsp_session_pool_finalize (GObject * object); +static gchar * create_session_id (GstRTSPSessionPool *pool); G_DEFINE_TYPE (GstRTSPSessionPool, gst_rtsp_session_pool, G_TYPE_OBJECT); @@ -34,6 +35,8 @@ gst_rtsp_session_pool_class_init (GstRTSPSessionPoolClass * klass) gobject_class = G_OBJECT_CLASS (klass); gobject_class->finalize = gst_rtsp_session_pool_finalize; + + klass->create_session_id = create_session_id; } static void @@ -59,6 +62,8 @@ gst_rtsp_session_pool_finalize (GObject * object) * gst_rtsp_session_pool_new: * * Create a new #GstRTSPSessionPool instance. + * + * Returns: A new #GstRTSPSessionPool. g_object_unref() after usage. */ GstRTSPSessionPool * gst_rtsp_session_pool_new (void) @@ -98,7 +103,7 @@ gst_rtsp_session_pool_find (GstRTSPSessionPool *pool, const gchar *sessionid) } static gchar * -create_session_id (void) +create_session_id (GstRTSPSessionPool *pool) { gchar id[16]; gint i; @@ -122,14 +127,23 @@ GstRTSPSession * gst_rtsp_session_pool_create (GstRTSPSessionPool *pool) { GstRTSPSession *result = NULL; - gchar *id; + GstRTSPSessionPoolClass *klass; + gchar *id = NULL; g_return_val_if_fail (GST_IS_RTSP_SESSION_POOL (pool), NULL); + klass = GST_RTSP_SESSION_POOL_GET_CLASS (pool); + do { /* start by creating a new random session id, we assume that this is random * enough to not cause a collision, which we will check later */ - id = create_session_id (); + if (klass->create_session_id) + id = klass->create_session_id (pool); + else + goto no_function; + + if (id == NULL) + goto no_session; g_mutex_lock (pool->lock); /* check if the sessionid existed */ @@ -151,6 +165,18 @@ gst_rtsp_session_pool_create (GstRTSPSessionPool *pool) } while (result == NULL); return result; + + /* ERRORS */ +no_function: + { + g_warning ("no create_session_id vmethod in GstRTSPSessionPool %p", pool); + return NULL; + } +no_session: + { + g_warning ("can't create session id with GstRTSPSessionPool %p", pool); + return NULL; + } } /** diff --git a/gst/rtsp-server/rtsp-session-pool.h b/gst/rtsp-server/rtsp-session-pool.h index 9336647..fafe606 100644 --- a/gst/rtsp-server/rtsp-session-pool.h +++ b/gst/rtsp-server/rtsp-session-pool.h @@ -41,6 +41,9 @@ typedef struct _GstRTSPSessionPoolClass GstRTSPSessionPoolClass; /** * GstRTSPSessionPool: * + * @lock: locking the session hashtable + * @session: hashtable of sessions indexed by the session id. + * * An object that keeps track of the active sessions. */ struct _GstRTSPSessionPool { @@ -50,8 +53,16 @@ struct _GstRTSPSessionPool { GHashTable *sessions; }; +/** + * GstRTSPSessionPoolClass: + * + * @create_session_id: create a new random session id. Subclasses should not + * check if the session exists. + */ struct _GstRTSPSessionPoolClass { GObjectClass parent_class; + + gchar * (*create_session_id) (GstRTSPSessionPool *pool); }; GType gst_rtsp_session_pool_get_type (void); -- 2.7.4