Skip to content

Commit

Permalink
Add GetAttributes to ISapServer
Browse files Browse the repository at this point in the history
  • Loading branch information
campersau committed Sep 1, 2022
1 parent 0e651de commit c60998d
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/SapNwRfc/ISapServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public interface ISapServer : IDisposable
/// </summary>
event EventHandler<SapServerStateChangeEventArgs> StateChange;

/// <summary>
/// Gets the server attributes.
/// </summary>
/// <returns>The server attributes.</returns>
SapServerAttributes GetAttributes();

/// <summary>
/// Launches the server.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions src/SapNwRfc/Internal/Interop/RfcInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,12 @@ public virtual RfcResultCode LaunchServer(IntPtr rfcHandle, out RfcErrorInfo err
public virtual RfcResultCode ShutdownServer(IntPtr rfcHandle, uint timeout, out RfcErrorInfo errorInfo)
=> RfcShutdownServer(rfcHandle, timeout, out errorInfo);

[DllImport(SapNwRfcDllName)]
private static extern RfcResultCode RfcGetServerAttributes(IntPtr rfcHandle, out RfcServerAttributes serverAttributes, out RfcErrorInfo errorInfo);

public virtual RfcResultCode GetServerAttributes(IntPtr rfcHandle, out RfcServerAttributes serverAttributes, out RfcErrorInfo errorInfo)
=> RfcGetServerAttributes(rfcHandle, out serverAttributes, out errorInfo);

[DllImport(SapNwRfcDllName)]
private static extern RfcResultCode RfcGetServerContext(IntPtr rfcHandle, out RfcServerContext serverContext, out RfcErrorInfo errorInfo);

Expand Down
26 changes: 26 additions & 0 deletions src/SapNwRfc/Internal/Interop/RfcServerAttributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Runtime.InteropServices;

namespace SapNwRfc.Internal.Interop
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct RfcServerAttributes
{
public IntPtr ServerName;

[MarshalAs(UnmanagedType.I4)]
public SapRfcProtocolType Type;

[MarshalAs(UnmanagedType.U4)]
public uint RegistrationCount;

[MarshalAs(UnmanagedType.I4)]
public SapRfcServerState State;

[MarshalAs(UnmanagedType.U4)]
public uint CurrentBusyCount;

[MarshalAs(UnmanagedType.U4)]
public uint PeakBusyCount;
}
}
4 changes: 2 additions & 2 deletions src/SapNwRfc/Internal/Interop/RfcStateChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace SapNwRfc.Internal.Interop
internal struct RfcStateChange
{
[MarshalAs(UnmanagedType.I4)]
public SapServerState OldState;
public SapRfcServerState OldState;

[MarshalAs(UnmanagedType.I4)]
public SapServerState NewState;
public SapRfcServerState NewState;
}
}
19 changes: 19 additions & 0 deletions src/SapNwRfc/SapRfcProtocolType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace SapNwRfc
{
/// <summary>
/// Represents the SAP RFC server protocol.
/// </summary>
public enum SapRfcProtocolType
{
RFC_UNKOWN,
RFC_CLIENT,
RFC_STARTED_SERVER,
RFC_REGISTERED_SERVER,
RFC_MULTI_COUNT_REGISTERED_SERVER,
RFC_TCP_SOCKET_CLIENT,
RFC_TCP_SOCKET_SERVER,
RFC_WEBSOCKET_CLIENT,
RFC_WEBSOCKET_SERVER,
RFC_PROXY_WEBSOCKET_CLIENT,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace SapNwRfc
/// <summary>
/// Represents the SAP RFC server states.
/// </summary>
public enum SapServerState
public enum SapRfcServerState
{
RFC_SERVER_INITIAL,
RFC_SERVER_STARTING,
Expand Down
13 changes: 13 additions & 0 deletions src/SapNwRfc/SapServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,19 @@ private void ServerStateChangeListener(IntPtr serverHandle, in RfcStateChange st
_stateChange?.Invoke(this, new SapServerStateChangeEventArgs(stateChange));
}

/// <inheritdoc cref="ISapServer"/>
public SapServerAttributes GetAttributes()
{
RfcResultCode resultCode = _interop.GetServerAttributes(
rfcHandle: _rfcServerHandle,
serverAttributes: out RfcServerAttributes serverAttributes,
errorInfo: out RfcErrorInfo errorInfo);

resultCode.ThrowOnError(errorInfo);

return new SapServerAttributes(serverAttributes);
}

/// <inheritdoc cref="ISapServer"/>
public void Launch()
{
Expand Down
28 changes: 28 additions & 0 deletions src/SapNwRfc/SapServerAttributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Runtime.InteropServices;
using SapNwRfc.Internal.Interop;

namespace SapNwRfc
{
public sealed class SapServerAttributes
{
private readonly RfcServerAttributes _serverAttributes;

internal SapServerAttributes(RfcServerAttributes serverAttributes)
{
_serverAttributes = serverAttributes;
ServerName = Marshal.PtrToStringAuto(serverAttributes.ServerName);
}

public string ServerName { get; }

public SapRfcProtocolType Type => _serverAttributes.Type;

public uint RegistrationCount => _serverAttributes.RegistrationCount;

public SapRfcServerState State => _serverAttributes.State;

public uint CurrentBusyCount => _serverAttributes.CurrentBusyCount;

public uint PeakBusyCount => _serverAttributes.PeakBusyCount;
}
}
4 changes: 2 additions & 2 deletions src/SapNwRfc/SapServerStateChangeEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ internal SapServerStateChangeEventArgs(RfcStateChange stateChange)
/// <summary>
/// Gets the old server state.
/// </summary>
public SapServerState OldState { get; }
public SapRfcServerState OldState { get; }

/// <summary>
/// Gets the new server state.
/// </summary>
public SapServerState NewState { get; }
public SapRfcServerState NewState { get; }
}
}

0 comments on commit c60998d

Please sign in to comment.