// vim: set filetype=c : // // Delegates.generated.cs: // // Authors: // Rolf Bjarne Kvinge // // Copyright 2013-2014 Xamarin Inc. // /* * This file was generated from Delegates.cs.t4, any modifications will be lost once this file is re-generated. */ <#@ include file="delegates.t4" #> #if !COREBUILD using System; using System.Collections.Generic; using System.Reflection; using System.Runtime.InteropServices; using Foundation; using Registrar; namespace ObjCRuntime { public unsafe partial class Runtime { <# foreach (var d in delegates) { #> internal delegate <#= d.ReturnType.MType #> <#= d.SimpleEntryPoint #>_delegate (<#= d.MArgumentSignature #>); <# } #> internal struct Delegates { <# foreach (var d in delegates) { #> public IntPtr <#= d.SimpleEntryPoint #>; <# } #> } <# foreach (var d in delegates) { #> [MonoPInvokeCallback (typeof (<#= d.SimpleEntryPoint #>_delegate))] static <#= d.ReturnType.MType #> <#= d.SimpleEntryPoint #> (<#= d.MArgumentSignature #>) <# if (d.ExceptionHandling) { #> { exception_gchandle = IntPtr.Zero; try { <# if (string.IsNullOrEmpty (d.WrappedManagedFunction)) { #> throw new NotImplementedException (); <# } else { #> <# if (d.ReturnType.MType != "void") { #>return <# } #><#=d.WrappedManagedFunction#> (<#=d.MArgumentNames#>); <# } #> } catch (Exception ex) { var handle = GCHandle.Alloc (ex, GCHandleType.Normal); exception_gchandle = GCHandle.ToIntPtr (handle); <# if (d.SimpleEntryPoint == "get_nsobject_with_type") { #> created = false; <# } #> <# if (d.ReturnType.MType != "void") { #> return default (<#= d.ReturnType.MType #>); <# } #> } } <# } else { #> { <# if (string.IsNullOrEmpty (d.WrappedManagedFunction)) { #> throw new NotImplementedException (); <# } else { #> <# if (d.ReturnType.MType != "void") { #>return <# } #><#=d.WrappedManagedFunction#> (<#=d.MArgumentNames#>); <# } #> } <# } #> <# } #> [BindingImpl (BindingImplOptions.Optimizable)] // To inline the Runtime.DynamicRegistrationSupported code if possible. static void RegisterDelegates (InitializationOptions* options) { <# foreach (var d in delegates) { if (d.OnlyDynamicUsage) continue; #> options->Delegates-><#= d.SimpleEntryPoint #> = GetFunctionPointer (new <#= d.SimpleEntryPoint #>_delegate (<#= d.SimpleEntryPoint #>)); <# } #> // The linker will remove this condition (and the subsequent method call) if possible if (DynamicRegistrationSupported) RegisterDelegatesDynamic (options); } static void RegisterDelegatesDynamic (InitializationOptions* options) { <# foreach (var d in delegates) { if (!d.OnlyDynamicUsage) continue; #> options->Delegates-><#= d.SimpleEntryPoint #> = GetFunctionPointer (new <#= d.SimpleEntryPoint #>_delegate (<#= d.SimpleEntryPoint #>)); <# } #> } } } #endif