Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(csharp/client): Wrappers for some Enterprise Core+ features #6003

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions csharp/client/DeephavenClient/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,31 @@ public static Client Connect(string target, ClientOptions options) {
return new Client(clientResult, manager);
}

private Client(NativePtr<NativeClient> self, TableHandleManager manager) {
private protected Client(NativePtr<NativeClient> self, TableHandleManager manager) {
Self = self;
Manager = manager;
}

~Client() {
ReleaseUnmanagedResources();
ReleaseUnmanagedResources(true);
}

public void Close() {
Dispose();
}

public void Dispose() {
ReleaseUnmanagedResources();
ReleaseUnmanagedResources(true);
GC.SuppressFinalize(this);
}

private void ReleaseUnmanagedResources() {
protected virtual void ReleaseUnmanagedResources(bool destructSelf) {
if (!Self.TryRelease(out var old)) {
return;
}
if (!destructSelf) {
return;
}
NativeClient.deephaven_client_Client_dtor(old);
}
}
Expand Down
8 changes: 7 additions & 1 deletion csharp/client/DeephavenClient/DeephavenClient.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<Compile Remove="dh_client\**" />
<EmbeddedResource Remove="dh_client\**" />
<None Remove="dh_client\**" />
</ItemGroup>

</Project>
11 changes: 7 additions & 4 deletions csharp/client/DeephavenClient/TableHandleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Deephaven.DeephavenClient;

public sealed class TableHandleManager : IDisposable {
public class TableHandleManager : IDisposable {
internal NativePtr<NativeTableHandleManager> Self;
private readonly Dictionary<SubscriptionHandle, object> _subscriptions;

Expand All @@ -13,18 +13,21 @@ internal TableHandleManager(NativePtr<NativeTableHandleManager> self) {
}

~TableHandleManager() {
ReleaseUnmanagedResources();
ReleaseUnmanagedResources(true);
}

public void Dispose() {
ReleaseUnmanagedResources();
ReleaseUnmanagedResources(true);
GC.SuppressFinalize(this);
}

private void ReleaseUnmanagedResources() {
protected virtual void ReleaseUnmanagedResources(bool destructSelf) {
if (!Self.TryRelease(out var old)) {
return;
}
if (!destructSelf) {
return;
}
NativeTableHandleManager.deephaven_client_TableHandleManager_dtor(old);
}

Expand Down
57 changes: 57 additions & 0 deletions csharp/client/DeephavenClient/dhe_client/session/DndClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.Runtime.InteropServices;
using Deephaven.DeephavenClient;
using Deephaven.DeephavenClient.Interop;

namespace Deephaven.DheClient.Session;

public sealed class DndClient : Client {
internal new NativePtr<NativeDndClient> Self;
public Int64 PqSerial;

internal static DndClient OfNativePtr(NativePtr<NativeDndClient> dndClient) {
NativeDndClient.deephaven_enterprise_session_DndClient_GetManager(dndClient,
out var dndManagerResult, out var status1);
status1.OkOrThrow();
NativeDndClient.deephaven_enterprise_session_DndClient_PqSerial(dndClient,
out var pqSerial, out var status2);
status2.OkOrThrow();
var dndManager = new DndTableHandleManager(dndManagerResult);

return new DndClient(dndClient, dndManager, pqSerial);
}

private DndClient(NativePtr<NativeDndClient> self, DndTableHandleManager manager,
Int64 pqSerial)
: base(self.UnsafeCast<NativeClient>(), manager) {
Self = self;
PqSerial = pqSerial;
}

protected override void ReleaseUnmanagedResources(bool destructSelf) {
base.ReleaseUnmanagedResources(false);
if (!Self.TryRelease(out var old)) {
return;
}
if (!destructSelf) {
return;
}
NativeDndClient.deephaven_enterprise_session_DndClient_dtor(old);
}
}


internal partial class NativeDndClient {
[LibraryImport(LibraryPaths.DhEnterprise, StringMarshalling = StringMarshalling.Utf8)]
public static partial void deephaven_enterprise_session_DndClient_dtor(
NativePtr<NativeDndClient> self);

[LibraryImport(LibraryPaths.DhEnterprise, StringMarshalling = StringMarshalling.Utf8)]
public static partial void deephaven_enterprise_session_DndClient_GetManager(
NativePtr<NativeDndClient> self,
out NativePtr<NativeDndTableHandleManager> result, out ErrorStatus status);

[LibraryImport(LibraryPaths.DhEnterprise, StringMarshalling = StringMarshalling.Utf8)]
public static partial void deephaven_enterprise_session_DndClient_PqSerial(
NativePtr<NativeDndClient> self,
out Int64 result, out ErrorStatus status);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Runtime.InteropServices;
using Deephaven.DeephavenClient;
using Deephaven.DeephavenClient.Interop;

namespace Deephaven.DheClient.Session;

public sealed class DndTableHandleManager : TableHandleManager {
internal new NativePtr<NativeDndTableHandleManager> Self;

internal DndTableHandleManager(NativePtr<NativeDndTableHandleManager> self) :
base(self.UnsafeCast<NativeTableHandleManager>()) {
Self = self;
}

protected override void ReleaseUnmanagedResources(bool destructSelf) {
base.ReleaseUnmanagedResources(false);
if (!Self.TryRelease(out var old)) {
return;
}
if (!destructSelf) {
return;
}
NativeDndTableHandleManager.deephaven_enterprise_session_DndTableHandleManager_dtor(old);
}

}

internal partial class NativeDndTableHandleManager {
[LibraryImport(LibraryPaths.DhEnterprise, StringMarshalling = StringMarshalling.Utf8)]
public static partial void deephaven_enterprise_session_DndTableHandleManager_dtor(
NativePtr<NativeDndTableHandleManager> self);
}
73 changes: 73 additions & 0 deletions csharp/client/DeephavenClient/dhe_client/session/SessionManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System.Runtime.InteropServices;
using Deephaven.DeephavenClient.Interop;

namespace Deephaven.DheClient.Session;

public class SessionManager : IDisposable {
internal NativePtr<NativeSessionManager> Self;

public static SessionManager FromUrl(string descriptiveName, string jsonUrl) {
NativeSessionManager.deephaven_enterprise_session_SessionManager_FromUrl(descriptiveName,
jsonUrl, out var sessionResult, out var status);
status.OkOrThrow();
return new SessionManager(sessionResult);
}

private SessionManager(NativePtr<NativeSessionManager> self) {
Self = self;
}

~SessionManager() {
ReleaseUnmanagedResources();
}

public void Close() {
Dispose();
}

public void Dispose() {
ReleaseUnmanagedResources();
GC.SuppressFinalize(this);
}

public bool PasswordAuthentication(string user, string password, string operateAs) {
NativeSessionManager.deephaven_enterprise_session_SessionManager_PasswordAuthentication(
Self, user, password, operateAs, out var result, out var status);
status.OkOrThrow();
return (bool)result;
}

public DndClient ConnectToPqByName(string pqName, bool removeOnClose) {
NativeSessionManager.deephaven_enterprise_session_SessionManager_ConnectToPqByName(
Self, pqName, (InteropBool)removeOnClose, out var result, out var status);
status.OkOrThrow();
return DndClient.OfNativePtr(result);
}

private void ReleaseUnmanagedResources() {
if (!Self.TryRelease(out var old)) {
return;
}
NativeSessionManager.deephaven_enterprise_session_SessionManager_dtor(old);
}
}

internal partial class NativeSessionManager {
[LibraryImport(LibraryPaths.DhEnterprise, StringMarshalling = StringMarshalling.Utf8)]
public static partial void deephaven_enterprise_session_SessionManager_dtor(
NativePtr<NativeSessionManager> self);

[LibraryImport(LibraryPaths.DhEnterprise, StringMarshalling = StringMarshalling.Utf8)]
public static partial void deephaven_enterprise_session_SessionManager_FromUrl(string descriptiveName,
string jsonUrl, out NativePtr<NativeSessionManager> result, out ErrorStatus status);

[LibraryImport(LibraryPaths.DhEnterprise, StringMarshalling = StringMarshalling.Utf8)]
public static partial void deephaven_enterprise_session_SessionManager_PasswordAuthentication(
NativePtr<NativeSessionManager> self, string user, string password, string operateAs,
out InteropBool result, out ErrorStatus status);

[LibraryImport(LibraryPaths.DhEnterprise, StringMarshalling = StringMarshalling.Utf8)]
public static partial void deephaven_enterprise_session_SessionManager_ConnectToPqByName(
NativePtr<NativeSessionManager> self, string pqName, InteropBool removeOnClose,
out NativePtr<NativeDndClient> result, out ErrorStatus status);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

namespace Deephaven.DeephavenClient.Interop;

internal class LibraryPaths {
internal const string Dhcore = "dhcore";
internal const string Dhclient = "dhclient";
public class LibraryPaths {
public const string Dhcore = "dhcore";
public const string Dhclient = "dhclient";
// public const string DhEnterprise = @"dhe_client"; // does not work
public const string DhEnterprise = @"dhe_client.dll"; // works
}

/// <summary>
Expand All @@ -32,6 +34,10 @@ public bool TryRelease(out NativePtr<T> oldPtr) {
return true;
}

public NativePtr<T2> UnsafeCast<T2>() {
return new NativePtr<T2>(ptr);
}

public readonly bool IsNull => ptr == IntPtr.Zero;
}

Expand Down
Loading