OLD | NEW |
(Empty) | |
| 1 #region Copyright notice and license |
| 2 |
| 3 // Copyright 2015-2016, 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 |
| 34 using System; |
| 35 using System.Collections.Concurrent; |
| 36 using System.Diagnostics; |
| 37 using System.IO; |
| 38 using System.Reflection; |
| 39 using System.Runtime.InteropServices; |
| 40 using System.Threading; |
| 41 |
| 42 using Grpc.Core.Logging; |
| 43 using Grpc.Core.Utils; |
| 44 |
| 45 namespace 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 intell
igent loading |
| 50 /// of the right configuration of the native extension based on current plat
form, 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_ve
rsion_string; |
| 59 |
| 60 public readonly Delegates.grpcsharp_batch_context_create_delegate grpcsh
arp_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_de
legate 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_trailin
g_metadata; |
| 67 public readonly Delegates.grpcsharp_batch_context_server_rpc_new_call_de
legate 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_de
legate grpcsharp_batch_context_server_rpc_new_host; |
| 70 public readonly Delegates.grpcsharp_batch_context_server_rpc_new_deadlin
e_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_c
ancelled_delegate grpcsharp_batch_context_recv_close_on_server_cancelled; |
| 73 public readonly Delegates.grpcsharp_batch_context_destroy_delegate grpcs
harp_batch_context_destroy; |
| 74 |
| 75 public readonly Delegates.grpcsharp_composite_call_credentials_create_de
legate grpcsharp_composite_call_credentials_create; |
| 76 public readonly Delegates.grpcsharp_call_credentials_release_delegate gr
pcsharp_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 grp
csharp_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_delegat
e 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 grpcs
harp_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 grpcsh
arp_call_set_credentials; |
| 92 public readonly Delegates.grpcsharp_call_get_peer_delegate grpcsharp_cal
l_get_peer; |
| 93 public readonly Delegates.grpcsharp_call_destroy_delegate grpcsharp_call
_destroy; |
| 94 |
| 95 public readonly Delegates.grpcsharp_channel_args_create_delegate grpcsha
rp_channel_args_create; |
| 96 public readonly Delegates.grpcsharp_channel_args_set_string_delegate grp
csharp_channel_args_set_string; |
| 97 public readonly Delegates.grpcsharp_channel_args_set_integer_delegate gr
pcsharp_channel_args_set_integer; |
| 98 public readonly Delegates.grpcsharp_channel_args_destroy_delegate grpcsh
arp_channel_args_destroy; |
| 99 |
| 100 public readonly Delegates.grpcsharp_override_default_ssl_roots grpcsharp
_override_default_ssl_roots; |
| 101 public readonly Delegates.grpcsharp_ssl_credentials_create_delegate grpc
sharp_ssl_credentials_create; |
| 102 public readonly Delegates.grpcsharp_composite_channel_credentials_create
_delegate grpcsharp_composite_channel_credentials_create; |
| 103 public readonly Delegates.grpcsharp_channel_credentials_release_delegate
grpcsharp_channel_credentials_release; |
| 104 |
| 105 public readonly Delegates.grpcsharp_insecure_channel_create_delegate grp
csharp_insecure_channel_create; |
| 106 public readonly Delegates.grpcsharp_secure_channel_create_delegate grpcs
harp_secure_channel_create; |
| 107 public readonly Delegates.grpcsharp_channel_create_call_delegate grpcsha
rp_channel_create_call; |
| 108 public readonly Delegates.grpcsharp_channel_check_connectivity_state_del
egate grpcsharp_channel_check_connectivity_state; |
| 109 public readonly Delegates.grpcsharp_channel_watch_connectivity_state_del
egate grpcsharp_channel_watch_connectivity_state; |
| 110 public readonly Delegates.grpcsharp_channel_get_target_delegate grpcshar
p_channel_get_target; |
| 111 public readonly Delegates.grpcsharp_channel_destroy_delegate grpcsharp_c
hannel_destroy; |
| 112 |
| 113 public readonly Delegates.grpcsharp_sizeof_grpc_event_delegate grpcsharp
_sizeof_grpc_event; |
| 114 |
| 115 public readonly Delegates.grpcsharp_completion_queue_create_delegate grp
csharp_completion_queue_create; |
| 116 public readonly Delegates.grpcsharp_completion_queue_shutdown_delegate g
rpcsharp_completion_queue_shutdown; |
| 117 public readonly Delegates.grpcsharp_completion_queue_next_delegate grpcs
harp_completion_queue_next; |
| 118 public readonly Delegates.grpcsharp_completion_queue_pluck_delegate grpc
sharp_completion_queue_pluck; |
| 119 public readonly Delegates.grpcsharp_completion_queue_destroy_delegate gr
pcsharp_completion_queue_destroy; |
| 120 |
| 121 public readonly Delegates.gprsharp_free_delegate gprsharp_free; |
| 122 |
| 123 public readonly Delegates.grpcsharp_metadata_array_create_delegate grpcs
harp_metadata_array_create; |
| 124 public readonly Delegates.grpcsharp_metadata_array_add_delegate grpcshar
p_metadata_array_add; |
| 125 public readonly Delegates.grpcsharp_metadata_array_count_delegate grpcsh
arp_metadata_array_count; |
| 126 public readonly Delegates.grpcsharp_metadata_array_get_key_delegate grpc
sharp_metadata_array_get_key; |
| 127 public readonly Delegates.grpcsharp_metadata_array_get_value_delegate gr
pcsharp_metadata_array_get_value; |
| 128 public readonly Delegates.grpcsharp_metadata_array_get_value_length_dele
gate grpcsharp_metadata_array_get_value_length; |
| 129 public readonly Delegates.grpcsharp_metadata_array_destroy_full_delegate
grpcsharp_metadata_array_destroy_full; |
| 130 |
| 131 public readonly Delegates.grpcsharp_redirect_log_delegate grpcsharp_redi
rect_log; |
| 132 |
| 133 public readonly Delegates.grpcsharp_metadata_credentials_create_from_plu
gin_delegate grpcsharp_metadata_credentials_create_from_plugin; |
| 134 public readonly Delegates.grpcsharp_metadata_credentials_notify_from_plu
gin_delegate grpcsharp_metadata_credentials_notify_from_plugin; |
| 135 |
| 136 public readonly Delegates.grpcsharp_ssl_server_credentials_create_delega
te grpcsharp_ssl_server_credentials_create; |
| 137 public readonly Delegates.grpcsharp_server_credentials_release_delegate
grpcsharp_server_credentials_release; |
| 138 |
| 139 public readonly Delegates.grpcsharp_server_create_delegate grpcsharp_ser
ver_create; |
| 140 public readonly Delegates.grpcsharp_server_add_insecure_http2_port_deleg
ate grpcsharp_server_add_insecure_http2_port; |
| 141 public readonly Delegates.grpcsharp_server_add_secure_http2_port_delegat
e grpcsharp_server_add_secure_http2_port; |
| 142 public readonly Delegates.grpcsharp_server_start_delegate grpcsharp_serv
er_start; |
| 143 public readonly Delegates.grpcsharp_server_request_call_delegate grpcsha
rp_server_request_call; |
| 144 public readonly Delegates.grpcsharp_server_cancel_all_calls_delegate grp
csharp_server_cancel_all_calls; |
| 145 public readonly Delegates.grpcsharp_server_shutdown_and_notify_callback_
delegate grpcsharp_server_shutdown_and_notify_callback; |
| 146 public readonly Delegates.grpcsharp_server_destroy_delegate grpcsharp_se
rver_destroy; |
| 147 |
| 148 public readonly Delegates.gprsharp_now_delegate gprsharp_now; |
| 149 public readonly Delegates.gprsharp_inf_future_delegate gprsharp_inf_futu
re; |
| 150 public readonly Delegates.gprsharp_inf_past_delegate gprsharp_inf_past; |
| 151 public readonly Delegates.gprsharp_convert_clock_type_delegate gprsharp_
convert_clock_type; |
| 152 public readonly Delegates.gprsharp_sizeof_timespec_delegate gprsharp_siz
eof_timespec; |
| 153 |
| 154 public readonly Delegates.grpcsharp_test_callback_delegate grpcsharp_tes
t_callback; |
| 155 public readonly Delegates.grpcsharp_test_nop_delegate grpcsharp_test_nop
; |
| 156 |
| 157 #endregion |
| 158 |
| 159 public NativeMethods(UnmanagedLibrary library) |
| 160 { |
| 161 if (PlatformApis.IsLinux || PlatformApis.IsMacOSX) |
| 162 { |
| 163 this.grpcsharp_init = GetMethodDelegate<Delegates.grpcsharp_init
_delegate>(library); |
| 164 this.grpcsharp_shutdown = GetMethodDelegate<Delegates.grpcsharp_
shutdown_delegate>(library); |
| 165 this.grpcsharp_version_string = GetMethodDelegate<Delegates.grpc
sharp_version_string_delegate>(library); |
| 166 |
| 167 this.grpcsharp_batch_context_create = GetMethodDelegate<Delegate
s.grpcsharp_batch_context_create_delegate>(library); |
| 168 this.grpcsharp_batch_context_recv_initial_metadata = GetMethodDe
legate<Delegates.grpcsharp_batch_context_recv_initial_metadata_delegate>(library
); |
| 169 this.grpcsharp_batch_context_recv_message_length = GetMethodDele
gate<Delegates.grpcsharp_batch_context_recv_message_length_delegate>(library); |
| 170 this.grpcsharp_batch_context_recv_message_to_buffer = GetMethodD
elegate<Delegates.grpcsharp_batch_context_recv_message_to_buffer_delegate>(libra
ry); |
| 171 this.grpcsharp_batch_context_recv_status_on_client_status = GetM
ethodDelegate<Delegates.grpcsharp_batch_context_recv_status_on_client_status_del
egate>(library); |
| 172 this.grpcsharp_batch_context_recv_status_on_client_details = Get
MethodDelegate<Delegates.grpcsharp_batch_context_recv_status_on_client_details_d
elegate>(library); |
| 173 this.grpcsharp_batch_context_recv_status_on_client_trailing_meta
data = GetMethodDelegate<Delegates.grpcsharp_batch_context_recv_status_on_client
_trailing_metadata_delegate>(library); |
| 174 this.grpcsharp_batch_context_server_rpc_new_call = GetMethodDele
gate<Delegates.grpcsharp_batch_context_server_rpc_new_call_delegate>(library); |
| 175 this.grpcsharp_batch_context_server_rpc_new_method = GetMethodDe
legate<Delegates.grpcsharp_batch_context_server_rpc_new_method_delegate>(library
); |
| 176 this.grpcsharp_batch_context_server_rpc_new_host = GetMethodDele
gate<Delegates.grpcsharp_batch_context_server_rpc_new_host_delegate>(library); |
| 177 this.grpcsharp_batch_context_server_rpc_new_deadline = GetMethod
Delegate<Delegates.grpcsharp_batch_context_server_rpc_new_deadline_delegate>(lib
rary); |
| 178 this.grpcsharp_batch_context_server_rpc_new_request_metadata = G
etMethodDelegate<Delegates.grpcsharp_batch_context_server_rpc_new_request_metada
ta_delegate>(library); |
| 179 this.grpcsharp_batch_context_recv_close_on_server_cancelled = Ge
tMethodDelegate<Delegates.grpcsharp_batch_context_recv_close_on_server_cancelled
_delegate>(library); |
| 180 this.grpcsharp_batch_context_destroy = GetMethodDelegate<Delegat
es.grpcsharp_batch_context_destroy_delegate>(library); |
| 181 |
| 182 this.grpcsharp_composite_call_credentials_create = GetMethodDele
gate<Delegates.grpcsharp_composite_call_credentials_create_delegate>(library); |
| 183 this.grpcsharp_call_credentials_release = GetMethodDelegate<Dele
gates.grpcsharp_call_credentials_release_delegate>(library); |
| 184 |
| 185 this.grpcsharp_call_cancel = GetMethodDelegate<Delegates.grpcsha
rp_call_cancel_delegate>(library); |
| 186 this.grpcsharp_call_cancel_with_status = GetMethodDelegate<Deleg
ates.grpcsharp_call_cancel_with_status_delegate>(library); |
| 187 this.grpcsharp_call_start_unary = GetMethodDelegate<Delegates.gr
pcsharp_call_start_unary_delegate>(library); |
| 188 this.grpcsharp_call_start_client_streaming = GetMethodDelegate<D
elegates.grpcsharp_call_start_client_streaming_delegate>(library); |
| 189 this.grpcsharp_call_start_server_streaming = GetMethodDelegate<D
elegates.grpcsharp_call_start_server_streaming_delegate>(library); |
| 190 this.grpcsharp_call_start_duplex_streaming = GetMethodDelegate<D
elegates.grpcsharp_call_start_duplex_streaming_delegate>(library); |
| 191 this.grpcsharp_call_send_message = GetMethodDelegate<Delegates.g
rpcsharp_call_send_message_delegate>(library); |
| 192 this.grpcsharp_call_send_close_from_client = GetMethodDelegate<D
elegates.grpcsharp_call_send_close_from_client_delegate>(library); |
| 193 this.grpcsharp_call_send_status_from_server = GetMethodDelegate<
Delegates.grpcsharp_call_send_status_from_server_delegate>(library); |
| 194 this.grpcsharp_call_recv_message = GetMethodDelegate<Delegates.g
rpcsharp_call_recv_message_delegate>(library); |
| 195 this.grpcsharp_call_recv_initial_metadata = GetMethodDelegate<De
legates.grpcsharp_call_recv_initial_metadata_delegate>(library); |
| 196 this.grpcsharp_call_start_serverside = GetMethodDelegate<Delegat
es.grpcsharp_call_start_serverside_delegate>(library); |
| 197 this.grpcsharp_call_send_initial_metadata = GetMethodDelegate<De
legates.grpcsharp_call_send_initial_metadata_delegate>(library); |
| 198 this.grpcsharp_call_set_credentials = GetMethodDelegate<Delegate
s.grpcsharp_call_set_credentials_delegate>(library); |
| 199 this.grpcsharp_call_get_peer = GetMethodDelegate<Delegates.grpcs
harp_call_get_peer_delegate>(library); |
| 200 this.grpcsharp_call_destroy = GetMethodDelegate<Delegates.grpcsh
arp_call_destroy_delegate>(library); |
| 201 |
| 202 this.grpcsharp_channel_args_create = GetMethodDelegate<Delegates
.grpcsharp_channel_args_create_delegate>(library); |
| 203 this.grpcsharp_channel_args_set_string = GetMethodDelegate<Deleg
ates.grpcsharp_channel_args_set_string_delegate>(library); |
| 204 this.grpcsharp_channel_args_set_integer = GetMethodDelegate<Dele
gates.grpcsharp_channel_args_set_integer_delegate>(library); |
| 205 this.grpcsharp_channel_args_destroy = GetMethodDelegate<Delegate
s.grpcsharp_channel_args_destroy_delegate>(library); |
| 206 |
| 207 this.grpcsharp_override_default_ssl_roots = GetMethodDelegate<De
legates.grpcsharp_override_default_ssl_roots>(library); |
| 208 this.grpcsharp_ssl_credentials_create = GetMethodDelegate<Delega
tes.grpcsharp_ssl_credentials_create_delegate>(library); |
| 209 this.grpcsharp_composite_channel_credentials_create = GetMethodD
elegate<Delegates.grpcsharp_composite_channel_credentials_create_delegate>(libra
ry); |
| 210 this.grpcsharp_channel_credentials_release = GetMethodDelegate<D
elegates.grpcsharp_channel_credentials_release_delegate>(library); |
| 211 |
| 212 this.grpcsharp_insecure_channel_create = GetMethodDelegate<Deleg
ates.grpcsharp_insecure_channel_create_delegate>(library); |
| 213 this.grpcsharp_secure_channel_create = GetMethodDelegate<Delegat
es.grpcsharp_secure_channel_create_delegate>(library); |
| 214 this.grpcsharp_channel_create_call = GetMethodDelegate<Delegates
.grpcsharp_channel_create_call_delegate>(library); |
| 215 this.grpcsharp_channel_check_connectivity_state = GetMethodDeleg
ate<Delegates.grpcsharp_channel_check_connectivity_state_delegate>(library); |
| 216 this.grpcsharp_channel_watch_connectivity_state = GetMethodDeleg
ate<Delegates.grpcsharp_channel_watch_connectivity_state_delegate>(library); |
| 217 this.grpcsharp_channel_get_target = GetMethodDelegate<Delegates.
grpcsharp_channel_get_target_delegate>(library); |
| 218 this.grpcsharp_channel_destroy = GetMethodDelegate<Delegates.grp
csharp_channel_destroy_delegate>(library); |
| 219 |
| 220 this.grpcsharp_sizeof_grpc_event = GetMethodDelegate<Delegates.g
rpcsharp_sizeof_grpc_event_delegate>(library); |
| 221 |
| 222 this.grpcsharp_completion_queue_create = GetMethodDelegate<Deleg
ates.grpcsharp_completion_queue_create_delegate>(library); |
| 223 this.grpcsharp_completion_queue_shutdown = GetMethodDelegate<Del
egates.grpcsharp_completion_queue_shutdown_delegate>(library); |
| 224 this.grpcsharp_completion_queue_next = GetMethodDelegate<Delegat
es.grpcsharp_completion_queue_next_delegate>(library); |
| 225 this.grpcsharp_completion_queue_pluck = GetMethodDelegate<Delega
tes.grpcsharp_completion_queue_pluck_delegate>(library); |
| 226 this.grpcsharp_completion_queue_destroy = GetMethodDelegate<Dele
gates.grpcsharp_completion_queue_destroy_delegate>(library); |
| 227 |
| 228 this.gprsharp_free = GetMethodDelegate<Delegates.gprsharp_free_d
elegate>(library); |
| 229 |
| 230 this.grpcsharp_metadata_array_create = GetMethodDelegate<Delegat
es.grpcsharp_metadata_array_create_delegate>(library); |
| 231 this.grpcsharp_metadata_array_add = GetMethodDelegate<Delegates.
grpcsharp_metadata_array_add_delegate>(library); |
| 232 this.grpcsharp_metadata_array_count = GetMethodDelegate<Delegate
s.grpcsharp_metadata_array_count_delegate>(library); |
| 233 this.grpcsharp_metadata_array_get_key = GetMethodDelegate<Delega
tes.grpcsharp_metadata_array_get_key_delegate>(library); |
| 234 this.grpcsharp_metadata_array_get_value = GetMethodDelegate<Dele
gates.grpcsharp_metadata_array_get_value_delegate>(library); |
| 235 this.grpcsharp_metadata_array_get_value_length = GetMethodDelega
te<Delegates.grpcsharp_metadata_array_get_value_length_delegate>(library); |
| 236 this.grpcsharp_metadata_array_destroy_full = GetMethodDelegate<D
elegates.grpcsharp_metadata_array_destroy_full_delegate>(library); |
| 237 |
| 238 this.grpcsharp_redirect_log = GetMethodDelegate<Delegates.grpcsh
arp_redirect_log_delegate>(library); |
| 239 |
| 240 this.grpcsharp_metadata_credentials_create_from_plugin = GetMeth
odDelegate<Delegates.grpcsharp_metadata_credentials_create_from_plugin_delegate>
(library); |
| 241 this.grpcsharp_metadata_credentials_notify_from_plugin = GetMeth
odDelegate<Delegates.grpcsharp_metadata_credentials_notify_from_plugin_delegate>
(library); |
| 242 |
| 243 this.grpcsharp_ssl_server_credentials_create = GetMethodDelegate
<Delegates.grpcsharp_ssl_server_credentials_create_delegate>(library); |
| 244 this.grpcsharp_server_credentials_release = GetMethodDelegate<De
legates.grpcsharp_server_credentials_release_delegate>(library); |
| 245 |
| 246 this.grpcsharp_server_create = GetMethodDelegate<Delegates.grpcs
harp_server_create_delegate>(library); |
| 247 this.grpcsharp_server_add_insecure_http2_port = GetMethodDelegat
e<Delegates.grpcsharp_server_add_insecure_http2_port_delegate>(library); |
| 248 this.grpcsharp_server_add_secure_http2_port = GetMethodDelegate<
Delegates.grpcsharp_server_add_secure_http2_port_delegate>(library); |
| 249 this.grpcsharp_server_start = GetMethodDelegate<Delegates.grpcsh
arp_server_start_delegate>(library); |
| 250 this.grpcsharp_server_request_call = GetMethodDelegate<Delegates
.grpcsharp_server_request_call_delegate>(library); |
| 251 this.grpcsharp_server_cancel_all_calls = GetMethodDelegate<Deleg
ates.grpcsharp_server_cancel_all_calls_delegate>(library); |
| 252 this.grpcsharp_server_shutdown_and_notify_callback = GetMethodDe
legate<Delegates.grpcsharp_server_shutdown_and_notify_callback_delegate>(library
); |
| 253 this.grpcsharp_server_destroy = GetMethodDelegate<Delegates.grpc
sharp_server_destroy_delegate>(library); |
| 254 |
| 255 this.gprsharp_now = GetMethodDelegate<Delegates.gprsharp_now_del
egate>(library); |
| 256 this.gprsharp_inf_future = GetMethodDelegate<Delegates.gprsharp_
inf_future_delegate>(library); |
| 257 this.gprsharp_inf_past = GetMethodDelegate<Delegates.gprsharp_in
f_past_delegate>(library); |
| 258 this.gprsharp_convert_clock_type = GetMethodDelegate<Delegates.g
prsharp_convert_clock_type_delegate>(library); |
| 259 this.gprsharp_sizeof_timespec = GetMethodDelegate<Delegates.gprs
harp_sizeof_timespec_delegate>(library); |
| 260 |
| 261 this.grpcsharp_test_callback = GetMethodDelegate<Delegates.grpcs
harp_test_callback_delegate>(library); |
| 262 this.grpcsharp_test_nop = GetMethodDelegate<Delegates.grpcsharp_
test_nop_delegate>(library); |
| 263 } |
| 264 else |
| 265 { |
| 266 // Windows or fallback |
| 267 this.grpcsharp_init = PInvokeMethods.grpcsharp_init; |
| 268 this.grpcsharp_shutdown = PInvokeMethods.grpcsharp_shutdown; |
| 269 this.grpcsharp_version_string = PInvokeMethods.grpcsharp_version
_string; |
| 270 |
| 271 this.grpcsharp_batch_context_create = PInvokeMethods.grpcsharp_b
atch_context_create; |
| 272 this.grpcsharp_batch_context_recv_initial_metadata = PInvokeMeth
ods.grpcsharp_batch_context_recv_initial_metadata; |
| 273 this.grpcsharp_batch_context_recv_message_length = PInvokeMethod
s.grpcsharp_batch_context_recv_message_length; |
| 274 this.grpcsharp_batch_context_recv_message_to_buffer = PInvokeMet
hods.grpcsharp_batch_context_recv_message_to_buffer; |
| 275 this.grpcsharp_batch_context_recv_status_on_client_status = PInv
okeMethods.grpcsharp_batch_context_recv_status_on_client_status; |
| 276 this.grpcsharp_batch_context_recv_status_on_client_details = PIn
vokeMethods.grpcsharp_batch_context_recv_status_on_client_details; |
| 277 this.grpcsharp_batch_context_recv_status_on_client_trailing_meta
data = PInvokeMethods.grpcsharp_batch_context_recv_status_on_client_trailing_met
adata; |
| 278 this.grpcsharp_batch_context_server_rpc_new_call = PInvokeMethod
s.grpcsharp_batch_context_server_rpc_new_call; |
| 279 this.grpcsharp_batch_context_server_rpc_new_method = PInvokeMeth
ods.grpcsharp_batch_context_server_rpc_new_method; |
| 280 this.grpcsharp_batch_context_server_rpc_new_host = PInvokeMethod
s.grpcsharp_batch_context_server_rpc_new_host; |
| 281 this.grpcsharp_batch_context_server_rpc_new_deadline = PInvokeMe
thods.grpcsharp_batch_context_server_rpc_new_deadline; |
| 282 this.grpcsharp_batch_context_server_rpc_new_request_metadata = P
InvokeMethods.grpcsharp_batch_context_server_rpc_new_request_metadata; |
| 283 this.grpcsharp_batch_context_recv_close_on_server_cancelled = PI
nvokeMethods.grpcsharp_batch_context_recv_close_on_server_cancelled; |
| 284 this.grpcsharp_batch_context_destroy = PInvokeMethods.grpcsharp_
batch_context_destroy; |
| 285 |
| 286 this.grpcsharp_composite_call_credentials_create = PInvokeMethod
s.grpcsharp_composite_call_credentials_create; |
| 287 this.grpcsharp_call_credentials_release = PInvokeMethods.grpcsha
rp_call_credentials_release; |
| 288 |
| 289 this.grpcsharp_call_cancel = PInvokeMethods.grpcsharp_call_cance
l; |
| 290 this.grpcsharp_call_cancel_with_status = PInvokeMethods.grpcshar
p_call_cancel_with_status; |
| 291 this.grpcsharp_call_start_unary = PInvokeMethods.grpcsharp_call_
start_unary; |
| 292 this.grpcsharp_call_start_client_streaming = PInvokeMethods.grpc
sharp_call_start_client_streaming; |
| 293 this.grpcsharp_call_start_server_streaming = PInvokeMethods.grpc
sharp_call_start_server_streaming; |
| 294 this.grpcsharp_call_start_duplex_streaming = PInvokeMethods.grpc
sharp_call_start_duplex_streaming; |
| 295 this.grpcsharp_call_send_message = PInvokeMethods.grpcsharp_call
_send_message; |
| 296 this.grpcsharp_call_send_close_from_client = PInvokeMethods.grpc
sharp_call_send_close_from_client; |
| 297 this.grpcsharp_call_send_status_from_server = PInvokeMethods.grp
csharp_call_send_status_from_server; |
| 298 this.grpcsharp_call_recv_message = PInvokeMethods.grpcsharp_call
_recv_message; |
| 299 this.grpcsharp_call_recv_initial_metadata = PInvokeMethods.grpcs
harp_call_recv_initial_metadata; |
| 300 this.grpcsharp_call_start_serverside = PInvokeMethods.grpcsharp_
call_start_serverside; |
| 301 this.grpcsharp_call_send_initial_metadata = PInvokeMethods.grpcs
harp_call_send_initial_metadata; |
| 302 this.grpcsharp_call_set_credentials = PInvokeMethods.grpcsharp_c
all_set_credentials; |
| 303 this.grpcsharp_call_get_peer = PInvokeMethods.grpcsharp_call_get
_peer; |
| 304 this.grpcsharp_call_destroy = PInvokeMethods.grpcsharp_call_dest
roy; |
| 305 |
| 306 this.grpcsharp_channel_args_create = PInvokeMethods.grpcsharp_ch
annel_args_create; |
| 307 this.grpcsharp_channel_args_set_string = PInvokeMethods.grpcshar
p_channel_args_set_string; |
| 308 this.grpcsharp_channel_args_set_integer = PInvokeMethods.grpcsha
rp_channel_args_set_integer; |
| 309 this.grpcsharp_channel_args_destroy = PInvokeMethods.grpcsharp_c
hannel_args_destroy; |
| 310 |
| 311 this.grpcsharp_override_default_ssl_roots = PInvokeMethods.grpcs
harp_override_default_ssl_roots; |
| 312 this.grpcsharp_ssl_credentials_create = PInvokeMethods.grpcsharp
_ssl_credentials_create; |
| 313 this.grpcsharp_composite_channel_credentials_create = PInvokeMet
hods.grpcsharp_composite_channel_credentials_create; |
| 314 this.grpcsharp_channel_credentials_release = PInvokeMethods.grpc
sharp_channel_credentials_release; |
| 315 |
| 316 this.grpcsharp_insecure_channel_create = PInvokeMethods.grpcshar
p_insecure_channel_create; |
| 317 this.grpcsharp_secure_channel_create = PInvokeMethods.grpcsharp_
secure_channel_create; |
| 318 this.grpcsharp_channel_create_call = PInvokeMethods.grpcsharp_ch
annel_create_call; |
| 319 this.grpcsharp_channel_check_connectivity_state = PInvokeMethods
.grpcsharp_channel_check_connectivity_state; |
| 320 this.grpcsharp_channel_watch_connectivity_state = PInvokeMethods
.grpcsharp_channel_watch_connectivity_state; |
| 321 this.grpcsharp_channel_get_target = PInvokeMethods.grpcsharp_cha
nnel_get_target; |
| 322 this.grpcsharp_channel_destroy = PInvokeMethods.grpcsharp_channe
l_destroy; |
| 323 |
| 324 this.grpcsharp_sizeof_grpc_event = PInvokeMethods.grpcsharp_size
of_grpc_event; |
| 325 |
| 326 this.grpcsharp_completion_queue_create = PInvokeMethods.grpcshar
p_completion_queue_create; |
| 327 this.grpcsharp_completion_queue_shutdown = PInvokeMethods.grpcsh
arp_completion_queue_shutdown; |
| 328 this.grpcsharp_completion_queue_next = PInvokeMethods.grpcsharp_
completion_queue_next; |
| 329 this.grpcsharp_completion_queue_pluck = PInvokeMethods.grpcsharp
_completion_queue_pluck; |
| 330 this.grpcsharp_completion_queue_destroy = PInvokeMethods.grpcsha
rp_completion_queue_destroy; |
| 331 |
| 332 this.gprsharp_free = PInvokeMethods.gprsharp_free; |
| 333 |
| 334 this.grpcsharp_metadata_array_create = PInvokeMethods.grpcsharp_
metadata_array_create; |
| 335 this.grpcsharp_metadata_array_add = PInvokeMethods.grpcsharp_met
adata_array_add; |
| 336 this.grpcsharp_metadata_array_count = PInvokeMethods.grpcsharp_m
etadata_array_count; |
| 337 this.grpcsharp_metadata_array_get_key = PInvokeMethods.grpcsharp
_metadata_array_get_key; |
| 338 this.grpcsharp_metadata_array_get_value = PInvokeMethods.grpcsha
rp_metadata_array_get_value; |
| 339 this.grpcsharp_metadata_array_get_value_length = PInvokeMethods.
grpcsharp_metadata_array_get_value_length; |
| 340 this.grpcsharp_metadata_array_destroy_full = PInvokeMethods.grpc
sharp_metadata_array_destroy_full; |
| 341 |
| 342 this.grpcsharp_redirect_log = PInvokeMethods.grpcsharp_redirect_
log; |
| 343 |
| 344 this.grpcsharp_metadata_credentials_create_from_plugin = PInvoke
Methods.grpcsharp_metadata_credentials_create_from_plugin; |
| 345 this.grpcsharp_metadata_credentials_notify_from_plugin = PInvoke
Methods.grpcsharp_metadata_credentials_notify_from_plugin; |
| 346 |
| 347 this.grpcsharp_ssl_server_credentials_create = PInvokeMethods.gr
pcsharp_ssl_server_credentials_create; |
| 348 this.grpcsharp_server_credentials_release = PInvokeMethods.grpcs
harp_server_credentials_release; |
| 349 |
| 350 this.grpcsharp_server_create = PInvokeMethods.grpcsharp_server_c
reate; |
| 351 this.grpcsharp_server_add_insecure_http2_port = PInvokeMethods.g
rpcsharp_server_add_insecure_http2_port; |
| 352 this.grpcsharp_server_add_secure_http2_port = PInvokeMethods.grp
csharp_server_add_secure_http2_port; |
| 353 this.grpcsharp_server_start = PInvokeMethods.grpcsharp_server_st
art; |
| 354 this.grpcsharp_server_request_call = PInvokeMethods.grpcsharp_se
rver_request_call; |
| 355 this.grpcsharp_server_cancel_all_calls = PInvokeMethods.grpcshar
p_server_cancel_all_calls; |
| 356 this.grpcsharp_server_shutdown_and_notify_callback = PInvokeMeth
ods.grpcsharp_server_shutdown_and_notify_callback; |
| 357 this.grpcsharp_server_destroy = PInvokeMethods.grpcsharp_server_
destroy; |
| 358 |
| 359 this.gprsharp_now = PInvokeMethods.gprsharp_now; |
| 360 this.gprsharp_inf_future = PInvokeMethods.gprsharp_inf_future; |
| 361 this.gprsharp_inf_past = PInvokeMethods.gprsharp_inf_past; |
| 362 this.gprsharp_convert_clock_type = PInvokeMethods.gprsharp_conve
rt_clock_type; |
| 363 this.gprsharp_sizeof_timespec = PInvokeMethods.gprsharp_sizeof_t
imespec; |
| 364 |
| 365 this.grpcsharp_test_callback = PInvokeMethods.grpcsharp_test_cal
lback; |
| 366 this.grpcsharp_test_nop = PInvokeMethods.grpcsharp_test_nop; |
| 367 } |
| 368 } |
| 369 |
| 370 /// <summary> |
| 371 /// Gets singleton instance of this class. |
| 372 /// </summary> |
| 373 public static NativeMethods Get() |
| 374 { |
| 375 return NativeExtension.Get().NativeMethods; |
| 376 } |
| 377 |
| 378 static T GetMethodDelegate<T>(UnmanagedLibrary library) |
| 379 where T : class |
| 380 { |
| 381 var methodName = RemoveStringSuffix(typeof(T).Name, "_delegate"); |
| 382 return library.GetNativeMethodDelegate<T>(methodName); |
| 383 } |
| 384 |
| 385 static string RemoveStringSuffix(string str, string toRemove) |
| 386 { |
| 387 if (!str.EndsWith(toRemove)) |
| 388 { |
| 389 return str; |
| 390 } |
| 391 return str.Substring(0, str.Length - toRemove.Length); |
| 392 } |
| 393 |
| 394 /// <summary> |
| 395 /// Delegate types for all published native methods. Declared under inne
r class to prevent scope pollution. |
| 396 /// </summary> |
| 397 public class Delegates |
| 398 { |
| 399 public delegate void grpcsharp_init_delegate(); |
| 400 public delegate void grpcsharp_shutdown_delegate(); |
| 401 public delegate IntPtr grpcsharp_version_string_delegate(); // retu
rns not-owned const char* |
| 402 |
| 403 public delegate BatchContextSafeHandle grpcsharp_batch_context_creat
e_delegate(); |
| 404 public delegate IntPtr grpcsharp_batch_context_recv_initial_metadata
_delegate(BatchContextSafeHandle ctx); |
| 405 public delegate IntPtr grpcsharp_batch_context_recv_message_length_d
elegate(BatchContextSafeHandle ctx); |
| 406 public delegate void grpcsharp_batch_context_recv_message_to_buffer_
delegate(BatchContextSafeHandle ctx, byte[] buffer, UIntPtr bufferLen); |
| 407 public delegate StatusCode grpcsharp_batch_context_recv_status_on_cl
ient_status_delegate(BatchContextSafeHandle ctx); |
| 408 public delegate IntPtr grpcsharp_batch_context_recv_status_on_client
_details_delegate(BatchContextSafeHandle ctx); // returns const char* |
| 409 public delegate IntPtr grpcsharp_batch_context_recv_status_on_client
_trailing_metadata_delegate(BatchContextSafeHandle ctx); |
| 410 public delegate CallSafeHandle grpcsharp_batch_context_server_rpc_ne
w_call_delegate(BatchContextSafeHandle ctx); |
| 411 public delegate IntPtr grpcsharp_batch_context_server_rpc_new_method
_delegate(BatchContextSafeHandle ctx); // returns const char* |
| 412 public delegate IntPtr grpcsharp_batch_context_server_rpc_new_host_d
elegate(BatchContextSafeHandle ctx); // returns const char* |
| 413 public delegate Timespec grpcsharp_batch_context_server_rpc_new_dead
line_delegate(BatchContextSafeHandle ctx); |
| 414 public delegate IntPtr grpcsharp_batch_context_server_rpc_new_reques
t_metadata_delegate(BatchContextSafeHandle ctx); |
| 415 public delegate int grpcsharp_batch_context_recv_close_on_server_can
celled_delegate(BatchContextSafeHandle ctx); |
| 416 public delegate void grpcsharp_batch_context_destroy_delegate(IntPtr
ctx); |
| 417 |
| 418 public delegate CallCredentialsSafeHandle grpcsharp_composite_call_c
redentials_create_delegate(CallCredentialsSafeHandle creds1, CallCredentialsSafe
Handle creds2); |
| 419 public delegate void grpcsharp_call_credentials_release_delegate(Int
Ptr credentials); |
| 420 |
| 421 public delegate GRPCCallError grpcsharp_call_cancel_delegate(CallSaf
eHandle call); |
| 422 public delegate GRPCCallError grpcsharp_call_cancel_with_status_dele
gate(CallSafeHandle call, StatusCode status, string description); |
| 423 public delegate GRPCCallError grpcsharp_call_start_unary_delegate(Ca
llSafeHandle call, |
| 424 BatchContextSafeHandle ctx, byte[] send_buffer, UIntPtr send_buf
fer_len, MetadataArraySafeHandle metadataArray, WriteFlags writeFlags); |
| 425 public delegate GRPCCallError grpcsharp_call_start_client_streaming_
delegate(CallSafeHandle call, |
| 426 BatchContextSafeHandle ctx, MetadataArraySafeHandle metadataArra
y); |
| 427 public delegate GRPCCallError grpcsharp_call_start_server_streaming_
delegate(CallSafeHandle call, |
| 428 BatchContextSafeHandle ctx, byte[] send_buffer, UIntPtr send_buf
fer_len, |
| 429 MetadataArraySafeHandle metadataArray, WriteFlags writeFlags); |
| 430 public delegate GRPCCallError grpcsharp_call_start_duplex_streaming_
delegate(CallSafeHandle call, |
| 431 BatchContextSafeHandle ctx, MetadataArraySafeHandle metadataArra
y); |
| 432 public delegate GRPCCallError grpcsharp_call_send_message_delegate(C
allSafeHandle call, |
| 433 BatchContextSafeHandle ctx, byte[] send_buffer, UIntPtr send_buf
fer_len, WriteFlags writeFlags, bool sendEmptyInitialMetadata); |
| 434 public delegate GRPCCallError grpcsharp_call_send_close_from_client_
delegate(CallSafeHandle call, |
| 435 BatchContextSafeHandle ctx); |
| 436 public delegate GRPCCallError grpcsharp_call_send_status_from_server
_delegate(CallSafeHandle call, |
| 437 BatchContextSafeHandle ctx, StatusCode statusCode, string status
Message, MetadataArraySafeHandle metadataArray, bool sendEmptyInitialMetadata); |
| 438 public delegate GRPCCallError grpcsharp_call_recv_message_delegate(C
allSafeHandle call, |
| 439 BatchContextSafeHandle ctx); |
| 440 public delegate GRPCCallError grpcsharp_call_recv_initial_metadata_d
elegate(CallSafeHandle call, |
| 441 BatchContextSafeHandle ctx); |
| 442 public delegate GRPCCallError grpcsharp_call_start_serverside_delega
te(CallSafeHandle call, |
| 443 BatchContextSafeHandle ctx); |
| 444 public delegate GRPCCallError grpcsharp_call_send_initial_metadata_d
elegate(CallSafeHandle call, |
| 445 BatchContextSafeHandle ctx, MetadataArraySafeHandle metadataArra
y); |
| 446 public delegate GRPCCallError grpcsharp_call_set_credentials_delegat
e(CallSafeHandle call, CallCredentialsSafeHandle credentials); |
| 447 public delegate CStringSafeHandle grpcsharp_call_get_peer_delegate(C
allSafeHandle call); |
| 448 public delegate void grpcsharp_call_destroy_delegate(IntPtr call); |
| 449 |
| 450 public delegate ChannelArgsSafeHandle grpcsharp_channel_args_create_
delegate(UIntPtr numArgs); |
| 451 public delegate void grpcsharp_channel_args_set_string_delegate(Chan
nelArgsSafeHandle args, UIntPtr index, string key, string value); |
| 452 public delegate void grpcsharp_channel_args_set_integer_delegate(Cha
nnelArgsSafeHandle args, UIntPtr index, string key, int value); |
| 453 public delegate void grpcsharp_channel_args_destroy_delegate(IntPtr
args); |
| 454 |
| 455 public delegate void grpcsharp_override_default_ssl_roots(string pem
RootCerts); |
| 456 public delegate ChannelCredentialsSafeHandle grpcsharp_ssl_credentia
ls_create_delegate(string pemRootCerts, string keyCertPairCertChain, string keyC
ertPairPrivateKey); |
| 457 public delegate ChannelCredentialsSafeHandle grpcsharp_composite_cha
nnel_credentials_create_delegate(ChannelCredentialsSafeHandle channelCreds, Call
CredentialsSafeHandle callCreds); |
| 458 public delegate void grpcsharp_channel_credentials_release_delegate(
IntPtr credentials); |
| 459 |
| 460 public delegate ChannelSafeHandle grpcsharp_insecure_channel_create_
delegate(string target, ChannelArgsSafeHandle channelArgs); |
| 461 public delegate ChannelSafeHandle grpcsharp_secure_channel_create_de
legate(ChannelCredentialsSafeHandle credentials, string target, ChannelArgsSafeH
andle channelArgs); |
| 462 public delegate CallSafeHandle grpcsharp_channel_create_call_delegat
e(ChannelSafeHandle channel, CallSafeHandle parentCall, ContextPropagationFlags
propagationMask, CompletionQueueSafeHandle cq, string method, string host, Times
pec deadline); |
| 463 public delegate ChannelState grpcsharp_channel_check_connectivity_st
ate_delegate(ChannelSafeHandle channel, int tryToConnect); |
| 464 public delegate void grpcsharp_channel_watch_connectivity_state_dele
gate(ChannelSafeHandle channel, ChannelState lastObservedState, |
| 465 Timespec deadline, CompletionQueueSafeHandle cq, BatchContextSaf
eHandle ctx); |
| 466 public delegate CStringSafeHandle grpcsharp_channel_get_target_deleg
ate(ChannelSafeHandle call); |
| 467 public delegate void grpcsharp_channel_destroy_delegate(IntPtr chann
el); |
| 468 |
| 469 public delegate int grpcsharp_sizeof_grpc_event_delegate(); |
| 470 |
| 471 public delegate CompletionQueueSafeHandle grpcsharp_completion_queue
_create_delegate(); |
| 472 public delegate void grpcsharp_completion_queue_shutdown_delegate(Co
mpletionQueueSafeHandle cq); |
| 473 public delegate CompletionQueueEvent grpcsharp_completion_queue_next
_delegate(CompletionQueueSafeHandle cq); |
| 474 public delegate CompletionQueueEvent grpcsharp_completion_queue_pluc
k_delegate(CompletionQueueSafeHandle cq, IntPtr tag); |
| 475 public delegate void grpcsharp_completion_queue_destroy_delegate(Int
Ptr cq); |
| 476 |
| 477 public delegate void gprsharp_free_delegate(IntPtr ptr); |
| 478 |
| 479 public delegate MetadataArraySafeHandle grpcsharp_metadata_array_cre
ate_delegate(UIntPtr capacity); |
| 480 public delegate void grpcsharp_metadata_array_add_delegate(MetadataA
rraySafeHandle array, string key, byte[] value, UIntPtr valueLength); |
| 481 public delegate UIntPtr grpcsharp_metadata_array_count_delegate(IntP
tr metadataArray); |
| 482 public delegate IntPtr grpcsharp_metadata_array_get_key_delegate(Int
Ptr metadataArray, UIntPtr index); |
| 483 public delegate IntPtr grpcsharp_metadata_array_get_value_delegate(I
ntPtr metadataArray, UIntPtr index); |
| 484 public delegate UIntPtr grpcsharp_metadata_array_get_value_length_de
legate(IntPtr metadataArray, UIntPtr index); |
| 485 public delegate void grpcsharp_metadata_array_destroy_full_delegate(
IntPtr array); |
| 486 |
| 487 public delegate void grpcsharp_redirect_log_delegate(GprLogDelegate
callback); |
| 488 |
| 489 public delegate CallCredentialsSafeHandle grpcsharp_metadata_credent
ials_create_from_plugin_delegate(NativeMetadataInterceptor interceptor); |
| 490 public delegate void grpcsharp_metadata_credentials_notify_from_plug
in_delegate(IntPtr callbackPtr, IntPtr userData, MetadataArraySafeHandle metadat
aArray, StatusCode statusCode, string errorDetails); |
| 491 |
| 492 public delegate ServerCredentialsSafeHandle grpcsharp_ssl_server_cre
dentials_create_delegate(string pemRootCerts, string[] keyCertPairCertChainArray
, string[] keyCertPairPrivateKeyArray, UIntPtr numKeyCertPairs, bool forceClient
Auth); |
| 493 public delegate void grpcsharp_server_credentials_release_delegate(I
ntPtr credentials); |
| 494 |
| 495 public delegate ServerSafeHandle grpcsharp_server_create_delegate(Co
mpletionQueueSafeHandle cq, ChannelArgsSafeHandle args); |
| 496 public delegate int grpcsharp_server_add_insecure_http2_port_delegat
e(ServerSafeHandle server, string addr); |
| 497 public delegate int grpcsharp_server_add_secure_http2_port_delegate(
ServerSafeHandle server, string addr, ServerCredentialsSafeHandle creds); |
| 498 public delegate void grpcsharp_server_start_delegate(ServerSafeHandl
e server); |
| 499 public delegate GRPCCallError grpcsharp_server_request_call_delegate
(ServerSafeHandle server, CompletionQueueSafeHandle cq, BatchContextSafeHandle c
tx); |
| 500 public delegate void grpcsharp_server_cancel_all_calls_delegate(Serv
erSafeHandle server); |
| 501 public delegate void grpcsharp_server_shutdown_and_notify_callback_d
elegate(ServerSafeHandle server, CompletionQueueSafeHandle cq, BatchContextSafeH
andle ctx); |
| 502 public delegate void grpcsharp_server_destroy_delegate(IntPtr server
); |
| 503 |
| 504 public delegate Timespec gprsharp_now_delegate(GPRClockType clockTyp
e); |
| 505 public delegate Timespec gprsharp_inf_future_delegate(GPRClockType c
lockType); |
| 506 public delegate Timespec gprsharp_inf_past_delegate(GPRClockType clo
ckType); |
| 507 |
| 508 public delegate Timespec gprsharp_convert_clock_type_delegate(Timesp
ec t, GPRClockType targetClock); |
| 509 public delegate int gprsharp_sizeof_timespec_delegate(); |
| 510 |
| 511 public delegate GRPCCallError grpcsharp_test_callback_delegate([Mars
halAs(UnmanagedType.FunctionPtr)] OpCompletionDelegate callback); |
| 512 public delegate IntPtr grpcsharp_test_nop_delegate(IntPtr ptr); |
| 513 } |
| 514 |
| 515 /// <summary> |
| 516 /// Default PInvoke bindings for native methods that are used on Windows
. |
| 517 /// Alternatively, they can also be used as a fallback on Mono |
| 518 /// (if libgrpc_csharp_ext is installed on your system, or is made acces
sible through e.g. LD_LIBRARY_PATH environment variable |
| 519 /// or using Mono's dllMap feature). |
| 520 /// </summary> |
| 521 private class PInvokeMethods |
| 522 { |
| 523 // Environment |
| 524 |
| 525 [DllImport("grpc_csharp_ext.dll")] |
| 526 public static extern void grpcsharp_init(); |
| 527 |
| 528 [DllImport("grpc_csharp_ext.dll")] |
| 529 public static extern void grpcsharp_shutdown(); |
| 530 |
| 531 [DllImport("grpc_csharp_ext.dll")] |
| 532 public static extern IntPtr grpcsharp_version_string(); // returns
not-owned const char* |
| 533 |
| 534 // BatchContextSafeHandle |
| 535 |
| 536 [DllImport("grpc_csharp_ext.dll")] |
| 537 public static extern BatchContextSafeHandle grpcsharp_batch_context_
create(); |
| 538 |
| 539 [DllImport("grpc_csharp_ext.dll")] |
| 540 public static extern IntPtr grpcsharp_batch_context_recv_initial_met
adata(BatchContextSafeHandle ctx); |
| 541 |
| 542 [DllImport("grpc_csharp_ext.dll")] |
| 543 public static extern IntPtr grpcsharp_batch_context_recv_message_len
gth(BatchContextSafeHandle ctx); |
| 544 |
| 545 [DllImport("grpc_csharp_ext.dll")] |
| 546 public static extern void grpcsharp_batch_context_recv_message_to_bu
ffer(BatchContextSafeHandle ctx, byte[] buffer, UIntPtr bufferLen); |
| 547 |
| 548 [DllImport("grpc_csharp_ext.dll")] |
| 549 public static extern StatusCode grpcsharp_batch_context_recv_status_
on_client_status(BatchContextSafeHandle ctx); |
| 550 |
| 551 [DllImport("grpc_csharp_ext.dll")] |
| 552 public static extern IntPtr grpcsharp_batch_context_recv_status_on_c
lient_details(BatchContextSafeHandle ctx); // returns const char* |
| 553 |
| 554 [DllImport("grpc_csharp_ext.dll")] |
| 555 public static extern IntPtr grpcsharp_batch_context_recv_status_on_c
lient_trailing_metadata(BatchContextSafeHandle ctx); |
| 556 |
| 557 [DllImport("grpc_csharp_ext.dll")] |
| 558 public static extern CallSafeHandle grpcsharp_batch_context_server_r
pc_new_call(BatchContextSafeHandle ctx); |
| 559 |
| 560 [DllImport("grpc_csharp_ext.dll")] |
| 561 public static extern IntPtr grpcsharp_batch_context_server_rpc_new_m
ethod(BatchContextSafeHandle ctx); // returns const char* |
| 562 |
| 563 [DllImport("grpc_csharp_ext.dll")] |
| 564 public static extern IntPtr grpcsharp_batch_context_server_rpc_new_h
ost(BatchContextSafeHandle ctx); // returns const char* |
| 565 |
| 566 [DllImport("grpc_csharp_ext.dll")] |
| 567 public static extern Timespec grpcsharp_batch_context_server_rpc_new
_deadline(BatchContextSafeHandle ctx); |
| 568 |
| 569 [DllImport("grpc_csharp_ext.dll")] |
| 570 public static extern IntPtr grpcsharp_batch_context_server_rpc_new_r
equest_metadata(BatchContextSafeHandle ctx); |
| 571 |
| 572 [DllImport("grpc_csharp_ext.dll")] |
| 573 public static extern int grpcsharp_batch_context_recv_close_on_serve
r_cancelled(BatchContextSafeHandle ctx); |
| 574 |
| 575 [DllImport("grpc_csharp_ext.dll")] |
| 576 public static extern void grpcsharp_batch_context_destroy(IntPtr ctx
); |
| 577 |
| 578 // CallCredentialsSafeHandle |
| 579 |
| 580 [DllImport("grpc_csharp_ext.dll")] |
| 581 public static extern CallCredentialsSafeHandle grpcsharp_composite_c
all_credentials_create(CallCredentialsSafeHandle creds1, CallCredentialsSafeHand
le creds2); |
| 582 |
| 583 [DllImport("grpc_csharp_ext.dll")] |
| 584 public static extern void grpcsharp_call_credentials_release(IntPtr
credentials); |
| 585 |
| 586 // CallSafeHandle |
| 587 |
| 588 [DllImport("grpc_csharp_ext.dll")] |
| 589 public static extern GRPCCallError grpcsharp_call_cancel(CallSafeHan
dle call); |
| 590 |
| 591 [DllImport("grpc_csharp_ext.dll")] |
| 592 public static extern GRPCCallError grpcsharp_call_cancel_with_status
(CallSafeHandle call, StatusCode status, string description); |
| 593 |
| 594 [DllImport("grpc_csharp_ext.dll")] |
| 595 public static extern GRPCCallError grpcsharp_call_start_unary(CallSa
feHandle call, |
| 596 BatchContextSafeHandle ctx, byte[] send_buffer, UIntPtr send_buf
fer_len, MetadataArraySafeHandle metadataArray, WriteFlags writeFlags); |
| 597 |
| 598 [DllImport("grpc_csharp_ext.dll")] |
| 599 public static extern GRPCCallError grpcsharp_call_start_client_strea
ming(CallSafeHandle call, |
| 600 BatchContextSafeHandle ctx, MetadataArraySafeHandle metadataArra
y); |
| 601 |
| 602 [DllImport("grpc_csharp_ext.dll")] |
| 603 public static extern GRPCCallError grpcsharp_call_start_server_strea
ming(CallSafeHandle call, |
| 604 BatchContextSafeHandle ctx, byte[] send_buffer, UIntPtr send_buf
fer_len, |
| 605 MetadataArraySafeHandle metadataArray, WriteFlags writeFlags); |
| 606 |
| 607 [DllImport("grpc_csharp_ext.dll")] |
| 608 public static extern GRPCCallError grpcsharp_call_start_duplex_strea
ming(CallSafeHandle call, |
| 609 BatchContextSafeHandle ctx, MetadataArraySafeHandle metadataArra
y); |
| 610 |
| 611 [DllImport("grpc_csharp_ext.dll")] |
| 612 public static extern GRPCCallError grpcsharp_call_send_message(CallS
afeHandle call, |
| 613 BatchContextSafeHandle ctx, byte[] send_buffer, UIntPtr send_buf
fer_len, WriteFlags writeFlags, bool sendEmptyInitialMetadata); |
| 614 |
| 615 [DllImport("grpc_csharp_ext.dll")] |
| 616 public static extern GRPCCallError grpcsharp_call_send_close_from_cl
ient(CallSafeHandle call, |
| 617 BatchContextSafeHandle ctx); |
| 618 |
| 619 [DllImport("grpc_csharp_ext.dll")] |
| 620 public static extern GRPCCallError grpcsharp_call_send_status_from_s
erver(CallSafeHandle call, |
| 621 BatchContextSafeHandle ctx, StatusCode statusCode, string status
Message, MetadataArraySafeHandle metadataArray, bool sendEmptyInitialMetadata); |
| 622 |
| 623 [DllImport("grpc_csharp_ext.dll")] |
| 624 public static extern GRPCCallError grpcsharp_call_recv_message(CallS
afeHandle call, |
| 625 BatchContextSafeHandle ctx); |
| 626 |
| 627 [DllImport("grpc_csharp_ext.dll")] |
| 628 public static extern GRPCCallError grpcsharp_call_recv_initial_metad
ata(CallSafeHandle call, |
| 629 BatchContextSafeHandle ctx); |
| 630 |
| 631 [DllImport("grpc_csharp_ext.dll")] |
| 632 public static extern GRPCCallError grpcsharp_call_start_serverside(C
allSafeHandle call, |
| 633 BatchContextSafeHandle ctx); |
| 634 |
| 635 [DllImport("grpc_csharp_ext.dll")] |
| 636 public static extern GRPCCallError grpcsharp_call_send_initial_metad
ata(CallSafeHandle call, |
| 637 BatchContextSafeHandle ctx, MetadataArraySafeHandle metadataArra
y); |
| 638 |
| 639 [DllImport("grpc_csharp_ext.dll")] |
| 640 public static extern GRPCCallError grpcsharp_call_set_credentials(Ca
llSafeHandle call, CallCredentialsSafeHandle credentials); |
| 641 |
| 642 [DllImport("grpc_csharp_ext.dll")] |
| 643 public static extern CStringSafeHandle grpcsharp_call_get_peer(CallS
afeHandle call); |
| 644 |
| 645 [DllImport("grpc_csharp_ext.dll")] |
| 646 public static extern void grpcsharp_call_destroy(IntPtr call); |
| 647 |
| 648 // ChannelArgsSafeHandle |
| 649 |
| 650 [DllImport("grpc_csharp_ext.dll")] |
| 651 public static extern ChannelArgsSafeHandle grpcsharp_channel_args_cr
eate(UIntPtr numArgs); |
| 652 |
| 653 [DllImport("grpc_csharp_ext.dll", CharSet = CharSet.Ansi)] |
| 654 public static extern void grpcsharp_channel_args_set_string(ChannelA
rgsSafeHandle args, UIntPtr index, string key, string value); |
| 655 |
| 656 [DllImport("grpc_csharp_ext.dll", CharSet = CharSet.Ansi)] |
| 657 public static extern void grpcsharp_channel_args_set_integer(Channel
ArgsSafeHandle args, UIntPtr index, string key, int value); |
| 658 |
| 659 [DllImport("grpc_csharp_ext.dll")] |
| 660 public static extern void grpcsharp_channel_args_destroy(IntPtr args
); |
| 661 |
| 662 // ChannelCredentialsSafeHandle |
| 663 |
| 664 [DllImport("grpc_csharp_ext.dll", CharSet = CharSet.Ansi)] |
| 665 public static extern void grpcsharp_override_default_ssl_roots(strin
g pemRootCerts); |
| 666 |
| 667 [DllImport("grpc_csharp_ext.dll", CharSet = CharSet.Ansi)] |
| 668 public static extern ChannelCredentialsSafeHandle grpcsharp_ssl_cred
entials_create(string pemRootCerts, string keyCertPairCertChain, string keyCertP
airPrivateKey); |
| 669 |
| 670 [DllImport("grpc_csharp_ext.dll")] |
| 671 public static extern ChannelCredentialsSafeHandle grpcsharp_composit
e_channel_credentials_create(ChannelCredentialsSafeHandle channelCreds, CallCred
entialsSafeHandle callCreds); |
| 672 |
| 673 [DllImport("grpc_csharp_ext.dll")] |
| 674 public static extern void grpcsharp_channel_credentials_release(IntP
tr credentials); |
| 675 |
| 676 // ChannelSafeHandle |
| 677 |
| 678 [DllImport("grpc_csharp_ext.dll")] |
| 679 public static extern ChannelSafeHandle grpcsharp_insecure_channel_cr
eate(string target, ChannelArgsSafeHandle channelArgs); |
| 680 |
| 681 [DllImport("grpc_csharp_ext.dll")] |
| 682 public static extern ChannelSafeHandle grpcsharp_secure_channel_crea
te(ChannelCredentialsSafeHandle credentials, string target, ChannelArgsSafeHandl
e channelArgs); |
| 683 |
| 684 [DllImport("grpc_csharp_ext.dll")] |
| 685 public static extern CallSafeHandle grpcsharp_channel_create_call(Ch
annelSafeHandle channel, CallSafeHandle parentCall, ContextPropagationFlags prop
agationMask, CompletionQueueSafeHandle cq, string method, string host, Timespec
deadline); |
| 686 |
| 687 [DllImport("grpc_csharp_ext.dll")] |
| 688 public static extern ChannelState grpcsharp_channel_check_connectivi
ty_state(ChannelSafeHandle channel, int tryToConnect); |
| 689 |
| 690 [DllImport("grpc_csharp_ext.dll")] |
| 691 public static extern void grpcsharp_channel_watch_connectivity_state
(ChannelSafeHandle channel, ChannelState lastObservedState, |
| 692 Timespec deadline, CompletionQueueSafeHandle cq, BatchContextSaf
eHandle ctx); |
| 693 |
| 694 [DllImport("grpc_csharp_ext.dll")] |
| 695 public static extern CStringSafeHandle grpcsharp_channel_get_target(
ChannelSafeHandle call); |
| 696 |
| 697 [DllImport("grpc_csharp_ext.dll")] |
| 698 public static extern void grpcsharp_channel_destroy(IntPtr channel); |
| 699 |
| 700 // CompletionQueueEvent |
| 701 |
| 702 [DllImport("grpc_csharp_ext.dll")] |
| 703 public static extern int grpcsharp_sizeof_grpc_event(); |
| 704 |
| 705 // CompletionQueueSafeHandle |
| 706 |
| 707 [DllImport("grpc_csharp_ext.dll")] |
| 708 public static extern CompletionQueueSafeHandle grpcsharp_completion_
queue_create(); |
| 709 |
| 710 [DllImport("grpc_csharp_ext.dll")] |
| 711 public static extern void grpcsharp_completion_queue_shutdown(Comple
tionQueueSafeHandle cq); |
| 712 |
| 713 [DllImport("grpc_csharp_ext.dll")] |
| 714 public static extern CompletionQueueEvent grpcsharp_completion_queue
_next(CompletionQueueSafeHandle cq); |
| 715 |
| 716 [DllImport("grpc_csharp_ext.dll")] |
| 717 public static extern CompletionQueueEvent grpcsharp_completion_queue
_pluck(CompletionQueueSafeHandle cq, IntPtr tag); |
| 718 |
| 719 [DllImport("grpc_csharp_ext.dll")] |
| 720 public static extern void grpcsharp_completion_queue_destroy(IntPtr
cq); |
| 721 |
| 722 // CStringSafeHandle |
| 723 |
| 724 [DllImport("grpc_csharp_ext.dll")] |
| 725 public static extern void gprsharp_free(IntPtr ptr); |
| 726 |
| 727 // MetadataArraySafeHandle |
| 728 |
| 729 [DllImport("grpc_csharp_ext.dll")] |
| 730 public static extern MetadataArraySafeHandle grpcsharp_metadata_arra
y_create(UIntPtr capacity); |
| 731 |
| 732 [DllImport("grpc_csharp_ext.dll", CharSet = CharSet.Ansi)] |
| 733 public static extern void grpcsharp_metadata_array_add(MetadataArray
SafeHandle array, string key, byte[] value, UIntPtr valueLength); |
| 734 |
| 735 [DllImport("grpc_csharp_ext.dll")] |
| 736 public static extern UIntPtr grpcsharp_metadata_array_count(IntPtr m
etadataArray); |
| 737 |
| 738 [DllImport("grpc_csharp_ext.dll")] |
| 739 public static extern IntPtr grpcsharp_metadata_array_get_key(IntPtr
metadataArray, UIntPtr index); |
| 740 |
| 741 [DllImport("grpc_csharp_ext.dll")] |
| 742 public static extern IntPtr grpcsharp_metadata_array_get_value(IntPt
r metadataArray, UIntPtr index); |
| 743 |
| 744 [DllImport("grpc_csharp_ext.dll")] |
| 745 public static extern UIntPtr grpcsharp_metadata_array_get_value_leng
th(IntPtr metadataArray, UIntPtr index); |
| 746 |
| 747 [DllImport("grpc_csharp_ext.dll")] |
| 748 public static extern void grpcsharp_metadata_array_destroy_full(IntP
tr array); |
| 749 |
| 750 // NativeLogRedirector |
| 751 |
| 752 [DllImport("grpc_csharp_ext.dll")] |
| 753 public static extern void grpcsharp_redirect_log(GprLogDelegate call
back); |
| 754 |
| 755 // NativeMetadataCredentialsPlugin |
| 756 |
| 757 [DllImport("grpc_csharp_ext.dll")] |
| 758 public static extern CallCredentialsSafeHandle grpcsharp_metadata_cr
edentials_create_from_plugin(NativeMetadataInterceptor interceptor); |
| 759 |
| 760 [DllImport("grpc_csharp_ext.dll", CharSet = CharSet.Ansi)] |
| 761 public static extern void grpcsharp_metadata_credentials_notify_from
_plugin(IntPtr callbackPtr, IntPtr userData, MetadataArraySafeHandle metadataArr
ay, StatusCode statusCode, string errorDetails); |
| 762 |
| 763 // ServerCredentialsSafeHandle |
| 764 |
| 765 [DllImport("grpc_csharp_ext.dll", CharSet = CharSet.Ansi)] |
| 766 public static extern ServerCredentialsSafeHandle grpcsharp_ssl_serve
r_credentials_create(string pemRootCerts, string[] keyCertPairCertChainArray, st
ring[] keyCertPairPrivateKeyArray, UIntPtr numKeyCertPairs, bool forceClientAuth
); |
| 767 |
| 768 [DllImport("grpc_csharp_ext.dll")] |
| 769 public static extern void grpcsharp_server_credentials_release(IntPt
r credentials); |
| 770 |
| 771 // ServerSafeHandle |
| 772 |
| 773 [DllImport("grpc_csharp_ext.dll")] |
| 774 public static extern ServerSafeHandle grpcsharp_server_create(Comple
tionQueueSafeHandle cq, ChannelArgsSafeHandle args); |
| 775 |
| 776 [DllImport("grpc_csharp_ext.dll")] |
| 777 public static extern int grpcsharp_server_add_insecure_http2_port(Se
rverSafeHandle server, string addr); |
| 778 |
| 779 [DllImport("grpc_csharp_ext.dll")] |
| 780 public static extern int grpcsharp_server_add_secure_http2_port(Serv
erSafeHandle server, string addr, ServerCredentialsSafeHandle creds); |
| 781 |
| 782 [DllImport("grpc_csharp_ext.dll")] |
| 783 public static extern void grpcsharp_server_start(ServerSafeHandle se
rver); |
| 784 |
| 785 [DllImport("grpc_csharp_ext.dll")] |
| 786 public static extern GRPCCallError grpcsharp_server_request_call(Ser
verSafeHandle server, CompletionQueueSafeHandle cq, BatchContextSafeHandle ctx); |
| 787 |
| 788 [DllImport("grpc_csharp_ext.dll")] |
| 789 public static extern void grpcsharp_server_cancel_all_calls(ServerSa
feHandle server); |
| 790 |
| 791 [DllImport("grpc_csharp_ext.dll")] |
| 792 public static extern void grpcsharp_server_shutdown_and_notify_callb
ack(ServerSafeHandle server, CompletionQueueSafeHandle cq, BatchContextSafeHandl
e ctx); |
| 793 |
| 794 [DllImport("grpc_csharp_ext.dll")] |
| 795 public static extern void grpcsharp_server_destroy(IntPtr server); |
| 796 |
| 797 // Timespec |
| 798 |
| 799 [DllImport("grpc_csharp_ext.dll")] |
| 800 public static extern Timespec gprsharp_now(GPRClockType clockType); |
| 801 |
| 802 [DllImport("grpc_csharp_ext.dll")] |
| 803 public static extern Timespec gprsharp_inf_future(GPRClockType clock
Type); |
| 804 |
| 805 [DllImport("grpc_csharp_ext.dll")] |
| 806 public static extern Timespec gprsharp_inf_past(GPRClockType clockTy
pe); |
| 807 |
| 808 [DllImport("grpc_csharp_ext.dll")] |
| 809 public static extern Timespec gprsharp_convert_clock_type(Timespec t
, GPRClockType targetClock); |
| 810 |
| 811 [DllImport("grpc_csharp_ext.dll")] |
| 812 public static extern int gprsharp_sizeof_timespec(); |
| 813 |
| 814 // Testing |
| 815 |
| 816 [DllImport("grpc_csharp_ext.dll")] |
| 817 public static extern GRPCCallError grpcsharp_test_callback([MarshalA
s(UnmanagedType.FunctionPtr)] OpCompletionDelegate callback); |
| 818 |
| 819 [DllImport("grpc_csharp_ext.dll")] |
| 820 public static extern IntPtr grpcsharp_test_nop(IntPtr ptr); |
| 821 } |
| 822 } |
| 823 } |
OLD | NEW |