3b8c0a10ad3f6a9e91fb51744f7a6202805d7192
[platform/upstream/gstreamer.git] / gst / rtsp-server / rtsp-context.c
1 /* GStreamer
2  * Copyright (C) 2013 Wim Taymans <wim.taymans at gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 /**
20  * SECTION:rtsp-context
21  * @short_description: A client request context
22  * @see_also: #GstRTSPServer, #GstRTSPClient
23  *
24  * Last reviewed on 2013-07-11 (1.0.0)
25  */
26
27 #include "rtsp-context.h"
28
29 static GPrivate current_context;
30
31 /**
32  * gst_rtsp_context_get_current:
33  *
34  * Get the current #GstRTSPContext. This object is retrieved from the
35  * current thread that is handling the request for a client.
36  *
37  * Returns: a #GstRTSPContext
38  */
39 GstRTSPContext *
40 gst_rtsp_context_get_current (void)
41 {
42   GSList *l;
43
44   l = g_private_get (&current_context);
45   if (l == NULL)
46     return NULL;
47
48   return (GstRTSPContext *) (l->data);
49
50 }
51
52 /**
53  * gst_rtsp_context_push_current:
54  * @ctx: a ##GstRTSPContext
55  *
56  * Pushes @ctx onto the context stack. The current
57  * context can then be received using gst_rtsp_context_get_current().
58  **/
59 void
60 gst_rtsp_context_push_current (GstRTSPContext * ctx)
61 {
62   GSList *l;
63
64   g_return_if_fail (ctx != NULL);
65
66   l = g_private_get (&current_context);
67   l = g_slist_prepend (l, ctx);
68   g_private_set (&current_context, l);
69 }
70
71 /**
72  * gst_rtsp_context_pop_current:
73  * @ctx: a #GstRTSPContext
74  *
75  * Pops @ctx off the context stack (verifying that @ctx
76  * is on the top of the stack).
77  **/
78 void
79 gst_rtsp_context_pop_current (GstRTSPContext * ctx)
80 {
81   GSList *l;
82
83   l = g_private_get (&current_context);
84
85   g_return_if_fail (l != NULL);
86   g_return_if_fail (l->data == ctx);
87
88   l = g_slist_delete_link (l, l);
89   g_private_set (&current_context, l);
90 }