• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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          public NativeMethods(DllImportsFromSharedLib_x86 unusedInstance)
67          {
68              % for method in get_native_methods():
69              this.${method['name']} = DllImportsFromSharedLib_x86.${method['name']};
70              % endfor
71          }
72
73          public NativeMethods(DllImportsFromSharedLib_x64 unusedInstance)
74          {
75              % for method in get_native_methods():
76              this.${method['name']} = DllImportsFromSharedLib_x64.${method['name']};
77              % endfor
78          }
79
80          public NativeMethods(DllImportsFromSharedLib_x86_dll unusedInstance)
81          {
82              % for method in get_native_methods():
83              this.${method['name']} = DllImportsFromSharedLib_x86_dll.${method['name']};
84              % endfor
85          }
86
87          public NativeMethods(DllImportsFromSharedLib_x64_dll unusedInstance)
88          {
89              % for method in get_native_methods():
90              this.${method['name']} = DllImportsFromSharedLib_x64_dll.${method['name']};
91              % endfor
92          }
93
94          /// <summary>
95          /// Delegate types for all published native methods. Declared under inner class to prevent scope pollution.
96          /// </summary>
97          public class Delegates
98          {
99              % for method in get_native_methods():
100              public delegate ${method['returntype']} ${method['name']}_delegate(${method['params']});${method['comment']}
101              % endfor
102          }
103
104          /// <summary>
105          /// grpc_csharp_ext used as a static library (e.g Unity iOS).
106          /// </summary>
107          internal class DllImportsFromStaticLib
108          {
109              private const string ImportName = "__Internal";
110              % for method in get_native_methods():
111
112              [DllImport(ImportName)]
113              public static extern ${method['returntype']} ${method['name']}(${method['params']});
114              % endfor
115          }
116
117          /// <summary>
118          /// grpc_csharp_ext used as a shared library (e.g on Unity Standalone and Android).
119          /// </summary>
120          internal class DllImportsFromSharedLib
121          {
122              private const string ImportName = "grpc_csharp_ext";
123              % for method in get_native_methods():
124
125              [DllImport(ImportName)]
126              public static extern ${method['returntype']} ${method['name']}(${method['params']});
127              % endfor
128          }
129
130          /// <summary>
131          /// grpc_csharp_ext used as a shared library (with x86 suffix)
132          /// </summary>
133          internal class DllImportsFromSharedLib_x86
134          {
135              private const string ImportName = "grpc_csharp_ext.x86";
136              % for method in get_native_methods():
137
138              [DllImport(ImportName)]
139              public static extern ${method['returntype']} ${method['name']}(${method['params']});
140              % endfor
141          }
142
143          /// <summary>
144          /// grpc_csharp_ext used as a shared library (with x64 suffix)
145          /// </summary>
146          internal class DllImportsFromSharedLib_x64
147          {
148              private const string ImportName = "grpc_csharp_ext.x64";
149              % for method in get_native_methods():
150
151              [DllImport(ImportName)]
152              public static extern ${method['returntype']} ${method['name']}(${method['params']});
153              % endfor
154          }
155
156          /// <summary>
157          /// grpc_csharp_ext used as a shared library (with x86.dll suffix)
158          /// </summary>
159          internal class DllImportsFromSharedLib_x86_dll
160          {
161              private const string ImportName = "grpc_csharp_ext.x86.dll";
162              % for method in get_native_methods():
163
164              [DllImport(ImportName)]
165              public static extern ${method['returntype']} ${method['name']}(${method['params']});
166              % endfor
167          }
168
169          /// <summary>
170          /// grpc_csharp_ext used as a shared library (with x64.dll suffix)
171          /// </summary>
172          internal class DllImportsFromSharedLib_x64_dll
173          {
174              private const string ImportName = "grpc_csharp_ext.x64.dll";
175              % for method in get_native_methods():
176
177              [DllImport(ImportName)]
178              public static extern ${method['returntype']} ${method['name']}(${method['params']});
179              % endfor
180          }
181      }
182  }
183