mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-20 00:31:13 +00:00
Add support for autogenerating signal code in element bindings
This commit is contained in:
parent
33d93e8e87
commit
8f450ee581
9 changed files with 84 additions and 80 deletions
|
@ -1,4 +1,4 @@
|
|||
SUBDIRS = source parser gstreamer-sharp doc tests samples
|
||||
SUBDIRS = source parser elementgen gstreamer-sharp doc tests samples
|
||||
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = gstreamer-sharp-0.10.pc
|
||||
|
|
|
@ -20,6 +20,11 @@ public class EnumInfo {
|
|||
public ArrayList values;
|
||||
}
|
||||
|
||||
public class SignalParameter {
|
||||
public string name;
|
||||
public string type;
|
||||
}
|
||||
|
||||
public class SignalInfo {
|
||||
public string name;
|
||||
public string managed_name;
|
||||
|
@ -147,7 +152,14 @@ public class ElementGen {
|
|||
if (parms != null) {
|
||||
si.parameters = new ArrayList ();
|
||||
foreach (XmlElement parm in parms.ChildNodes) {
|
||||
si.parameters.Add (parm.InnerText);
|
||||
SignalParameter par = new SignalParameter ();
|
||||
par.type = parm.InnerText;
|
||||
|
||||
if (parm.Attributes["name"] == null)
|
||||
throw new Exception ("All signal parameters need the 'name' attribute");
|
||||
|
||||
par.name = parm.Attributes["name"].InnerText;
|
||||
si.parameters.Add (par);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,7 +190,14 @@ public class ElementGen {
|
|||
if (parms != null) {
|
||||
si.parameters = new ArrayList ();
|
||||
foreach (XmlElement parm in parms.ChildNodes) {
|
||||
si.parameters.Add (parm.InnerText);
|
||||
SignalParameter par = new SignalParameter ();
|
||||
par.type = parm.InnerText;
|
||||
|
||||
if (parm.Attributes["name"] == null)
|
||||
throw new Exception ("All signal parameters need the 'name' attribute");
|
||||
|
||||
par.name = parm.Attributes["name"].InnerText;
|
||||
si.parameters.Add (par);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -288,14 +307,55 @@ public class ElementGen {
|
|||
writer.WriteLine ("\t\t}\n");
|
||||
}
|
||||
|
||||
/* FIXME: We can't write signal/action code as we don't know the parameter names! */
|
||||
|
||||
writer.WriteLine ();
|
||||
|
||||
if (ei.signals.Count > 0) {
|
||||
foreach (SignalInfo si in ei.signals) {
|
||||
string managed_name = (si.managed_name != null) ? si.managed_name : PropToCamelCase (si.name);
|
||||
|
||||
writer.WriteLine ("\t\tpublic delegate void " + managed_name + "Handler (object o, " + managed_name + "Args args);\n");
|
||||
|
||||
writer.WriteLine ("\t\tpublic class " + managed_name + "Args : GLib.SignalArgs {");
|
||||
for (int i = 0; i < si.parameters.Count; i++) {
|
||||
SignalParameter param = (SignalParameter) si.parameters[i];
|
||||
string managed_type = CTypeToManagedType (param.type, api_doc);
|
||||
writer.WriteLine ("\t\t\tpublic " + managed_type + " " + param.name + " {");
|
||||
writer.WriteLine ("\t\t\t\tget {");
|
||||
writer.WriteLine ("\t\t\t\t\treturn (" + managed_type + ") Args[" + i + "];");
|
||||
writer.WriteLine ("\t\t\t\t}");
|
||||
writer.WriteLine ("\t\t\t}\n");
|
||||
|
||||
}
|
||||
writer.WriteLine ("\t\t}\n");
|
||||
|
||||
writer.WriteLine ("\t\tprivate Delegate " + managed_name + "_delegate;\n");
|
||||
|
||||
writer.WriteLine ("\t\tprotected virtual void On" + managed_name + " (object o, GLib.SignalArgs args) {");
|
||||
writer.WriteLine ("\t\t\tBindingHelper.InvokeProxySignalDelegate (" + managed_name + "_delegate, typeof (" + managed_name + "Args), o, args);");
|
||||
writer.WriteLine ("\t\t}\n");
|
||||
|
||||
writer.WriteLine ("\t\tpublic event " + managed_name + "Handler " + managed_name + " {");
|
||||
writer.WriteLine ("\t\t\tadd {");
|
||||
writer.WriteLine ("\t\t\t\t" + managed_name + "_delegate = BindingHelper.AddProxySignalDelegate (this, \"" + si.name + "\", On" + managed_name + ", " + managed_name + "_delegate, value);");
|
||||
writer.WriteLine ("\t\t\t}\n");
|
||||
|
||||
writer.WriteLine ("\t\t\tremove {");
|
||||
writer.WriteLine ("\t\t\t\t" + managed_name + "_delegate = BindingHelper.RemoveProxySignalDelegate (this, \"" + si.name + "\", On" + managed_name + ", " + managed_name + "_delegate, value);");
|
||||
writer.WriteLine ("\t\t\t}");
|
||||
writer.WriteLine ("\t\t}");
|
||||
}
|
||||
}
|
||||
|
||||
if (ei.actions.Count > 0)
|
||||
throw new Exception ("No support for actions yet");
|
||||
|
||||
if (ei.interfaces.Count > 0) {
|
||||
string path = Path.GetDirectoryName (System.Reflection.Assembly.GetCallingAssembly ().Location);
|
||||
|
||||
foreach (string iface in ei.interfaces) {
|
||||
writer.WriteLine ("#endregion");
|
||||
writer.WriteLine ("#region Customized code");
|
||||
writer.WriteLine ("#line 1 \"" + iface + ".cs\"");
|
||||
StreamReader interface_code = System.IO.File.OpenText (path + "/interfaces/" + iface + ".cs");
|
||||
string iface_code = interface_code.ReadToEnd ();
|
||||
writer.WriteLine (iface_code);
|
||||
|
|
|
@ -136,10 +136,10 @@ generated-stamp: $(API) $(build_customs) $(overrides)
|
|||
&& mv generated/ObjectManager.cs.tmp generated/ObjectManager.cs \
|
||||
&& touch generated-stamp
|
||||
|
||||
coreplugins/*.cs: $(API) coreplugins/*.custom coreplugins/inspect/*.raw
|
||||
coreplugins/*.cs: $(API) coreplugins/*.metadata coreplugins/inspect/*.raw
|
||||
$(MAKE) -C coreplugins
|
||||
|
||||
baseplugins/*.cs: $(API) baseplugins/*.custom baseplugins/inspect/*.raw
|
||||
baseplugins/*.cs: $(API) baseplugins/*.metadata baseplugins/inspect/*.raw
|
||||
$(MAKE) -C baseplugins
|
||||
|
||||
$(KEYFILE): $(top_srcdir)/gstreamer-sharp.snk
|
||||
|
|
|
@ -2,8 +2,8 @@ ELEMENTS = decodebin playbin xvimagesink
|
|||
|
||||
NAMESPACE = Gst.BasePlugins
|
||||
INSPECT_FILES = $(patsubst %,inspect/%.raw,$(ELEMENTS))
|
||||
CUSTOM_FILES = decodebin.custom
|
||||
METADATA_FILES = playbin.metadata
|
||||
CUSTOM_FILES =
|
||||
METADATA_FILES = decodebin.metadata playbin.metadata
|
||||
CS_FILES = $(patsubst %,%.cs,$(ELEMENTS))
|
||||
XML_FILES = $(patsubst %,%.xml,$(ELEMENTS))
|
||||
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
public delegate void NewDecodedPadHandler (object o, NewDecodedPadArgs args);
|
||||
|
||||
public class NewDecodedPadArgs : GLib.SignalArgs {
|
||||
public Gst.Pad Pad {
|
||||
get {
|
||||
return (Gst.Pad) Args[0];
|
||||
}
|
||||
}
|
||||
|
||||
public bool Last {
|
||||
get {
|
||||
return (bool) Args[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Delegate new_decoded_pad_delegate;
|
||||
|
||||
protected virtual void OnNewDecodedPad (object o, GLib.SignalArgs args) {
|
||||
BindingHelper.InvokeProxySignalDelegate (new_decoded_pad_delegate,
|
||||
typeof (NewDecodedPadArgs), o, args);
|
||||
}
|
||||
|
||||
public event NewDecodedPadHandler NewDecodedPad {
|
||||
add {
|
||||
new_decoded_pad_delegate = BindingHelper.AddProxySignalDelegate (this,
|
||||
"new-decoded-pad", OnNewDecodedPad, new_decoded_pad_delegate, value);
|
||||
}
|
||||
|
||||
remove {
|
||||
new_decoded_pad_delegate = BindingHelper.RemoveProxySignalDelegate (this,
|
||||
"new-decoded-pad", OnNewDecodedPad, new_decoded_pad_delegate, value);
|
||||
}
|
||||
}
|
||||
|
8
gstreamer-sharp/baseplugins/decodebin.metadata
Normal file
8
gstreamer-sharp/baseplugins/decodebin.metadata
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0"?>
|
||||
<metadata>
|
||||
<attr path="/element/element-signals/signal[1]/params/type[1]" name="name">Pad</attr>
|
||||
<attr path="/element/element-signals/signal[1]/params/type[2]" name="name">Last</attr>
|
||||
<attr path="/element/element-signals/signal[2]/params/type[1]" name="name">Pad</attr>
|
||||
<attr path="/element/element-signals/signal[3]/params/type[1]" name="name">Pad</attr>
|
||||
<attr path="/element/element-signals/signal[3]/params/type[2]" name="name">Caps</attr>
|
||||
</metadata>
|
|
@ -3,8 +3,8 @@ ELEMENTS = capsfilter typefind
|
|||
|
||||
NAMESPACE = Gst.CorePlugins
|
||||
INSPECT_FILES = $(patsubst %,inspect/%.raw,$(ELEMENTS))
|
||||
CUSTOM_FILES = typefind.custom
|
||||
METADATA_FILES =
|
||||
CUSTOM_FILES =
|
||||
METADATA_FILES = typefind.metadata
|
||||
CS_FILES = $(patsubst %,%.cs,$(ELEMENTS))
|
||||
XML_FILES = $(patsubst %,%.xml,$(ELEMENTS))
|
||||
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
public delegate void HaveTypeHandler (object o, HaveTypeArgs args);
|
||||
|
||||
public class HaveTypeArgs : GLib.SignalArgs {
|
||||
public uint Probability {
|
||||
get {
|
||||
return (uint) Args[0];
|
||||
}
|
||||
}
|
||||
|
||||
public Gst.Caps Caps {
|
||||
get {
|
||||
return (Gst.Caps) Args[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Delegate have_type_delegate;
|
||||
|
||||
protected virtual void OnHaveType (object o, GLib.SignalArgs args) {
|
||||
BindingHelper.InvokeProxySignalDelegate (have_type_delegate, typeof (HaveTypeArgs), o, args);
|
||||
}
|
||||
|
||||
public event HaveTypeHandler HaveType {
|
||||
add {
|
||||
have_type_delegate = BindingHelper.AddProxySignalDelegate (this, "have-type",
|
||||
OnHaveType, have_type_delegate, value);
|
||||
}
|
||||
|
||||
remove {
|
||||
have_type_delegate = BindingHelper.RemoveProxySignalDelegate (this, "have-type",
|
||||
OnHaveType, have_type_delegate, value);
|
||||
}
|
||||
}
|
||||
|
5
gstreamer-sharp/coreplugins/typefind.metadata
Normal file
5
gstreamer-sharp/coreplugins/typefind.metadata
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0"?>
|
||||
<metadata>
|
||||
<attr path="/element/element-signals/signal[1]/params/type[1]" name="name">Probability</attr>
|
||||
<attr path="/element/element-signals/signal[1]/params/type[2]" name="name">Caps</attr>
|
||||
</metadata>
|
Loading…
Reference in a new issue