Skip to content
Snippets Groups Projects
Commit b5ea2f89 authored by Jan Tattermusch's avatar Jan Tattermusch
Browse files

Merge pull request #2873 from jtattermusch/expose_version_string

expose C core version string to C#
parents 5bdcfc60 13387988
No related branches found
No related tags found
No related merge requests found
...@@ -69,5 +69,13 @@ namespace Grpc.Core.Tests ...@@ -69,5 +69,13 @@ namespace Grpc.Core.Tests
Assert.IsFalse(object.ReferenceEquals(env1, env2)); Assert.IsFalse(object.ReferenceEquals(env1, env2));
} }
[Test]
public void GetCoreVersionString()
{
var coreVersion = GrpcEnvironment.GetCoreVersionString();
var parts = coreVersion.Split('.');
Assert.AreEqual(4, parts.Length);
}
} }
} }
...@@ -53,6 +53,9 @@ namespace Grpc.Core ...@@ -53,6 +53,9 @@ namespace Grpc.Core
[DllImport("grpc_csharp_ext.dll")] [DllImport("grpc_csharp_ext.dll")]
static extern void grpcsharp_shutdown(); static extern void grpcsharp_shutdown();
[DllImport("grpc_csharp_ext.dll")]
static extern IntPtr grpcsharp_version_string(); // returns not-owned const char*
static object staticLock = new object(); static object staticLock = new object();
static GrpcEnvironment instance; static GrpcEnvironment instance;
...@@ -163,6 +166,15 @@ namespace Grpc.Core ...@@ -163,6 +166,15 @@ namespace Grpc.Core
} }
} }
/// <summary>
/// Gets version of gRPC C core.
/// </summary>
internal static string GetCoreVersionString()
{
var ptr = grpcsharp_version_string(); // the pointer is not owned
return Marshal.PtrToStringAnsi(ptr);
}
/// <summary> /// <summary>
/// Shuts down this environment. /// Shuts down this environment.
/// </summary> /// </summary>
......
...@@ -876,6 +876,11 @@ GPR_EXPORT void GPR_CALLTYPE grpcsharp_redirect_log(grpcsharp_log_func func) { ...@@ -876,6 +876,11 @@ GPR_EXPORT void GPR_CALLTYPE grpcsharp_redirect_log(grpcsharp_log_func func) {
typedef void(GPR_CALLTYPE *test_callback_funcptr)(gpr_int32 success); typedef void(GPR_CALLTYPE *test_callback_funcptr)(gpr_int32 success);
/* Version info */
GPR_EXPORT const char *GPR_CALLTYPE grpcsharp_version_string() {
return grpc_version_string();
}
/* For testing */ /* For testing */
GPR_EXPORT void GPR_CALLTYPE GPR_EXPORT void GPR_CALLTYPE
grpcsharp_test_callback(test_callback_funcptr callback) { grpcsharp_test_callback(test_callback_funcptr callback) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment