Skip to content

Commit

Permalink
Merge pull request grpc#2873 from jtattermusch/expose_version_string
Browse files Browse the repository at this point in the history
expose C core version string to C#
  • Loading branch information
jtattermusch committed Aug 10, 2015
2 parents 5bdcfc6 + 1338798 commit b5ea2f8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/csharp/Grpc.Core.Tests/GrpcEnvironmentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,13 @@ public void InitializeAfterShutdown()

Assert.IsFalse(object.ReferenceEquals(env1, env2));
}

[Test]
public void GetCoreVersionString()
{
var coreVersion = GrpcEnvironment.GetCoreVersionString();
var parts = coreVersion.Split('.');
Assert.AreEqual(4, parts.Length);
}
}
}
12 changes: 12 additions & 0 deletions src/csharp/Grpc.Core/GrpcEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public class GrpcEnvironment
[DllImport("grpc_csharp_ext.dll")]
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 GrpcEnvironment instance;

Expand Down Expand Up @@ -163,6 +166,15 @@ internal DebugStats DebugStats
}
}

/// <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>
/// Shuts down this environment.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions src/csharp/ext/grpc_csharp_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/* Version info */
GPR_EXPORT const char *GPR_CALLTYPE grpcsharp_version_string() {
return grpc_version_string();
}

/* For testing */
GPR_EXPORT void GPR_CALLTYPE
grpcsharp_test_callback(test_callback_funcptr callback) {
Expand Down

0 comments on commit b5ea2f8

Please sign in to comment.