diff --git a/ext/gir-files b/ext/gir-files index 1714dab0a..3bfb2db3e 160000 --- a/ext/gir-files +++ b/ext/gir-files @@ -1 +1 @@ -Subproject commit 1714dab0af4c232c3ab4ee8719f2e176f3eb2d57 +Subproject commit 3bfb2db3eb86c4edacf52f659b395beb8a2697ab diff --git a/src/Generation/Generator/Renderer/Internal/Callback/CallbackDelegate.cs b/src/Generation/Generator/Renderer/Internal/Callback/CallbackDelegate.cs index a6954d9e7..0b11a6948 100644 --- a/src/Generation/Generator/Renderer/Internal/Callback/CallbackDelegate.cs +++ b/src/Generation/Generator/Renderer/Internal/Callback/CallbackDelegate.cs @@ -24,7 +24,7 @@ namespace {Namespace.GetInternalName(callback.Namespace)} } catch (Exception ex) { - Log.Warning($"Did not generate callback delegatre '{callback.Name}': {ex.Message}"); + Log.Warning($"Did not generate callback delegate '{callback.Name}': {ex.Message}"); return string.Empty; } diff --git a/src/Generation/Generator/Renderer/Internal/Parameter/CallbackParameters.cs b/src/Generation/Generator/Renderer/Internal/Parameter/CallbackParameters.cs index 3642783fe..305f8cef9 100644 --- a/src/Generation/Generator/Renderer/Internal/Parameter/CallbackParameters.cs +++ b/src/Generation/Generator/Renderer/Internal/Parameter/CallbackParameters.cs @@ -37,6 +37,7 @@ internal static class CallbackParameters new Parameter.RecordGLibPtrArray(), new Parameter.String(), new Parameter.Union(), + new Parameter.UnionArray(), new Parameter.UnsignedPointer(), new Parameter.Utf8StringArrayCallback(), new Parameter.Void(), diff --git a/src/Generation/Generator/Renderer/Internal/Parameter/Converter/UnionArray.cs b/src/Generation/Generator/Renderer/Internal/Parameter/Converter/UnionArray.cs new file mode 100644 index 000000000..918701dfb --- /dev/null +++ b/src/Generation/Generator/Renderer/Internal/Parameter/Converter/UnionArray.cs @@ -0,0 +1,39 @@ +namespace Generator.Renderer.Internal.Parameter; + +internal class UnionArray : ParameterConverter +{ + public bool Supports(GirModel.AnyType anyType) + { + return anyType.IsArray(); + } + + public RenderableParameter Convert(GirModel.Parameter parameter) + { + if (parameter.AnyTypeOrVarArgs.AsT0.AsT1.IsPointer) + return PointerArray(parameter); + + return DataArray(parameter); + } + + private static RenderableParameter PointerArray(GirModel.Parameter parameter) + { + return new RenderableParameter( + Attribute: string.Empty, + Direction: string.Empty, + NullableTypeName: $"ref {Model.Type.Pointer}", + Name: Model.Parameter.GetName(parameter) + ); + } + + private static RenderableParameter DataArray(GirModel.Parameter parameter) + { + var union = (GirModel.Union) parameter.AnyTypeOrVarArgs.AsT0.AsT1.AnyType.AsT0; + + return new RenderableParameter( + Attribute: string.Empty, + Direction: string.Empty, + NullableTypeName: Model.Union.GetFullyQualifiedInternalStructName(union) + "[]", + Name: Model.Parameter.GetName(parameter) + ); + } +} diff --git a/src/Generation/Generator/Renderer/Internal/Parameter/Parameters.cs b/src/Generation/Generator/Renderer/Internal/Parameter/Parameters.cs index e82a16601..31a552824 100644 --- a/src/Generation/Generator/Renderer/Internal/Parameter/Parameters.cs +++ b/src/Generation/Generator/Renderer/Internal/Parameter/Parameters.cs @@ -42,6 +42,7 @@ internal static class Parameters new Parameter.String(), new Parameter.StringGLibPtrArray(), new Parameter.Union(), + new Parameter.UnionArray(), new Parameter.UnsignedPointer(), new Parameter.Utf8StringArray(), new Parameter.Void(), diff --git a/src/Generation/Generator/Renderer/Internal/ParameterToManagedExpression/Converter/Record.cs b/src/Generation/Generator/Renderer/Internal/ParameterToManagedExpression/Converter/Record.cs index 42a96df58..421b7a6af 100644 --- a/src/Generation/Generator/Renderer/Internal/ParameterToManagedExpression/Converter/Record.cs +++ b/src/Generation/Generator/Renderer/Internal/ParameterToManagedExpression/Converter/Record.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using GirModel; namespace Generator.Renderer.Internal.ParameterToManagedExpressions; @@ -27,12 +28,31 @@ private static void ErrorRecord(ParameterToManagedData parameterData) private static void RegularRecord(ParameterToManagedData parameterData) { - if (parameterData.Parameter.Direction != GirModel.Direction.In) - throw new NotImplementedException($"{parameterData.Parameter.AnyTypeOrVarArgs}: record with direction != in not yet supported"); - if (!parameterData.Parameter.IsPointer) throw new NotImplementedException($"Unpointed record parameter {parameterData.Parameter.Name} ({parameterData.Parameter.AnyTypeOrVarArgs}) can not yet be converted to managed"); + switch (parameterData.Parameter.Direction) + { + case Direction.In: + InRecord(parameterData); + break; + case Direction.Out: + OutRecord(parameterData); + break; + default: + throw new NotImplementedException($"{parameterData.Parameter.AnyTypeOrVarArgs}: record with direction {parameterData.Parameter.Direction} not yet supported"); + } + } + + private static void OutRecord(ParameterToManagedData parameterData) + { + var parameterName = Model.Parameter.GetName(parameterData.Parameter); + parameterData.SetSignatureName(parameterName); + parameterData.SetCallName("out " + parameterName); + } + + private static void InRecord(ParameterToManagedData parameterData) + { var record = (GirModel.Record) parameterData.Parameter.AnyTypeOrVarArgs.AsT0.AsT0; var ownedHandle = parameterData.Parameter.Transfer == GirModel.Transfer.Full; var variableName = Model.Parameter.GetConvertedName(parameterData.Parameter); diff --git a/src/Generation/Generator/Renderer/Public/Parameter/Converter/Record.cs b/src/Generation/Generator/Renderer/Public/Parameter/Converter/Record.cs index 107c70d22..ed1484b1c 100644 --- a/src/Generation/Generator/Renderer/Public/Parameter/Converter/Record.cs +++ b/src/Generation/Generator/Renderer/Public/Parameter/Converter/Record.cs @@ -1,4 +1,6 @@ -namespace Generator.Renderer.Public.Parameter; +using System; + +namespace Generator.Renderer.Public.Parameter; internal class Record : ParameterConverter { @@ -8,24 +10,30 @@ public bool Supports(GirModel.AnyType anyType) } public ParameterTypeData Create(GirModel.Parameter parameter) + { + return parameter.Direction switch + { + GirModel.Direction.In => InRecord(parameter), + GirModel.Direction.Out => OutRecord(parameter), + _ => throw new Exception($"Unsupported record direction {parameter.Direction}") + }; + } + + private ParameterTypeData OutRecord(GirModel.Parameter parameter) { return new ParameterTypeData( - Direction: GetDirection(parameter), - NullableTypeName: GetNullableTypeName(parameter) + Direction: ParameterDirection.Out(), + NullableTypeName: Model.Type.Pointer ); } - private static string GetNullableTypeName(GirModel.Parameter parameter) + private static ParameterTypeData InRecord(GirModel.Parameter parameter) { var type = (GirModel.Record) parameter.AnyTypeOrVarArgs.AsT0.AsT0; - return Model.ComplexType.GetFullyQualified(type) + Nullable.Render(parameter); - } - private static string GetDirection(GirModel.Parameter parameter) => parameter switch - { - { Direction: GirModel.Direction.InOut } => ParameterDirection.Ref(), - { Direction: GirModel.Direction.Out, CallerAllocates: true } => ParameterDirection.Ref(), - { Direction: GirModel.Direction.Out } => ParameterDirection.Out(), - _ => ParameterDirection.In() - }; + return new ParameterTypeData( + Direction: ParameterDirection.In(), + NullableTypeName: Model.ComplexType.GetFullyQualified(type) + Nullable.Render(parameter) + ); + } } diff --git a/src/Generation/GirModel/GirModel.csproj b/src/Generation/GirModel/GirModel.csproj index 90baabd65..733180dfc 100644 --- a/src/Generation/GirModel/GirModel.csproj +++ b/src/Generation/GirModel/GirModel.csproj @@ -3,6 +3,6 @@ GirModule - + diff --git a/src/GirCore.Logging.props b/src/GirCore.Logging.props index 0e760a82e..c1c9df20d 100644 --- a/src/GirCore.Logging.props +++ b/src/GirCore.Logging.props @@ -1,7 +1,7 @@ - - + + \ No newline at end of file diff --git a/src/GirCore.Testing.props b/src/GirCore.Testing.props index ccb90a20d..023c16660 100644 --- a/src/GirCore.Testing.props +++ b/src/GirCore.Testing.props @@ -6,7 +6,7 @@ - + diff --git a/src/Libs/Gdk-4.0/Internal/DragSurfaceSizeHandle.cs b/src/Libs/Gdk-4.0/Internal/DragSurfaceSizeHandle.cs new file mode 100644 index 000000000..fc130bd23 --- /dev/null +++ b/src/Libs/Gdk-4.0/Internal/DragSurfaceSizeHandle.cs @@ -0,0 +1,29 @@ +using System; + +namespace Gdk.Internal; + +public partial class DragSurfaceSizeHandle +{ + public partial DragSurfaceSizeOwnedHandle OwnedCopy() + { + throw new NotImplementedException(); + } + + public partial DragSurfaceSizeUnownedHandle UnownedCopy() + { + throw new NotImplementedException(); + } +} + +public partial class DragSurfaceSizeOwnedHandle +{ + public static partial DragSurfaceSizeOwnedHandle FromUnowned(IntPtr ptr) + { + throw new NotImplementedException(); + } + + protected override partial bool ReleaseHandle() + { + throw new NotImplementedException(); + } +} diff --git a/src/Libs/Gst-1.0/Internal/DebugMessageHandle.cs b/src/Libs/Gst-1.0/Internal/DebugMessageHandle.cs new file mode 100644 index 000000000..616eb9d2d --- /dev/null +++ b/src/Libs/Gst-1.0/Internal/DebugMessageHandle.cs @@ -0,0 +1,29 @@ +using System; + +namespace Gst.Internal; + +public partial class DebugMessageHandle +{ + public partial DebugMessageOwnedHandle OwnedCopy() + { + throw new NotImplementedException(); + } + + public partial DebugMessageUnownedHandle UnownedCopy() + { + throw new NotImplementedException(); + } +} + +public partial class DebugMessageOwnedHandle +{ + public static partial DebugMessageOwnedHandle FromUnowned(IntPtr ptr) + { + throw new NotImplementedException(); + } + + protected override partial bool ReleaseHandle() + { + throw new NotImplementedException(); + } +} diff --git a/src/Libs/Gst-1.0/Internal/PollHandle.cs b/src/Libs/Gst-1.0/Internal/PollHandle.cs new file mode 100644 index 000000000..17af70c30 --- /dev/null +++ b/src/Libs/Gst-1.0/Internal/PollHandle.cs @@ -0,0 +1,34 @@ +using System; +using System.Runtime.InteropServices; + +namespace Gst.Internal; + +public partial class PollHandle +{ + public partial PollOwnedHandle OwnedCopy() + { + throw new NotImplementedException(); + } + + public partial PollUnownedHandle UnownedCopy() + { + throw new NotImplementedException(); + } +} + +public partial class PollOwnedHandle +{ + [DllImport(ImportResolver.Library, EntryPoint = "gst_poll_free")] + private static extern void Free(IntPtr set); + + public static partial PollOwnedHandle FromUnowned(IntPtr ptr) + { + throw new NotImplementedException(); + } + + protected override partial bool ReleaseHandle() + { + Free(handle); + return true; + } +} diff --git a/src/Libs/GstAudio-1.0/Internal/AudioChannelMixerHandle.cs b/src/Libs/GstAudio-1.0/Internal/AudioChannelMixerHandle.cs new file mode 100644 index 000000000..1343362c6 --- /dev/null +++ b/src/Libs/GstAudio-1.0/Internal/AudioChannelMixerHandle.cs @@ -0,0 +1,34 @@ +using System; +using System.Runtime.InteropServices; + +namespace GstAudio.Internal; + +public partial class AudioChannelMixerHandle +{ + public partial AudioChannelMixerOwnedHandle OwnedCopy() + { + throw new NotImplementedException(); + } + + public partial AudioChannelMixerUnownedHandle UnownedCopy() + { + throw new NotImplementedException(); + } +} + +public partial class AudioChannelMixerOwnedHandle +{ + [DllImport(ImportResolver.Library, EntryPoint = "gst_audio_channel_mixer_free")] + private static extern void Free(IntPtr data); + + public static partial AudioChannelMixerOwnedHandle FromUnowned(IntPtr ptr) + { + throw new NotImplementedException(); + } + + protected override partial bool ReleaseHandle() + { + Free(handle); + return true; + } +} diff --git a/src/Libs/GstAudio-1.0/Internal/AudioQuantizeHandle.cs b/src/Libs/GstAudio-1.0/Internal/AudioQuantizeHandle.cs new file mode 100644 index 000000000..8e306b4d8 --- /dev/null +++ b/src/Libs/GstAudio-1.0/Internal/AudioQuantizeHandle.cs @@ -0,0 +1,34 @@ +using System; +using System.Runtime.InteropServices; + +namespace GstAudio.Internal; + +public partial class AudioQuantizeHandle +{ + public partial AudioQuantizeOwnedHandle OwnedCopy() + { + throw new NotImplementedException(); + } + + public partial AudioQuantizeUnownedHandle UnownedCopy() + { + throw new NotImplementedException(); + } +} + +public partial class AudioQuantizeOwnedHandle +{ + [DllImport(ImportResolver.Library, EntryPoint = "gst_audio_quantize_free")] + private static extern void Free(IntPtr data); + + public static partial AudioQuantizeOwnedHandle FromUnowned(IntPtr ptr) + { + throw new NotImplementedException(); + } + + protected override partial bool ReleaseHandle() + { + Free(handle); + return true; + } +} diff --git a/src/Libs/GstAudio-1.0/Internal/AudioResamplerHandle.cs b/src/Libs/GstAudio-1.0/Internal/AudioResamplerHandle.cs new file mode 100644 index 000000000..070345682 --- /dev/null +++ b/src/Libs/GstAudio-1.0/Internal/AudioResamplerHandle.cs @@ -0,0 +1,34 @@ +using System; +using System.Runtime.InteropServices; + +namespace GstAudio.Internal; + +public partial class AudioResamplerHandle +{ + public partial AudioResamplerOwnedHandle OwnedCopy() + { + throw new NotImplementedException(); + } + + public partial AudioResamplerUnownedHandle UnownedCopy() + { + throw new NotImplementedException(); + } +} + +public partial class AudioResamplerOwnedHandle +{ + [DllImport(ImportResolver.Library, EntryPoint = "gst_audio_resampler_free")] + private static extern void Free(IntPtr data); + + public static partial AudioResamplerOwnedHandle FromUnowned(IntPtr ptr) + { + throw new NotImplementedException(); + } + + protected override partial bool ReleaseHandle() + { + Free(handle); + return true; + } +} diff --git a/src/Libs/GstBase-1.0/Internal/QueueArrayHandle.cs b/src/Libs/GstBase-1.0/Internal/QueueArrayHandle.cs new file mode 100644 index 000000000..1e9bbb8a3 --- /dev/null +++ b/src/Libs/GstBase-1.0/Internal/QueueArrayHandle.cs @@ -0,0 +1,34 @@ +using System; +using System.Runtime.InteropServices; + +namespace GstBase.Internal; + +public partial class QueueArrayHandle +{ + public partial QueueArrayOwnedHandle OwnedCopy() + { + throw new NotImplementedException(); + } + + public partial QueueArrayUnownedHandle UnownedCopy() + { + throw new NotImplementedException(); + } +} + +public partial class QueueArrayOwnedHandle +{ + [DllImport(ImportResolver.Library, EntryPoint = "gst_queue_array_free")] + private static extern void Free(IntPtr array); + + public static partial QueueArrayOwnedHandle FromUnowned(IntPtr ptr) + { + throw new NotImplementedException(); + } + + protected override partial bool ReleaseHandle() + { + Free(handle); + return true; + } +} diff --git a/src/Libs/GstBase-1.0/Internal/TypeFindDataHandle.cs b/src/Libs/GstBase-1.0/Internal/TypeFindDataHandle.cs new file mode 100644 index 000000000..e00b28be0 --- /dev/null +++ b/src/Libs/GstBase-1.0/Internal/TypeFindDataHandle.cs @@ -0,0 +1,34 @@ +using System; +using System.Runtime.InteropServices; + +namespace GstBase.Internal; + +public partial class TypeFindDataHandle +{ + public partial TypeFindDataOwnedHandle OwnedCopy() + { + throw new NotImplementedException(); + } + + public partial TypeFindDataUnownedHandle UnownedCopy() + { + throw new NotImplementedException(); + } +} + +public partial class TypeFindDataOwnedHandle +{ + [DllImport(ImportResolver.Library, EntryPoint = "gst_type_find_data_free")] + private static extern void Free(IntPtr data); + + public static partial TypeFindDataOwnedHandle FromUnowned(IntPtr ptr) + { + throw new NotImplementedException(); + } + + protected override partial bool ReleaseHandle() + { + Free(handle); + return true; + } +} diff --git a/src/Libs/GstVideo-1.0/Internal/VideoChromaResampleHandle.cs b/src/Libs/GstVideo-1.0/Internal/VideoChromaResampleHandle.cs new file mode 100644 index 000000000..dc9587fdb --- /dev/null +++ b/src/Libs/GstVideo-1.0/Internal/VideoChromaResampleHandle.cs @@ -0,0 +1,34 @@ +using System; +using System.Runtime.InteropServices; + +namespace GstVideo.Internal; + +public partial class VideoChromaResampleHandle +{ + public partial VideoChromaResampleOwnedHandle OwnedCopy() + { + throw new NotImplementedException(); + } + + public partial VideoChromaResampleUnownedHandle UnownedCopy() + { + throw new NotImplementedException(); + } +} + +public partial class VideoChromaResampleOwnedHandle +{ + [DllImport(ImportResolver.Library, EntryPoint = "gst_video_chroma_resample_free")] + private static extern void Free(IntPtr data); + + public static partial VideoChromaResampleOwnedHandle FromUnowned(IntPtr ptr) + { + throw new NotImplementedException(); + } + + protected override partial bool ReleaseHandle() + { + Free(handle); + return true; + } +} diff --git a/src/Libs/GstVideo-1.0/Internal/VideoConverterHandle.cs b/src/Libs/GstVideo-1.0/Internal/VideoConverterHandle.cs new file mode 100644 index 000000000..7ce919bb2 --- /dev/null +++ b/src/Libs/GstVideo-1.0/Internal/VideoConverterHandle.cs @@ -0,0 +1,34 @@ +using System; +using System.Runtime.InteropServices; + +namespace GstVideo.Internal; + +public partial class VideoConverterHandle +{ + public partial VideoConverterOwnedHandle OwnedCopy() + { + throw new NotImplementedException(); + } + + public partial VideoConverterUnownedHandle UnownedCopy() + { + throw new NotImplementedException(); + } +} + +public partial class VideoConverterOwnedHandle +{ + [DllImport(ImportResolver.Library, EntryPoint = "gst_video_converter_free")] + private static extern void Free(IntPtr data); + + public static partial VideoConverterOwnedHandle FromUnowned(IntPtr ptr) + { + throw new NotImplementedException(); + } + + protected override partial bool ReleaseHandle() + { + Free(handle); + return true; + } +} diff --git a/src/Libs/GstVideo-1.0/Internal/VideoDitherHandle.cs b/src/Libs/GstVideo-1.0/Internal/VideoDitherHandle.cs new file mode 100644 index 000000000..136edceeb --- /dev/null +++ b/src/Libs/GstVideo-1.0/Internal/VideoDitherHandle.cs @@ -0,0 +1,34 @@ +using System; +using System.Runtime.InteropServices; + +namespace GstVideo.Internal; + +public partial class VideoDitherHandle +{ + public partial VideoDitherOwnedHandle OwnedCopy() + { + throw new NotImplementedException(); + } + + public partial VideoDitherUnownedHandle UnownedCopy() + { + throw new NotImplementedException(); + } +} + +public partial class VideoDitherOwnedHandle +{ + [DllImport(ImportResolver.Library, EntryPoint = "gst_video_dither_free")] + private static extern void Free(IntPtr data); + + public static partial VideoDitherOwnedHandle FromUnowned(IntPtr ptr) + { + throw new NotImplementedException(); + } + + protected override partial bool ReleaseHandle() + { + Free(handle); + return true; + } +} diff --git a/src/Libs/GstVideo-1.0/Internal/VideoScalerHandle.cs b/src/Libs/GstVideo-1.0/Internal/VideoScalerHandle.cs new file mode 100644 index 000000000..fdfba9b76 --- /dev/null +++ b/src/Libs/GstVideo-1.0/Internal/VideoScalerHandle.cs @@ -0,0 +1,34 @@ +using System; +using System.Runtime.InteropServices; + +namespace GstVideo.Internal; + +public partial class VideoScalerHandle +{ + public partial VideoScalerOwnedHandle OwnedCopy() + { + throw new NotImplementedException(); + } + + public partial VideoScalerUnownedHandle UnownedCopy() + { + throw new NotImplementedException(); + } +} + +public partial class VideoScalerOwnedHandle +{ + [DllImport(ImportResolver.Library, EntryPoint = "gst_video_scaler_free")] + private static extern void Free(IntPtr data); + + public static partial VideoScalerOwnedHandle FromUnowned(IntPtr ptr) + { + throw new NotImplementedException(); + } + + protected override partial bool ReleaseHandle() + { + Free(handle); + return true; + } +}