blob: b79d7c75652122e44d7cbf94d119413c0ca2bc32 [file] [log] [blame]
Jan Tattermuschafab5412016-01-12 17:57:25 -08001#region Copyright notice and license
2
3// Copyright 2015, Google Inc.
4// All rights reserved.
5//
6// Redistribution and use in source and binary forms, with or without
7// modification, are permitted provided that the following conditions are
8// met:
9//
10// * Redistributions of source code must retain the above copyright
11// notice, this list of conditions and the following disclaimer.
12// * Redistributions in binary form must reproduce the above
13// copyright notice, this list of conditions and the following disclaimer
14// in the documentation and/or other materials provided with the
15// distribution.
16// * Neither the name of Google Inc. nor the names of its
17// contributors may be used to endorse or promote products derived from
18// this software without specific prior written permission.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32#endregion
33
34using System;
35using System.Collections.Concurrent;
36using System.Diagnostics;
37using System.IO;
38using System.Reflection;
39using System.Runtime.InteropServices;
40using System.Threading;
41
42using Grpc.Core.Logging;
43using Grpc.Core.Utils;
44
45namespace Grpc.Core.Internal
46{
47 /// <summary>
48 /// Provides access to all native methods provided by <c>NativeExtension</c>.
49 /// An extra level of indirection is added to P/Invoke calls to allow intelligent loading
50 /// of the right configuration of the native extension based on current platform, architecture etc.
51 /// </summary>
52 internal class NativeMethods
53 {
54 #region Native methods
55
56 public readonly Delegates.grpcsharp_init_delegate grpcsharp_init;
57 public readonly Delegates.grpcsharp_shutdown_delegate grpcsharp_shutdown;
58 public readonly Delegates.grpcsharp_version_string_delegate grpcsharp_version_string;
59
60 public readonly Delegates.grpcsharp_batch_context_create_delegate grpcsharp_batch_context_create;
61 public readonly Delegates.grpcsharp_batch_context_recv_initial_metadata_delegate grpcsharp_batch_context_recv_initial_metadata;
62 public readonly Delegates.grpcsharp_batch_context_recv_message_length_delegate grpcsharp_batch_context_recv_message_length;
63 public readonly Delegates.grpcsharp_batch_context_recv_message_to_buffer_delegate grpcsharp_batch_context_recv_message_to_buffer;
64 public readonly Delegates.grpcsharp_batch_context_recv_status_on_client_status_delegate grpcsharp_batch_context_recv_status_on_client_status;
65 public readonly Delegates.grpcsharp_batch_context_recv_status_on_client_details_delegate grpcsharp_batch_context_recv_status_on_client_details;
66 public readonly Delegates.grpcsharp_batch_context_recv_status_on_client_trailing_metadata_delegate grpcsharp_batch_context_recv_status_on_client_trailing_metadata;
67 public readonly Delegates.grpcsharp_batch_context_server_rpc_new_call_delegate grpcsharp_batch_context_server_rpc_new_call;
68 public readonly Delegates.grpcsharp_batch_context_server_rpc_new_method_delegate grpcsharp_batch_context_server_rpc_new_method;
69 public readonly Delegates.grpcsharp_batch_context_server_rpc_new_host_delegate grpcsharp_batch_context_server_rpc_new_host;
70 public readonly Delegates.grpcsharp_batch_context_server_rpc_new_deadline_delegate grpcsharp_batch_context_server_rpc_new_deadline;
71 public readonly Delegates.grpcsharp_batch_context_server_rpc_new_request_metadata_delegate grpcsharp_batch_context_server_rpc_new_request_metadata;
72 public readonly Delegates.grpcsharp_batch_context_recv_close_on_server_cancelled_delegate grpcsharp_batch_context_recv_close_on_server_cancelled;
73 public readonly Delegates.grpcsharp_batch_context_destroy_delegate grpcsharp_batch_context_destroy;
74
75 public readonly Delegates.grpcsharp_composite_call_credentials_create_delegate grpcsharp_composite_call_credentials_create;
76 public readonly Delegates.grpcsharp_call_credentials_release_delegate grpcsharp_call_credentials_release;
77
78 public readonly Delegates.grpcsharp_call_cancel_delegate grpcsharp_call_cancel;
79 public readonly Delegates.grpcsharp_call_cancel_with_status_delegate grpcsharp_call_cancel_with_status;
80 public readonly Delegates.grpcsharp_call_start_unary_delegate grpcsharp_call_start_unary;
81 public readonly Delegates.grpcsharp_call_start_client_streaming_delegate grpcsharp_call_start_client_streaming;
82 public readonly Delegates.grpcsharp_call_start_server_streaming_delegate grpcsharp_call_start_server_streaming;
83 public readonly Delegates.grpcsharp_call_start_duplex_streaming_delegate grpcsharp_call_start_duplex_streaming;
84 public readonly Delegates.grpcsharp_call_send_message_delegate grpcsharp_call_send_message;
85 public readonly Delegates.grpcsharp_call_send_close_from_client_delegate grpcsharp_call_send_close_from_client;
86 public readonly Delegates.grpcsharp_call_send_status_from_server_delegate grpcsharp_call_send_status_from_server;
87 public readonly Delegates.grpcsharp_call_recv_message_delegate grpcsharp_call_recv_message;
88 public readonly Delegates.grpcsharp_call_recv_initial_metadata_delegate grpcsharp_call_recv_initial_metadata;
89 public readonly Delegates.grpcsharp_call_start_serverside_delegate grpcsharp_call_start_serverside;
90 public readonly Delegates.grpcsharp_call_send_initial_metadata_delegate grpcsharp_call_send_initial_metadata;
91 public readonly Delegates.grpcsharp_call_set_credentials_delegate grpcsharp_call_set_credentials;
92 public readonly Delegates.grpcsharp_call_get_peer_delegate grpcsharp_call_get_peer;
93 public readonly Delegates.grpcsharp_call_destroy_delegate grpcsharp_call_destroy;
94
95 public readonly Delegates.grpcsharp_channel_args_create_delegate grpcsharp_channel_args_create;
96 public readonly Delegates.grpcsharp_channel_args_set_string_delegate grpcsharp_channel_args_set_string;
97 public readonly Delegates.grpcsharp_channel_args_set_integer_delegate grpcsharp_channel_args_set_integer;
98 public readonly Delegates.grpcsharp_channel_args_destroy_delegate grpcsharp_channel_args_destroy;
99
100 public readonly Delegates.grpcsharp_ssl_credentials_create_delegate grpcsharp_ssl_credentials_create;
101 public readonly Delegates.grpcsharp_composite_channel_credentials_create_delegate grpcsharp_composite_channel_credentials_create;
102 public readonly Delegates.grpcsharp_channel_credentials_release_delegate grpcsharp_channel_credentials_release;
103
104 public readonly Delegates.grpcsharp_insecure_channel_create_delegate grpcsharp_insecure_channel_create;
105 public readonly Delegates.grpcsharp_secure_channel_create_delegate grpcsharp_secure_channel_create;
106 public readonly Delegates.grpcsharp_channel_create_call_delegate grpcsharp_channel_create_call;
107 public readonly Delegates.grpcsharp_channel_check_connectivity_state_delegate grpcsharp_channel_check_connectivity_state;
108 public readonly Delegates.grpcsharp_channel_watch_connectivity_state_delegate grpcsharp_channel_watch_connectivity_state;
109 public readonly Delegates.grpcsharp_channel_get_target_delegate grpcsharp_channel_get_target;
110 public readonly Delegates.grpcsharp_channel_destroy_delegate grpcsharp_channel_destroy;
111
112 public readonly Delegates.grpcsharp_sizeof_grpc_event_delegate grpcsharp_sizeof_grpc_event;
113
114 public readonly Delegates.grpcsharp_completion_queue_create_delegate grpcsharp_completion_queue_create;
115 public readonly Delegates.grpcsharp_completion_queue_shutdown_delegate grpcsharp_completion_queue_shutdown;
116 public readonly Delegates.grpcsharp_completion_queue_next_delegate grpcsharp_completion_queue_next;
117 public readonly Delegates.grpcsharp_completion_queue_pluck_delegate grpcsharp_completion_queue_pluck;
118 public readonly Delegates.grpcsharp_completion_queue_destroy_delegate grpcsharp_completion_queue_destroy;
119
120 public readonly Delegates.gprsharp_free_delegate gprsharp_free;
121
122 public readonly Delegates.grpcsharp_metadata_array_create_delegate grpcsharp_metadata_array_create;
123 public readonly Delegates.grpcsharp_metadata_array_add_delegate grpcsharp_metadata_array_add;
124 public readonly Delegates.grpcsharp_metadata_array_count_delegate grpcsharp_metadata_array_count;
125 public readonly Delegates.grpcsharp_metadata_array_get_key_delegate grpcsharp_metadata_array_get_key;
126 public readonly Delegates.grpcsharp_metadata_array_get_value_delegate grpcsharp_metadata_array_get_value;
127 public readonly Delegates.grpcsharp_metadata_array_get_value_length_delegate grpcsharp_metadata_array_get_value_length;
128 public readonly Delegates.grpcsharp_metadata_array_destroy_full_delegate grpcsharp_metadata_array_destroy_full;
129
130 public readonly Delegates.grpcsharp_redirect_log_delegate grpcsharp_redirect_log;
131
132 public readonly Delegates.grpcsharp_metadata_credentials_create_from_plugin_delegate grpcsharp_metadata_credentials_create_from_plugin;
133 public readonly Delegates.grpcsharp_metadata_credentials_notify_from_plugin_delegate grpcsharp_metadata_credentials_notify_from_plugin;
134
135 public readonly Delegates.grpcsharp_ssl_server_credentials_create_delegate grpcsharp_ssl_server_credentials_create;
136 public readonly Delegates.grpcsharp_server_credentials_release_delegate grpcsharp_server_credentials_release;
137
138 public readonly Delegates.grpcsharp_server_create_delegate grpcsharp_server_create;
139 public readonly Delegates.grpcsharp_server_add_insecure_http2_port_delegate grpcsharp_server_add_insecure_http2_port;
140 public readonly Delegates.grpcsharp_server_add_secure_http2_port_delegate grpcsharp_server_add_secure_http2_port;
141 public readonly Delegates.grpcsharp_server_start_delegate grpcsharp_server_start;
142 public readonly Delegates.grpcsharp_server_request_call_delegate grpcsharp_server_request_call;
143 public readonly Delegates.grpcsharp_server_cancel_all_calls_delegate grpcsharp_server_cancel_all_calls;
144 public readonly Delegates.grpcsharp_server_shutdown_and_notify_callback_delegate grpcsharp_server_shutdown_and_notify_callback;
145 public readonly Delegates.grpcsharp_server_destroy_delegate grpcsharp_server_destroy;
146
147 public readonly Delegates.gprsharp_now_delegate gprsharp_now;
148 public readonly Delegates.gprsharp_inf_future_delegate gprsharp_inf_future;
149 public readonly Delegates.gprsharp_inf_past_delegate gprsharp_inf_past;
150 public readonly Delegates.gprsharp_convert_clock_type_delegate gprsharp_convert_clock_type;
151 public readonly Delegates.gprsharp_sizeof_timespec_delegate gprsharp_sizeof_timespec;
152
153 public readonly Delegates.grpcsharp_test_callback_delegate grpcsharp_test_callback;
154 public readonly Delegates.grpcsharp_test_nop_delegate grpcsharp_test_nop;
155
156 #endregion
157
158 public NativeMethods(UnmanagedLibrary library)
159 {
160 if (PlatformApis.IsLinux || PlatformApis.IsMacOSX)
161 {
162 this.grpcsharp_init = GetMethodDelegate<Delegates.grpcsharp_init_delegate>(library);
163 this.grpcsharp_shutdown = GetMethodDelegate<Delegates.grpcsharp_shutdown_delegate>(library);
164 this.grpcsharp_version_string = GetMethodDelegate<Delegates.grpcsharp_version_string_delegate>(library);
165
166 this.grpcsharp_batch_context_create = GetMethodDelegate<Delegates.grpcsharp_batch_context_create_delegate>(library);
167 this.grpcsharp_batch_context_recv_initial_metadata = GetMethodDelegate<Delegates.grpcsharp_batch_context_recv_initial_metadata_delegate>(library);
168 this.grpcsharp_batch_context_recv_message_length = GetMethodDelegate<Delegates.grpcsharp_batch_context_recv_message_length_delegate>(library);
169 this.grpcsharp_batch_context_recv_message_to_buffer = GetMethodDelegate<Delegates.grpcsharp_batch_context_recv_message_to_buffer_delegate>(library);
170 this.grpcsharp_batch_context_recv_status_on_client_status = GetMethodDelegate<Delegates.grpcsharp_batch_context_recv_status_on_client_status_delegate>(library);
171 this.grpcsharp_batch_context_recv_status_on_client_details = GetMethodDelegate<Delegates.grpcsharp_batch_context_recv_status_on_client_details_delegate>(library);
172 this.grpcsharp_batch_context_recv_status_on_client_trailing_metadata = GetMethodDelegate<Delegates.grpcsharp_batch_context_recv_status_on_client_trailing_metadata_delegate>(library);
173 this.grpcsharp_batch_context_server_rpc_new_call = GetMethodDelegate<Delegates.grpcsharp_batch_context_server_rpc_new_call_delegate>(library);
174 this.grpcsharp_batch_context_server_rpc_new_method = GetMethodDelegate<Delegates.grpcsharp_batch_context_server_rpc_new_method_delegate>(library);
175 this.grpcsharp_batch_context_server_rpc_new_host = GetMethodDelegate<Delegates.grpcsharp_batch_context_server_rpc_new_host_delegate>(library);
176 this.grpcsharp_batch_context_server_rpc_new_deadline = GetMethodDelegate<Delegates.grpcsharp_batch_context_server_rpc_new_deadline_delegate>(library);
177 this.grpcsharp_batch_context_server_rpc_new_request_metadata = GetMethodDelegate<Delegates.grpcsharp_batch_context_server_rpc_new_request_metadata_delegate>(library);
178 this.grpcsharp_batch_context_recv_close_on_server_cancelled = GetMethodDelegate<Delegates.grpcsharp_batch_context_recv_close_on_server_cancelled_delegate>(library);
179 this.grpcsharp_batch_context_destroy = GetMethodDelegate<Delegates.grpcsharp_batch_context_destroy_delegate>(library);
180
181 this.grpcsharp_composite_call_credentials_create = GetMethodDelegate<Delegates.grpcsharp_composite_call_credentials_create_delegate>(library);
182 this.grpcsharp_call_credentials_release = GetMethodDelegate<Delegates.grpcsharp_call_credentials_release_delegate>(library);
183
184 this.grpcsharp_call_cancel = GetMethodDelegate<Delegates.grpcsharp_call_cancel_delegate>(library);
185 this.grpcsharp_call_cancel_with_status = GetMethodDelegate<Delegates.grpcsharp_call_cancel_with_status_delegate>(library);
186 this.grpcsharp_call_start_unary = GetMethodDelegate<Delegates.grpcsharp_call_start_unary_delegate>(library);
187 this.grpcsharp_call_start_client_streaming = GetMethodDelegate<Delegates.grpcsharp_call_start_client_streaming_delegate>(library);
188 this.grpcsharp_call_start_server_streaming = GetMethodDelegate<Delegates.grpcsharp_call_start_server_streaming_delegate>(library);
189 this.grpcsharp_call_start_duplex_streaming = GetMethodDelegate<Delegates.grpcsharp_call_start_duplex_streaming_delegate>(library);
190 this.grpcsharp_call_send_message = GetMethodDelegate<Delegates.grpcsharp_call_send_message_delegate>(library);
191 this.grpcsharp_call_send_close_from_client = GetMethodDelegate<Delegates.grpcsharp_call_send_close_from_client_delegate>(library);
192 this.grpcsharp_call_send_status_from_server = GetMethodDelegate<Delegates.grpcsharp_call_send_status_from_server_delegate>(library);
193 this.grpcsharp_call_recv_message = GetMethodDelegate<Delegates.grpcsharp_call_recv_message_delegate>(library);
194 this.grpcsharp_call_recv_initial_metadata = GetMethodDelegate<Delegates.grpcsharp_call_recv_initial_metadata_delegate>(library);
195 this.grpcsharp_call_start_serverside = GetMethodDelegate<Delegates.grpcsharp_call_start_serverside_delegate>(library);
196 this.grpcsharp_call_send_initial_metadata = GetMethodDelegate<Delegates.grpcsharp_call_send_initial_metadata_delegate>(library);
197 this.grpcsharp_call_set_credentials = GetMethodDelegate<Delegates.grpcsharp_call_set_credentials_delegate>(library);
198 this.grpcsharp_call_get_peer = GetMethodDelegate<Delegates.grpcsharp_call_get_peer_delegate>(library);
199 this.grpcsharp_call_destroy = GetMethodDelegate<Delegates.grpcsharp_call_destroy_delegate>(library);
200
201 this.grpcsharp_channel_args_create = GetMethodDelegate<Delegates.grpcsharp_channel_args_create_delegate>(library);
202 this.grpcsharp_channel_args_set_string = GetMethodDelegate<Delegates.grpcsharp_channel_args_set_string_delegate>(library);
203 this.grpcsharp_channel_args_set_integer = GetMethodDelegate<Delegates.grpcsharp_channel_args_set_integer_delegate>(library);
204 this.grpcsharp_channel_args_destroy = GetMethodDelegate<Delegates.grpcsharp_channel_args_destroy_delegate>(library);
205
206 this.grpcsharp_ssl_credentials_create = GetMethodDelegate<Delegates.grpcsharp_ssl_credentials_create_delegate>(library);
207 this.grpcsharp_composite_channel_credentials_create = GetMethodDelegate<Delegates.grpcsharp_composite_channel_credentials_create_delegate>(library);
208 this.grpcsharp_channel_credentials_release = GetMethodDelegate<Delegates.grpcsharp_channel_credentials_release_delegate>(library);
209
210 this.grpcsharp_insecure_channel_create = GetMethodDelegate<Delegates.grpcsharp_insecure_channel_create_delegate>(library);
211 this.grpcsharp_secure_channel_create = GetMethodDelegate<Delegates.grpcsharp_secure_channel_create_delegate>(library);
212 this.grpcsharp_channel_create_call = GetMethodDelegate<Delegates.grpcsharp_channel_create_call_delegate>(library);
213 this.grpcsharp_channel_check_connectivity_state = GetMethodDelegate<Delegates.grpcsharp_channel_check_connectivity_state_delegate>(library);
214 this.grpcsharp_channel_watch_connectivity_state = GetMethodDelegate<Delegates.grpcsharp_channel_watch_connectivity_state_delegate>(library);
215 this.grpcsharp_channel_get_target = GetMethodDelegate<Delegates.grpcsharp_channel_get_target_delegate>(library);
216 this.grpcsharp_channel_destroy = GetMethodDelegate<Delegates.grpcsharp_channel_destroy_delegate>(library);
217
218 this.grpcsharp_sizeof_grpc_event = GetMethodDelegate<Delegates.grpcsharp_sizeof_grpc_event_delegate>(library);
219
220 this.grpcsharp_completion_queue_create = GetMethodDelegate<Delegates.grpcsharp_completion_queue_create_delegate>(library);
221 this.grpcsharp_completion_queue_shutdown = GetMethodDelegate<Delegates.grpcsharp_completion_queue_shutdown_delegate>(library);
222 this.grpcsharp_completion_queue_next = GetMethodDelegate<Delegates.grpcsharp_completion_queue_next_delegate>(library);
223 this.grpcsharp_completion_queue_pluck = GetMethodDelegate<Delegates.grpcsharp_completion_queue_pluck_delegate>(library);
224 this.grpcsharp_completion_queue_destroy = GetMethodDelegate<Delegates.grpcsharp_completion_queue_destroy_delegate>(library);
225
226 this.gprsharp_free = GetMethodDelegate<Delegates.gprsharp_free_delegate>(library);
227
228 this.grpcsharp_metadata_array_create = GetMethodDelegate<Delegates.grpcsharp_metadata_array_create_delegate>(library);
229 this.grpcsharp_metadata_array_add = GetMethodDelegate<Delegates.grpcsharp_metadata_array_add_delegate>(library);
230 this.grpcsharp_metadata_array_count = GetMethodDelegate<Delegates.grpcsharp_metadata_array_count_delegate>(library);
231 this.grpcsharp_metadata_array_get_key = GetMethodDelegate<Delegates.grpcsharp_metadata_array_get_key_delegate>(library);
232 this.grpcsharp_metadata_array_get_value = GetMethodDelegate<Delegates.grpcsharp_metadata_array_get_value_delegate>(library);
233 this.grpcsharp_metadata_array_get_value_length = GetMethodDelegate<Delegates.grpcsharp_metadata_array_get_value_length_delegate>(library);
234 this.grpcsharp_metadata_array_destroy_full = GetMethodDelegate<Delegates.grpcsharp_metadata_array_destroy_full_delegate>(library);
235
236 this.grpcsharp_redirect_log = GetMethodDelegate<Delegates.grpcsharp_redirect_log_delegate>(library);
237
238 this.grpcsharp_metadata_credentials_create_from_plugin = GetMethodDelegate<Delegates.grpcsharp_metadata_credentials_create_from_plugin_delegate>(library);
239 this.grpcsharp_metadata_credentials_notify_from_plugin = GetMethodDelegate<Delegates.grpcsharp_metadata_credentials_notify_from_plugin_delegate>(library);
240
241 this.grpcsharp_ssl_server_credentials_create = GetMethodDelegate<Delegates.grpcsharp_ssl_server_credentials_create_delegate>(library);
242 this.grpcsharp_server_credentials_release = GetMethodDelegate<Delegates.grpcsharp_server_credentials_release_delegate>(library);
243
244 this.grpcsharp_server_create = GetMethodDelegate<Delegates.grpcsharp_server_create_delegate>(library);
245 this.grpcsharp_server_add_insecure_http2_port = GetMethodDelegate<Delegates.grpcsharp_server_add_insecure_http2_port_delegate>(library);
246 this.grpcsharp_server_add_secure_http2_port = GetMethodDelegate<Delegates.grpcsharp_server_add_secure_http2_port_delegate>(library);
247 this.grpcsharp_server_start = GetMethodDelegate<Delegates.grpcsharp_server_start_delegate>(library);
248 this.grpcsharp_server_request_call = GetMethodDelegate<Delegates.grpcsharp_server_request_call_delegate>(library);
249 this.grpcsharp_server_cancel_all_calls = GetMethodDelegate<Delegates.grpcsharp_server_cancel_all_calls_delegate>(library);
250 this.grpcsharp_server_shutdown_and_notify_callback = GetMethodDelegate<Delegates.grpcsharp_server_shutdown_and_notify_callback_delegate>(library);
251 this.grpcsharp_server_destroy = GetMethodDelegate<Delegates.grpcsharp_server_destroy_delegate>(library);
252
253 this.gprsharp_now = GetMethodDelegate<Delegates.gprsharp_now_delegate>(library);
254 this.gprsharp_inf_future = GetMethodDelegate<Delegates.gprsharp_inf_future_delegate>(library);
255 this.gprsharp_inf_past = GetMethodDelegate<Delegates.gprsharp_inf_past_delegate>(library);
256 this.gprsharp_convert_clock_type = GetMethodDelegate<Delegates.gprsharp_convert_clock_type_delegate>(library);
257 this.gprsharp_sizeof_timespec = GetMethodDelegate<Delegates.gprsharp_sizeof_timespec_delegate>(library);
258
259 this.grpcsharp_test_callback = GetMethodDelegate<Delegates.grpcsharp_test_callback_delegate>(library);
260 this.grpcsharp_test_nop = GetMethodDelegate<Delegates.grpcsharp_test_nop_delegate>(library);
261 }
262 else
263 {
264 // Windows or fallback
265 this.grpcsharp_init = PInvokeMethods.grpcsharp_init;
266 this.grpcsharp_shutdown = PInvokeMethods.grpcsharp_shutdown;
267 this.grpcsharp_version_string = PInvokeMethods.grpcsharp_version_string;
268
269 this.grpcsharp_batch_context_create = PInvokeMethods.grpcsharp_batch_context_create;
270 this.grpcsharp_batch_context_recv_initial_metadata = PInvokeMethods.grpcsharp_batch_context_recv_initial_metadata;
271 this.grpcsharp_batch_context_recv_message_length = PInvokeMethods.grpcsharp_batch_context_recv_message_length;
272 this.grpcsharp_batch_context_recv_message_to_buffer = PInvokeMethods.grpcsharp_batch_context_recv_message_to_buffer;
273 this.grpcsharp_batch_context_recv_status_on_client_status = PInvokeMethods.grpcsharp_batch_context_recv_status_on_client_status;
274 this.grpcsharp_batch_context_recv_status_on_client_details = PInvokeMethods.grpcsharp_batch_context_recv_status_on_client_details;
275 this.grpcsharp_batch_context_recv_status_on_client_trailing_metadata = PInvokeMethods.grpcsharp_batch_context_recv_status_on_client_trailing_metadata;
276 this.grpcsharp_batch_context_server_rpc_new_call = PInvokeMethods.grpcsharp_batch_context_server_rpc_new_call;
277 this.grpcsharp_batch_context_server_rpc_new_method = PInvokeMethods.grpcsharp_batch_context_server_rpc_new_method;
278 this.grpcsharp_batch_context_server_rpc_new_host = PInvokeMethods.grpcsharp_batch_context_server_rpc_new_host;
279 this.grpcsharp_batch_context_server_rpc_new_deadline = PInvokeMethods.grpcsharp_batch_context_server_rpc_new_deadline;
280 this.grpcsharp_batch_context_server_rpc_new_request_metadata = PInvokeMethods.grpcsharp_batch_context_server_rpc_new_request_metadata;
281 this.grpcsharp_batch_context_recv_close_on_server_cancelled = PInvokeMethods.grpcsharp_batch_context_recv_close_on_server_cancelled;
282 this.grpcsharp_batch_context_destroy = PInvokeMethods.grpcsharp_batch_context_destroy;
283
284 this.grpcsharp_composite_call_credentials_create = PInvokeMethods.grpcsharp_composite_call_credentials_create;
285 this.grpcsharp_call_credentials_release = PInvokeMethods.grpcsharp_call_credentials_release;
286
287 this.grpcsharp_call_cancel = PInvokeMethods.grpcsharp_call_cancel;
288 this.grpcsharp_call_cancel_with_status = PInvokeMethods.grpcsharp_call_cancel_with_status;
289 this.grpcsharp_call_start_unary = PInvokeMethods.grpcsharp_call_start_unary;
290 this.grpcsharp_call_start_client_streaming = PInvokeMethods.grpcsharp_call_start_client_streaming;
291 this.grpcsharp_call_start_server_streaming = PInvokeMethods.grpcsharp_call_start_server_streaming;
292 this.grpcsharp_call_start_duplex_streaming = PInvokeMethods.grpcsharp_call_start_duplex_streaming;
293 this.grpcsharp_call_send_message = PInvokeMethods.grpcsharp_call_send_message;
294 this.grpcsharp_call_send_close_from_client = PInvokeMethods.grpcsharp_call_send_close_from_client;
295 this.grpcsharp_call_send_status_from_server = PInvokeMethods.grpcsharp_call_send_status_from_server;
296 this.grpcsharp_call_recv_message = PInvokeMethods.grpcsharp_call_recv_message;
297 this.grpcsharp_call_recv_initial_metadata = PInvokeMethods.grpcsharp_call_recv_initial_metadata;
298 this.grpcsharp_call_start_serverside = PInvokeMethods.grpcsharp_call_start_serverside;
299 this.grpcsharp_call_send_initial_metadata = PInvokeMethods.grpcsharp_call_send_initial_metadata;
300 this.grpcsharp_call_set_credentials = PInvokeMethods.grpcsharp_call_set_credentials;
301 this.grpcsharp_call_get_peer = PInvokeMethods.grpcsharp_call_get_peer;
302 this.grpcsharp_call_destroy = PInvokeMethods.grpcsharp_call_destroy;
303
304 this.grpcsharp_channel_args_create = PInvokeMethods.grpcsharp_channel_args_create;
305 this.grpcsharp_channel_args_set_string = PInvokeMethods.grpcsharp_channel_args_set_string;
306 this.grpcsharp_channel_args_set_integer = PInvokeMethods.grpcsharp_channel_args_set_integer;
307 this.grpcsharp_channel_args_destroy = PInvokeMethods.grpcsharp_channel_args_destroy;
308
309 this.grpcsharp_ssl_credentials_create = PInvokeMethods.grpcsharp_ssl_credentials_create;
310 this.grpcsharp_composite_channel_credentials_create = PInvokeMethods.grpcsharp_composite_channel_credentials_create;
311 this.grpcsharp_channel_credentials_release = PInvokeMethods.grpcsharp_channel_credentials_release;
312
313 this.grpcsharp_insecure_channel_create = PInvokeMethods.grpcsharp_insecure_channel_create;
314 this.grpcsharp_secure_channel_create = PInvokeMethods.grpcsharp_secure_channel_create;
315 this.grpcsharp_channel_create_call = PInvokeMethods.grpcsharp_channel_create_call;
316 this.grpcsharp_channel_check_connectivity_state = PInvokeMethods.grpcsharp_channel_check_connectivity_state;
317 this.grpcsharp_channel_watch_connectivity_state = PInvokeMethods.grpcsharp_channel_watch_connectivity_state;
318 this.grpcsharp_channel_get_target = PInvokeMethods.grpcsharp_channel_get_target;
319 this.grpcsharp_channel_destroy = PInvokeMethods.grpcsharp_channel_destroy;
320
321 this.grpcsharp_sizeof_grpc_event = PInvokeMethods.grpcsharp_sizeof_grpc_event;
322
323 this.grpcsharp_completion_queue_create = PInvokeMethods.grpcsharp_completion_queue_create;
324 this.grpcsharp_completion_queue_shutdown = PInvokeMethods.grpcsharp_completion_queue_shutdown;
325 this.grpcsharp_completion_queue_next = PInvokeMethods.grpcsharp_completion_queue_next;
326 this.grpcsharp_completion_queue_pluck = PInvokeMethods.grpcsharp_completion_queue_pluck;
327 this.grpcsharp_completion_queue_destroy = PInvokeMethods.grpcsharp_completion_queue_destroy;
328
329 this.gprsharp_free = PInvokeMethods.gprsharp_free;
330
331 this.grpcsharp_metadata_array_create = PInvokeMethods.grpcsharp_metadata_array_create;
332 this.grpcsharp_metadata_array_add = PInvokeMethods.grpcsharp_metadata_array_add;
333 this.grpcsharp_metadata_array_count = PInvokeMethods.grpcsharp_metadata_array_count;
334 this.grpcsharp_metadata_array_get_key = PInvokeMethods.grpcsharp_metadata_array_get_key;
335 this.grpcsharp_metadata_array_get_value = PInvokeMethods.grpcsharp_metadata_array_get_value;
336 this.grpcsharp_metadata_array_get_value_length = PInvokeMethods.grpcsharp_metadata_array_get_value_length;
337 this.grpcsharp_metadata_array_destroy_full = PInvokeMethods.grpcsharp_metadata_array_destroy_full;
338
339 this.grpcsharp_redirect_log = PInvokeMethods.grpcsharp_redirect_log;
340
341 this.grpcsharp_metadata_credentials_create_from_plugin = PInvokeMethods.grpcsharp_metadata_credentials_create_from_plugin;
342 this.grpcsharp_metadata_credentials_notify_from_plugin = PInvokeMethods.grpcsharp_metadata_credentials_notify_from_plugin;
343
344 this.grpcsharp_ssl_server_credentials_create = PInvokeMethods.grpcsharp_ssl_server_credentials_create;
345 this.grpcsharp_server_credentials_release = PInvokeMethods.grpcsharp_server_credentials_release;
346
347 this.grpcsharp_server_create = PInvokeMethods.grpcsharp_server_create;
348 this.grpcsharp_server_add_insecure_http2_port = PInvokeMethods.grpcsharp_server_add_insecure_http2_port;
349 this.grpcsharp_server_add_secure_http2_port = PInvokeMethods.grpcsharp_server_add_secure_http2_port;
350 this.grpcsharp_server_start = PInvokeMethods.grpcsharp_server_start;
351 this.grpcsharp_server_request_call = PInvokeMethods.grpcsharp_server_request_call;
352 this.grpcsharp_server_cancel_all_calls = PInvokeMethods.grpcsharp_server_cancel_all_calls;
353 this.grpcsharp_server_shutdown_and_notify_callback = PInvokeMethods.grpcsharp_server_shutdown_and_notify_callback;
354 this.grpcsharp_server_destroy = PInvokeMethods.grpcsharp_server_destroy;
355
356 this.gprsharp_now = PInvokeMethods.gprsharp_now;
357 this.gprsharp_inf_future = PInvokeMethods.gprsharp_inf_future;
358 this.gprsharp_inf_past = PInvokeMethods.gprsharp_inf_past;
359 this.gprsharp_convert_clock_type = PInvokeMethods.gprsharp_convert_clock_type;
360 this.gprsharp_sizeof_timespec = PInvokeMethods.gprsharp_sizeof_timespec;
361
362 this.grpcsharp_test_callback = PInvokeMethods.grpcsharp_test_callback;
363 this.grpcsharp_test_nop = PInvokeMethods.grpcsharp_test_nop;
364 }
365 }
366
367 /// <summary>
368 /// Gets singleton instance of this class.
369 /// </summary>
370 public static NativeMethods Get()
371 {
372 return NativeExtension.Get().NativeMethods;
373 }
374
375 static T GetMethodDelegate<T>(UnmanagedLibrary library)
376 where T : class
377 {
378 var methodName = RemoveStringSuffix(typeof(T).Name, "_delegate");
379 return library.GetNativeMethodDelegate<T>(methodName);
380 }
381
382 static string RemoveStringSuffix(string str, string toRemove)
383 {
384 if (!str.EndsWith(toRemove))
385 {
386 return str;
387 }
388 return str.Substring(0, str.Length - toRemove.Length);
389 }
390
391 /// <summary>
392 /// Delegate types for all published native methods. Declared under inner class to prevent scope pollution.
393 /// </summary>
394 public class Delegates
395 {
396 public delegate void grpcsharp_init_delegate();
397 public delegate void grpcsharp_shutdown_delegate();
398 public delegate IntPtr grpcsharp_version_string_delegate(); // returns not-owned const char*
399
400 public delegate BatchContextSafeHandle grpcsharp_batch_context_create_delegate();
401 public delegate IntPtr grpcsharp_batch_context_recv_initial_metadata_delegate(BatchContextSafeHandle ctx);
402 public delegate IntPtr grpcsharp_batch_context_recv_message_length_delegate(BatchContextSafeHandle ctx);
403 public delegate void grpcsharp_batch_context_recv_message_to_buffer_delegate(BatchContextSafeHandle ctx, byte[] buffer, UIntPtr bufferLen);
404 public delegate StatusCode grpcsharp_batch_context_recv_status_on_client_status_delegate(BatchContextSafeHandle ctx);
405 public delegate IntPtr grpcsharp_batch_context_recv_status_on_client_details_delegate(BatchContextSafeHandle ctx); // returns const char*
406 public delegate IntPtr grpcsharp_batch_context_recv_status_on_client_trailing_metadata_delegate(BatchContextSafeHandle ctx);
407 public delegate CallSafeHandle grpcsharp_batch_context_server_rpc_new_call_delegate(BatchContextSafeHandle ctx);
408 public delegate IntPtr grpcsharp_batch_context_server_rpc_new_method_delegate(BatchContextSafeHandle ctx); // returns const char*
409 public delegate IntPtr grpcsharp_batch_context_server_rpc_new_host_delegate(BatchContextSafeHandle ctx); // returns const char*
410 public delegate Timespec grpcsharp_batch_context_server_rpc_new_deadline_delegate(BatchContextSafeHandle ctx);
411 public delegate IntPtr grpcsharp_batch_context_server_rpc_new_request_metadata_delegate(BatchContextSafeHandle ctx);
412 public delegate int grpcsharp_batch_context_recv_close_on_server_cancelled_delegate(BatchContextSafeHandle ctx);
413 public delegate void grpcsharp_batch_context_destroy_delegate(IntPtr ctx);
414
415 public delegate CallCredentialsSafeHandle grpcsharp_composite_call_credentials_create_delegate(CallCredentialsSafeHandle creds1, CallCredentialsSafeHandle creds2);
416 public delegate void grpcsharp_call_credentials_release_delegate(IntPtr credentials);
417
418 public delegate GRPCCallError grpcsharp_call_cancel_delegate(CallSafeHandle call);
419 public delegate GRPCCallError grpcsharp_call_cancel_with_status_delegate(CallSafeHandle call, StatusCode status, string description);
420 public delegate GRPCCallError grpcsharp_call_start_unary_delegate(CallSafeHandle call,
421 BatchContextSafeHandle ctx, byte[] send_buffer, UIntPtr send_buffer_len, MetadataArraySafeHandle metadataArray, WriteFlags writeFlags);
422 public delegate GRPCCallError grpcsharp_call_start_client_streaming_delegate(CallSafeHandle call,
423 BatchContextSafeHandle ctx, MetadataArraySafeHandle metadataArray);
424 public delegate GRPCCallError grpcsharp_call_start_server_streaming_delegate(CallSafeHandle call,
425 BatchContextSafeHandle ctx, byte[] send_buffer, UIntPtr send_buffer_len,
426 MetadataArraySafeHandle metadataArray, WriteFlags writeFlags);
427 public delegate GRPCCallError grpcsharp_call_start_duplex_streaming_delegate(CallSafeHandle call,
428 BatchContextSafeHandle ctx, MetadataArraySafeHandle metadataArray);
429 public delegate GRPCCallError grpcsharp_call_send_message_delegate(CallSafeHandle call,
430 BatchContextSafeHandle ctx, byte[] send_buffer, UIntPtr send_buffer_len, WriteFlags writeFlags, bool sendEmptyInitialMetadata);
431 public delegate GRPCCallError grpcsharp_call_send_close_from_client_delegate(CallSafeHandle call,
432 BatchContextSafeHandle ctx);
433 public delegate GRPCCallError grpcsharp_call_send_status_from_server_delegate(CallSafeHandle call,
434 BatchContextSafeHandle ctx, StatusCode statusCode, string statusMessage, MetadataArraySafeHandle metadataArray, bool sendEmptyInitialMetadata);
435 public delegate GRPCCallError grpcsharp_call_recv_message_delegate(CallSafeHandle call,
436 BatchContextSafeHandle ctx);
437 public delegate GRPCCallError grpcsharp_call_recv_initial_metadata_delegate(CallSafeHandle call,
438 BatchContextSafeHandle ctx);
439 public delegate GRPCCallError grpcsharp_call_start_serverside_delegate(CallSafeHandle call,
440 BatchContextSafeHandle ctx);
441 public delegate GRPCCallError grpcsharp_call_send_initial_metadata_delegate(CallSafeHandle call,
442 BatchContextSafeHandle ctx, MetadataArraySafeHandle metadataArray);
443 public delegate GRPCCallError grpcsharp_call_set_credentials_delegate(CallSafeHandle call, CallCredentialsSafeHandle credentials);
444 public delegate CStringSafeHandle grpcsharp_call_get_peer_delegate(CallSafeHandle call);
445 public delegate void grpcsharp_call_destroy_delegate(IntPtr call);
446
447 public delegate ChannelArgsSafeHandle grpcsharp_channel_args_create_delegate(UIntPtr numArgs);
448 public delegate void grpcsharp_channel_args_set_string_delegate(ChannelArgsSafeHandle args, UIntPtr index, string key, string value);
449 public delegate void grpcsharp_channel_args_set_integer_delegate(ChannelArgsSafeHandle args, UIntPtr index, string key, int value);
450 public delegate void grpcsharp_channel_args_destroy_delegate(IntPtr args);
451
452 public delegate ChannelCredentialsSafeHandle grpcsharp_ssl_credentials_create_delegate(string pemRootCerts, string keyCertPairCertChain, string keyCertPairPrivateKey);
453 public delegate ChannelCredentialsSafeHandle grpcsharp_composite_channel_credentials_create_delegate(ChannelCredentialsSafeHandle channelCreds, CallCredentialsSafeHandle callCreds);
454 public delegate void grpcsharp_channel_credentials_release_delegate(IntPtr credentials);
455
456 public delegate ChannelSafeHandle grpcsharp_insecure_channel_create_delegate(string target, ChannelArgsSafeHandle channelArgs);
457 public delegate ChannelSafeHandle grpcsharp_secure_channel_create_delegate(ChannelCredentialsSafeHandle credentials, string target, ChannelArgsSafeHandle channelArgs);
458 public delegate CallSafeHandle grpcsharp_channel_create_call_delegate(ChannelSafeHandle channel, CallSafeHandle parentCall, ContextPropagationFlags propagationMask, CompletionQueueSafeHandle cq, string method, string host, Timespec deadline);
459 public delegate ChannelState grpcsharp_channel_check_connectivity_state_delegate(ChannelSafeHandle channel, int tryToConnect);
460 public delegate void grpcsharp_channel_watch_connectivity_state_delegate(ChannelSafeHandle channel, ChannelState lastObservedState,
461 Timespec deadline, CompletionQueueSafeHandle cq, BatchContextSafeHandle ctx);
462 public delegate CStringSafeHandle grpcsharp_channel_get_target_delegate(ChannelSafeHandle call);
463 public delegate void grpcsharp_channel_destroy_delegate(IntPtr channel);
464
465 public delegate int grpcsharp_sizeof_grpc_event_delegate();
466
467 public delegate CompletionQueueSafeHandle grpcsharp_completion_queue_create_delegate();
468 public delegate void grpcsharp_completion_queue_shutdown_delegate(CompletionQueueSafeHandle cq);
469 public delegate CompletionQueueEvent grpcsharp_completion_queue_next_delegate(CompletionQueueSafeHandle cq);
470 public delegate CompletionQueueEvent grpcsharp_completion_queue_pluck_delegate(CompletionQueueSafeHandle cq, IntPtr tag);
471 public delegate void grpcsharp_completion_queue_destroy_delegate(IntPtr cq);
472
473 public delegate void gprsharp_free_delegate(IntPtr ptr);
474
475 public delegate MetadataArraySafeHandle grpcsharp_metadata_array_create_delegate(UIntPtr capacity);
476 public delegate void grpcsharp_metadata_array_add_delegate(MetadataArraySafeHandle array, string key, byte[] value, UIntPtr valueLength);
477 public delegate UIntPtr grpcsharp_metadata_array_count_delegate(IntPtr metadataArray);
478 public delegate IntPtr grpcsharp_metadata_array_get_key_delegate(IntPtr metadataArray, UIntPtr index);
479 public delegate IntPtr grpcsharp_metadata_array_get_value_delegate(IntPtr metadataArray, UIntPtr index);
480 public delegate UIntPtr grpcsharp_metadata_array_get_value_length_delegate(IntPtr metadataArray, UIntPtr index);
481 public delegate void grpcsharp_metadata_array_destroy_full_delegate(IntPtr array);
482
483 public delegate void grpcsharp_redirect_log_delegate(GprLogDelegate callback);
484
485 public delegate CallCredentialsSafeHandle grpcsharp_metadata_credentials_create_from_plugin_delegate(NativeMetadataInterceptor interceptor);
486 public delegate void grpcsharp_metadata_credentials_notify_from_plugin_delegate(IntPtr callbackPtr, IntPtr userData, MetadataArraySafeHandle metadataArray, StatusCode statusCode, string errorDetails);
487
488 public delegate ServerCredentialsSafeHandle grpcsharp_ssl_server_credentials_create_delegate(string pemRootCerts, string[] keyCertPairCertChainArray, string[] keyCertPairPrivateKeyArray, UIntPtr numKeyCertPairs, bool forceClientAuth);
489 public delegate void grpcsharp_server_credentials_release_delegate(IntPtr credentials);
490
491 public delegate ServerSafeHandle grpcsharp_server_create_delegate(CompletionQueueSafeHandle cq, ChannelArgsSafeHandle args);
492 public delegate int grpcsharp_server_add_insecure_http2_port_delegate(ServerSafeHandle server, string addr);
493 public delegate int grpcsharp_server_add_secure_http2_port_delegate(ServerSafeHandle server, string addr, ServerCredentialsSafeHandle creds);
494 public delegate void grpcsharp_server_start_delegate(ServerSafeHandle server);
495 public delegate GRPCCallError grpcsharp_server_request_call_delegate(ServerSafeHandle server, CompletionQueueSafeHandle cq, BatchContextSafeHandle ctx);
496 public delegate void grpcsharp_server_cancel_all_calls_delegate(ServerSafeHandle server);
497 public delegate void grpcsharp_server_shutdown_and_notify_callback_delegate(ServerSafeHandle server, CompletionQueueSafeHandle cq, BatchContextSafeHandle ctx);
498 public delegate void grpcsharp_server_destroy_delegate(IntPtr server);
499
500 public delegate Timespec gprsharp_now_delegate(GPRClockType clockType);
501 public delegate Timespec gprsharp_inf_future_delegate(GPRClockType clockType);
502 public delegate Timespec gprsharp_inf_past_delegate(GPRClockType clockType);
503
504 public delegate Timespec gprsharp_convert_clock_type_delegate(Timespec t, GPRClockType targetClock);
505 public delegate int gprsharp_sizeof_timespec_delegate();
506
507 public delegate GRPCCallError grpcsharp_test_callback_delegate([MarshalAs(UnmanagedType.FunctionPtr)] OpCompletionDelegate callback);
508 public delegate IntPtr grpcsharp_test_nop_delegate(IntPtr ptr);
509 }
510
511 /// <summary>
512 /// Default PInvoke bindings for native methods that are used on Windows.
513 /// Alternatively, they can also be used as a fallback on Mono
514 /// (if libgrpc_csharp_ext is installed on your system, or is made accessible through e.g. LD_LIBRARY_PATH environment variable
515 /// or using Mono's dllMap feature).
516 /// </summary>
517 private class PInvokeMethods
518 {
519 // Environment
520
521 [DllImport("grpc_csharp_ext.dll")]
522 public static extern void grpcsharp_init();
523
524 [DllImport("grpc_csharp_ext.dll")]
525 public static extern void grpcsharp_shutdown();
526
527 [DllImport("grpc_csharp_ext.dll")]
528 public static extern IntPtr grpcsharp_version_string(); // returns not-owned const char*
529
530 // BatchContextSafeHandle
531
532 [DllImport("grpc_csharp_ext.dll")]
533 public static extern BatchContextSafeHandle grpcsharp_batch_context_create();
534
535 [DllImport("grpc_csharp_ext.dll")]
536 public static extern IntPtr grpcsharp_batch_context_recv_initial_metadata(BatchContextSafeHandle ctx);
537
538 [DllImport("grpc_csharp_ext.dll")]
539 public static extern IntPtr grpcsharp_batch_context_recv_message_length(BatchContextSafeHandle ctx);
540
541 [DllImport("grpc_csharp_ext.dll")]
542 public static extern void grpcsharp_batch_context_recv_message_to_buffer(BatchContextSafeHandle ctx, byte[] buffer, UIntPtr bufferLen);
543
544 [DllImport("grpc_csharp_ext.dll")]
545 public static extern StatusCode grpcsharp_batch_context_recv_status_on_client_status(BatchContextSafeHandle ctx);
546
547 [DllImport("grpc_csharp_ext.dll")]
548 public static extern IntPtr grpcsharp_batch_context_recv_status_on_client_details(BatchContextSafeHandle ctx); // returns const char*
549
550 [DllImport("grpc_csharp_ext.dll")]
551 public static extern IntPtr grpcsharp_batch_context_recv_status_on_client_trailing_metadata(BatchContextSafeHandle ctx);
552
553 [DllImport("grpc_csharp_ext.dll")]
554 public static extern CallSafeHandle grpcsharp_batch_context_server_rpc_new_call(BatchContextSafeHandle ctx);
555
556 [DllImport("grpc_csharp_ext.dll")]
557 public static extern IntPtr grpcsharp_batch_context_server_rpc_new_method(BatchContextSafeHandle ctx); // returns const char*
558
559 [DllImport("grpc_csharp_ext.dll")]
560 public static extern IntPtr grpcsharp_batch_context_server_rpc_new_host(BatchContextSafeHandle ctx); // returns const char*
561
562 [DllImport("grpc_csharp_ext.dll")]
563 public static extern Timespec grpcsharp_batch_context_server_rpc_new_deadline(BatchContextSafeHandle ctx);
564
565 [DllImport("grpc_csharp_ext.dll")]
566 public static extern IntPtr grpcsharp_batch_context_server_rpc_new_request_metadata(BatchContextSafeHandle ctx);
567
568 [DllImport("grpc_csharp_ext.dll")]
569 public static extern int grpcsharp_batch_context_recv_close_on_server_cancelled(BatchContextSafeHandle ctx);
570
571 [DllImport("grpc_csharp_ext.dll")]
572 public static extern void grpcsharp_batch_context_destroy(IntPtr ctx);
573
574 // CallCredentialsSafeHandle
575
576 [DllImport("grpc_csharp_ext.dll")]
577 public static extern CallCredentialsSafeHandle grpcsharp_composite_call_credentials_create(CallCredentialsSafeHandle creds1, CallCredentialsSafeHandle creds2);
578
579 [DllImport("grpc_csharp_ext.dll")]
580 public static extern void grpcsharp_call_credentials_release(IntPtr credentials);
581
582 // CallSafeHandle
583
584 [DllImport("grpc_csharp_ext.dll")]
585 public static extern GRPCCallError grpcsharp_call_cancel(CallSafeHandle call);
586
587 [DllImport("grpc_csharp_ext.dll")]
588 public static extern GRPCCallError grpcsharp_call_cancel_with_status(CallSafeHandle call, StatusCode status, string description);
589
590 [DllImport("grpc_csharp_ext.dll")]
591 public static extern GRPCCallError grpcsharp_call_start_unary(CallSafeHandle call,
592 BatchContextSafeHandle ctx, byte[] send_buffer, UIntPtr send_buffer_len, MetadataArraySafeHandle metadataArray, WriteFlags writeFlags);
593
594 [DllImport("grpc_csharp_ext.dll")]
595 public static extern GRPCCallError grpcsharp_call_start_client_streaming(CallSafeHandle call,
596 BatchContextSafeHandle ctx, MetadataArraySafeHandle metadataArray);
597
598 [DllImport("grpc_csharp_ext.dll")]
599 public static extern GRPCCallError grpcsharp_call_start_server_streaming(CallSafeHandle call,
600 BatchContextSafeHandle ctx, byte[] send_buffer, UIntPtr send_buffer_len,
601 MetadataArraySafeHandle metadataArray, WriteFlags writeFlags);
602
603 [DllImport("grpc_csharp_ext.dll")]
604 public static extern GRPCCallError grpcsharp_call_start_duplex_streaming(CallSafeHandle call,
605 BatchContextSafeHandle ctx, MetadataArraySafeHandle metadataArray);
606
607 [DllImport("grpc_csharp_ext.dll")]
608 public static extern GRPCCallError grpcsharp_call_send_message(CallSafeHandle call,
609 BatchContextSafeHandle ctx, byte[] send_buffer, UIntPtr send_buffer_len, WriteFlags writeFlags, bool sendEmptyInitialMetadata);
610
611 [DllImport("grpc_csharp_ext.dll")]
612 public static extern GRPCCallError grpcsharp_call_send_close_from_client(CallSafeHandle call,
613 BatchContextSafeHandle ctx);
614
615 [DllImport("grpc_csharp_ext.dll")]
616 public static extern GRPCCallError grpcsharp_call_send_status_from_server(CallSafeHandle call,
617 BatchContextSafeHandle ctx, StatusCode statusCode, string statusMessage, MetadataArraySafeHandle metadataArray, bool sendEmptyInitialMetadata);
618
619 [DllImport("grpc_csharp_ext.dll")]
620 public static extern GRPCCallError grpcsharp_call_recv_message(CallSafeHandle call,
621 BatchContextSafeHandle ctx);
622
623 [DllImport("grpc_csharp_ext.dll")]
624 public static extern GRPCCallError grpcsharp_call_recv_initial_metadata(CallSafeHandle call,
625 BatchContextSafeHandle ctx);
626
627 [DllImport("grpc_csharp_ext.dll")]
628 public static extern GRPCCallError grpcsharp_call_start_serverside(CallSafeHandle call,
629 BatchContextSafeHandle ctx);
630
631 [DllImport("grpc_csharp_ext.dll")]
632 public static extern GRPCCallError grpcsharp_call_send_initial_metadata(CallSafeHandle call,
633 BatchContextSafeHandle ctx, MetadataArraySafeHandle metadataArray);
634
635 [DllImport("grpc_csharp_ext.dll")]
636 public static extern GRPCCallError grpcsharp_call_set_credentials(CallSafeHandle call, CallCredentialsSafeHandle credentials);
637
638 [DllImport("grpc_csharp_ext.dll")]
639 public static extern CStringSafeHandle grpcsharp_call_get_peer(CallSafeHandle call);
640
641 [DllImport("grpc_csharp_ext.dll")]
642 public static extern void grpcsharp_call_destroy(IntPtr call);
643
644 // ChannelArgsSafeHandle
645
646 [DllImport("grpc_csharp_ext.dll")]
647 public static extern ChannelArgsSafeHandle grpcsharp_channel_args_create(UIntPtr numArgs);
648
649 [DllImport("grpc_csharp_ext.dll", CharSet = CharSet.Ansi)]
650 public static extern void grpcsharp_channel_args_set_string(ChannelArgsSafeHandle args, UIntPtr index, string key, string value);
651
652 [DllImport("grpc_csharp_ext.dll", CharSet = CharSet.Ansi)]
653 public static extern void grpcsharp_channel_args_set_integer(ChannelArgsSafeHandle args, UIntPtr index, string key, int value);
654
655 [DllImport("grpc_csharp_ext.dll")]
656 public static extern void grpcsharp_channel_args_destroy(IntPtr args);
657
658 // ChannelCredentialsSafeHandle
659
660 [DllImport("grpc_csharp_ext.dll", CharSet = CharSet.Ansi)]
661 public static extern ChannelCredentialsSafeHandle grpcsharp_ssl_credentials_create(string pemRootCerts, string keyCertPairCertChain, string keyCertPairPrivateKey);
662
663 [DllImport("grpc_csharp_ext.dll")]
664 public static extern ChannelCredentialsSafeHandle grpcsharp_composite_channel_credentials_create(ChannelCredentialsSafeHandle channelCreds, CallCredentialsSafeHandle callCreds);
665
666 [DllImport("grpc_csharp_ext.dll")]
667 public static extern void grpcsharp_channel_credentials_release(IntPtr credentials);
668
669 // ChannelSafeHandle
670
671 [DllImport("grpc_csharp_ext.dll")]
672 public static extern ChannelSafeHandle grpcsharp_insecure_channel_create(string target, ChannelArgsSafeHandle channelArgs);
673
674 [DllImport("grpc_csharp_ext.dll")]
675 public static extern ChannelSafeHandle grpcsharp_secure_channel_create(ChannelCredentialsSafeHandle credentials, string target, ChannelArgsSafeHandle channelArgs);
676
677 [DllImport("grpc_csharp_ext.dll")]
678 public static extern CallSafeHandle grpcsharp_channel_create_call(ChannelSafeHandle channel, CallSafeHandle parentCall, ContextPropagationFlags propagationMask, CompletionQueueSafeHandle cq, string method, string host, Timespec deadline);
679
680 [DllImport("grpc_csharp_ext.dll")]
681 public static extern ChannelState grpcsharp_channel_check_connectivity_state(ChannelSafeHandle channel, int tryToConnect);
682
683 [DllImport("grpc_csharp_ext.dll")]
684 public static extern void grpcsharp_channel_watch_connectivity_state(ChannelSafeHandle channel, ChannelState lastObservedState,
685 Timespec deadline, CompletionQueueSafeHandle cq, BatchContextSafeHandle ctx);
686
687 [DllImport("grpc_csharp_ext.dll")]
688 public static extern CStringSafeHandle grpcsharp_channel_get_target(ChannelSafeHandle call);
689
690 [DllImport("grpc_csharp_ext.dll")]
691 public static extern void grpcsharp_channel_destroy(IntPtr channel);
692
693 // CompletionQueueEvent
694
695 [DllImport("grpc_csharp_ext.dll")]
696 public static extern int grpcsharp_sizeof_grpc_event();
697
698 // CompletionQueueSafeHandle
699
700 [DllImport("grpc_csharp_ext.dll")]
701 public static extern CompletionQueueSafeHandle grpcsharp_completion_queue_create();
702
703 [DllImport("grpc_csharp_ext.dll")]
704 public static extern void grpcsharp_completion_queue_shutdown(CompletionQueueSafeHandle cq);
705
706 [DllImport("grpc_csharp_ext.dll")]
707 public static extern CompletionQueueEvent grpcsharp_completion_queue_next(CompletionQueueSafeHandle cq);
708
709 [DllImport("grpc_csharp_ext.dll")]
710 public static extern CompletionQueueEvent grpcsharp_completion_queue_pluck(CompletionQueueSafeHandle cq, IntPtr tag);
711
712 [DllImport("grpc_csharp_ext.dll")]
713 public static extern void grpcsharp_completion_queue_destroy(IntPtr cq);
714
715 // CStringSafeHandle
716
717 [DllImport("grpc_csharp_ext.dll")]
718 public static extern void gprsharp_free(IntPtr ptr);
719
720 // MetadataArraySafeHandle
721
722 [DllImport("grpc_csharp_ext.dll")]
723 public static extern MetadataArraySafeHandle grpcsharp_metadata_array_create(UIntPtr capacity);
724
725 [DllImport("grpc_csharp_ext.dll", CharSet = CharSet.Ansi)]
726 public static extern void grpcsharp_metadata_array_add(MetadataArraySafeHandle array, string key, byte[] value, UIntPtr valueLength);
727
728 [DllImport("grpc_csharp_ext.dll")]
729 public static extern UIntPtr grpcsharp_metadata_array_count(IntPtr metadataArray);
730
731 [DllImport("grpc_csharp_ext.dll")]
732 public static extern IntPtr grpcsharp_metadata_array_get_key(IntPtr metadataArray, UIntPtr index);
733
734 [DllImport("grpc_csharp_ext.dll")]
735 public static extern IntPtr grpcsharp_metadata_array_get_value(IntPtr metadataArray, UIntPtr index);
736
737 [DllImport("grpc_csharp_ext.dll")]
738 public static extern UIntPtr grpcsharp_metadata_array_get_value_length(IntPtr metadataArray, UIntPtr index);
739
740 [DllImport("grpc_csharp_ext.dll")]
741 public static extern void grpcsharp_metadata_array_destroy_full(IntPtr array);
742
743 // NativeLogRedirector
744
745 [DllImport("grpc_csharp_ext.dll")]
746 public static extern void grpcsharp_redirect_log(GprLogDelegate callback);
747
748 // NativeMetadataCredentialsPlugin
749
750 [DllImport("grpc_csharp_ext.dll")]
751 public static extern CallCredentialsSafeHandle grpcsharp_metadata_credentials_create_from_plugin(NativeMetadataInterceptor interceptor);
752
753 [DllImport("grpc_csharp_ext.dll", CharSet = CharSet.Ansi)]
754 public static extern void grpcsharp_metadata_credentials_notify_from_plugin(IntPtr callbackPtr, IntPtr userData, MetadataArraySafeHandle metadataArray, StatusCode statusCode, string errorDetails);
755
756 // ServerCredentialsSafeHandle
757
758 [DllImport("grpc_csharp_ext.dll", CharSet = CharSet.Ansi)]
759 public static extern ServerCredentialsSafeHandle grpcsharp_ssl_server_credentials_create(string pemRootCerts, string[] keyCertPairCertChainArray, string[] keyCertPairPrivateKeyArray, UIntPtr numKeyCertPairs, bool forceClientAuth);
760
761 [DllImport("grpc_csharp_ext.dll")]
762 public static extern void grpcsharp_server_credentials_release(IntPtr credentials);
763
764 // ServerSafeHandle
765
766 [DllImport("grpc_csharp_ext.dll")]
767 public static extern ServerSafeHandle grpcsharp_server_create(CompletionQueueSafeHandle cq, ChannelArgsSafeHandle args);
768
769 [DllImport("grpc_csharp_ext.dll")]
770 public static extern int grpcsharp_server_add_insecure_http2_port(ServerSafeHandle server, string addr);
771
772 [DllImport("grpc_csharp_ext.dll")]
773 public static extern int grpcsharp_server_add_secure_http2_port(ServerSafeHandle server, string addr, ServerCredentialsSafeHandle creds);
774
775 [DllImport("grpc_csharp_ext.dll")]
776 public static extern void grpcsharp_server_start(ServerSafeHandle server);
777
778 [DllImport("grpc_csharp_ext.dll")]
779 public static extern GRPCCallError grpcsharp_server_request_call(ServerSafeHandle server, CompletionQueueSafeHandle cq, BatchContextSafeHandle ctx);
780
781 [DllImport("grpc_csharp_ext.dll")]
782 public static extern void grpcsharp_server_cancel_all_calls(ServerSafeHandle server);
783
784 [DllImport("grpc_csharp_ext.dll")]
785 public static extern void grpcsharp_server_shutdown_and_notify_callback(ServerSafeHandle server, CompletionQueueSafeHandle cq, BatchContextSafeHandle ctx);
786
787 [DllImport("grpc_csharp_ext.dll")]
788 public static extern void grpcsharp_server_destroy(IntPtr server);
789
790 // Timespec
791
792 [DllImport("grpc_csharp_ext.dll")]
793 public static extern Timespec gprsharp_now(GPRClockType clockType);
794
795 [DllImport("grpc_csharp_ext.dll")]
796 public static extern Timespec gprsharp_inf_future(GPRClockType clockType);
797
798 [DllImport("grpc_csharp_ext.dll")]
799 public static extern Timespec gprsharp_inf_past(GPRClockType clockType);
800
801 [DllImport("grpc_csharp_ext.dll")]
802 public static extern Timespec gprsharp_convert_clock_type(Timespec t, GPRClockType targetClock);
803
804 [DllImport("grpc_csharp_ext.dll")]
805 public static extern int gprsharp_sizeof_timespec();
806
807 // Testing
808
809 [DllImport("grpc_csharp_ext.dll")]
810 public static extern GRPCCallError grpcsharp_test_callback([MarshalAs(UnmanagedType.FunctionPtr)] OpCompletionDelegate callback);
811
812 [DllImport("grpc_csharp_ext.dll")]
813 public static extern IntPtr grpcsharp_test_nop(IntPtr ptr);
814 }
815 }
816}