1%YAML 1.2 2--- | 3 <%namespace file="native_methods.include" import="get_native_methods"/> 4 #region Copyright notice and license 5 6 // Copyright 2015 gRPC authors. 7 // 8 // Licensed under the Apache License, Version 2.0 (the "License"); 9 // you may not use this file except in compliance with the License. 10 // You may obtain a copy of the License at 11 // 12 // http://www.apache.org/licenses/LICENSE-2.0 13 // 14 // Unless required by applicable law or agreed to in writing, software 15 // distributed under the License is distributed on an "AS IS" BASIS, 16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 // See the License for the specific language governing permissions and 18 // limitations under the License. 19 20 #endregion 21 22 using System; 23 using System.Collections.Concurrent; 24 using System.Diagnostics; 25 using System.IO; 26 using System.Reflection; 27 using System.Runtime.InteropServices; 28 using System.Threading; 29 30 using Grpc.Core.Logging; 31 using Grpc.Core.Utils; 32 33 namespace Grpc.Core.Internal 34 { 35 internal partial class NativeMethods 36 { 37 #region Native methods 38 39 % for method in get_native_methods(): 40 public readonly Delegates.${method['name']}_delegate ${method['name']}; 41 % endfor 42 43 #endregion 44 45 public NativeMethods(UnmanagedLibrary library) 46 { 47 % for method in get_native_methods(): 48 this.${method['name']} = GetMethodDelegate<Delegates.${method['name']}_delegate>(library); 49 % endfor 50 } 51 52 public NativeMethods(DllImportsFromStaticLib unusedInstance) 53 { 54 % for method in get_native_methods(): 55 this.${method['name']} = DllImportsFromStaticLib.${method['name']}; 56 % endfor 57 } 58 59 public NativeMethods(DllImportsFromSharedLib unusedInstance) 60 { 61 % for method in get_native_methods(): 62 this.${method['name']} = DllImportsFromSharedLib.${method['name']}; 63 % endfor 64 } 65 66 /// <summary> 67 /// Delegate types for all published native methods. Declared under inner class to prevent scope pollution. 68 /// </summary> 69 public class Delegates 70 { 71 % for method in get_native_methods(): 72 public delegate ${method['returntype']} ${method['name']}_delegate(${method['params']});${method['comment']} 73 % endfor 74 } 75 76 /// <summary> 77 /// grpc_csharp_ext used as a static library (e.g Unity iOS). 78 /// </summary> 79 internal class DllImportsFromStaticLib 80 { 81 private const string ImportName = "__Internal"; 82 % for method in get_native_methods(): 83 84 [DllImport(ImportName)] 85 public static extern ${method['returntype']} ${method['name']}(${method['params']}); 86 % endfor 87 } 88 89 /// <summary> 90 /// grpc_csharp_ext used a shared library (e.g on Unity Standalone and Android). 91 /// </summary> 92 internal class DllImportsFromSharedLib 93 { 94 private const string ImportName = "grpc_csharp_ext"; 95 % for method in get_native_methods(): 96 97 [DllImport(ImportName)] 98 public static extern ${method['returntype']} ${method['name']}(${method['params']}); 99 % endfor 100 } 101 } 102 } 103