1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gstreamer.Context;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gstreamer.Structure;
31 private import gstreamerc.gstreamer;
32 public  import gstreamerc.gstreamertypes;
33 
34 
35 /**
36  * #GstContext is a container object used to store contexts like a device
37  * context, a display server connection and similar concepts that should
38  * be shared between multiple elements.
39  * 
40  * Applications can set a context on a complete pipeline by using
41  * gst_element_set_context(), which will then be propagated to all
42  * child elements. Elements can handle these in #GstElementClass.set_context()
43  * and merge them with the context information they already have.
44  * 
45  * When an element needs a context it will do the following actions in this
46  * order until one step succeeds:
47  * 1. Check if the element already has a context
48  * 2. Query downstream with GST_QUERY_CONTEXT for the context
49  * 3. Query upstream with GST_QUERY_CONTEXT for the context
50  * 4. Post a GST_MESSAGE_NEED_CONTEXT message on the bus with the required
51  * context types and afterwards check if a usable context was set now
52  * 5. Create a context by itself and post a GST_MESSAGE_HAVE_CONTEXT message
53  * on the bus.
54  * 
55  * Bins will catch GST_MESSAGE_NEED_CONTEXT messages and will set any previously
56  * known context on the element that asks for it if possible. Otherwise the
57  * application should provide one if it can.
58  */
59 public class Context
60 {
61 	/** the main Gtk struct */
62 	protected GstContext* gstContext;
63 
64 	/** Get the main Gtk struct */
65 	public GstContext* getContextStruct()
66 	{
67 		return gstContext;
68 	}
69 
70 	/** the main Gtk struct as a void* */
71 	protected void* getStruct()
72 	{
73 		return cast(void*)gstContext;
74 	}
75 
76 	/**
77 	 * Sets our main struct and passes it to the parent class.
78 	 */
79 	public this (GstContext* gstContext)
80 	{
81 		this.gstContext = gstContext;
82 	}
83 
84 	/**
85 	 */
86 
87 	public static GType getType()
88 	{
89 		return gst_context_get_type();
90 	}
91 
92 	/**
93 	 * Create a new context.
94 	 *
95 	 * Params:
96 	 *     contextType = Context type
97 	 *     persistent = Persistent context
98 	 *
99 	 * Return: The new context.
100 	 *
101 	 * Since: 1.2
102 	 *
103 	 * Throws: ConstructionException GTK+ fails to create the object.
104 	 */
105 	public this(string contextType, bool persistent)
106 	{
107 		auto p = gst_context_new(Str.toStringz(contextType), persistent);
108 		
109 		if(p is null)
110 		{
111 			throw new ConstructionException("null returned by new");
112 		}
113 		
114 		this(cast(GstContext*) p);
115 	}
116 
117 	/**
118 	 * Get the type of @context.
119 	 *
120 	 * Return: The type of the context.
121 	 *
122 	 * Since: 1.2
123 	 */
124 	public string getContextType()
125 	{
126 		return Str.toString(gst_context_get_context_type(gstContext));
127 	}
128 
129 	/**
130 	 * Access the structure of the context.
131 	 *
132 	 * Return: The structure of the context. The structure is
133 	 *     still owned by the context, which means that you should not modify it,
134 	 *     free it and that the pointer becomes invalid when you free the context.
135 	 *
136 	 * Since: 1.2
137 	 */
138 	public Structure getStructure()
139 	{
140 		auto p = gst_context_get_structure(gstContext);
141 		
142 		if(p is null)
143 		{
144 			return null;
145 		}
146 		
147 		return ObjectG.getDObject!(Structure)(cast(GstStructure*) p);
148 	}
149 
150 	/**
151 	 * Checks if @context has @context_type.
152 	 *
153 	 * Params:
154 	 *     contextType = Context type to check.
155 	 *
156 	 * Return: %TRUE if @context has @context_type.
157 	 *
158 	 * Since: 1.2
159 	 */
160 	public bool hasContextType(string contextType)
161 	{
162 		return gst_context_has_context_type(gstContext, Str.toStringz(contextType)) != 0;
163 	}
164 
165 	/**
166 	 * Check if @context is persistent.
167 	 *
168 	 * Return: %TRUE if the context is persistent.
169 	 *
170 	 * Since: 1.2
171 	 */
172 	public bool isPersistent()
173 	{
174 		return gst_context_is_persistent(gstContext) != 0;
175 	}
176 
177 	/**
178 	 * Get a writable version of the structure.
179 	 *
180 	 * Return: The structure of the context. The structure is still
181 	 *     owned by the event, which means that you should not free it and
182 	 *     that the pointer becomes invalid when you free the event.
183 	 *     This function checks if @context is writable.
184 	 *
185 	 * Since: 1.2
186 	 */
187 	public Structure writableStructure()
188 	{
189 		auto p = gst_context_writable_structure(gstContext);
190 		
191 		if(p is null)
192 		{
193 			return null;
194 		}
195 		
196 		return ObjectG.getDObject!(Structure)(cast(GstStructure*) p);
197 	}
198 }