diff --git a/src/SapNwRfc/ISapServer.cs b/src/SapNwRfc/ISapServer.cs index 0a19655..f71eb7b 100644 --- a/src/SapNwRfc/ISapServer.cs +++ b/src/SapNwRfc/ISapServer.cs @@ -17,6 +17,12 @@ public interface ISapServer : IDisposable /// event EventHandler StateChange; + /// + /// Gets the server attributes. + /// + /// The server attributes. + SapServerAttributes GetAttributes(); + /// /// Launches the server. /// diff --git a/src/SapNwRfc/Internal/Interop/RfcInterop.cs b/src/SapNwRfc/Internal/Interop/RfcInterop.cs index 9a90709..87d1c7f 100644 --- a/src/SapNwRfc/Internal/Interop/RfcInterop.cs +++ b/src/SapNwRfc/Internal/Interop/RfcInterop.cs @@ -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); diff --git a/src/SapNwRfc/Internal/Interop/RfcServerAttributes.cs b/src/SapNwRfc/Internal/Interop/RfcServerAttributes.cs new file mode 100644 index 0000000..aa8858b --- /dev/null +++ b/src/SapNwRfc/Internal/Interop/RfcServerAttributes.cs @@ -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; + } +} diff --git a/src/SapNwRfc/Internal/Interop/RfcStateChange.cs b/src/SapNwRfc/Internal/Interop/RfcStateChange.cs index 89c1ea3..736e2d4 100644 --- a/src/SapNwRfc/Internal/Interop/RfcStateChange.cs +++ b/src/SapNwRfc/Internal/Interop/RfcStateChange.cs @@ -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; } } diff --git a/src/SapNwRfc/SapRfcProtocolType.cs b/src/SapNwRfc/SapRfcProtocolType.cs new file mode 100644 index 0000000..6748b02 --- /dev/null +++ b/src/SapNwRfc/SapRfcProtocolType.cs @@ -0,0 +1,19 @@ +namespace SapNwRfc +{ + /// + /// Represents the SAP RFC server protocol. + /// + 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, + } +} diff --git a/src/SapNwRfc/RfcServerState.cs b/src/SapNwRfc/SapRfcServerState.cs similarity index 89% rename from src/SapNwRfc/RfcServerState.cs rename to src/SapNwRfc/SapRfcServerState.cs index f4fa475..ad0d586 100644 --- a/src/SapNwRfc/RfcServerState.cs +++ b/src/SapNwRfc/SapRfcServerState.cs @@ -3,7 +3,7 @@ namespace SapNwRfc /// /// Represents the SAP RFC server states. /// - public enum SapServerState + public enum SapRfcServerState { RFC_SERVER_INITIAL, RFC_SERVER_STARTING, diff --git a/src/SapNwRfc/SapServer.cs b/src/SapNwRfc/SapServer.cs index 185512d..11c233a 100644 --- a/src/SapNwRfc/SapServer.cs +++ b/src/SapNwRfc/SapServer.cs @@ -147,6 +147,19 @@ private void ServerStateChangeListener(IntPtr serverHandle, in RfcStateChange st _stateChange?.Invoke(this, new SapServerStateChangeEventArgs(stateChange)); } + /// + public SapServerAttributes GetAttributes() + { + RfcResultCode resultCode = _interop.GetServerAttributes( + rfcHandle: _rfcServerHandle, + serverAttributes: out RfcServerAttributes serverAttributes, + errorInfo: out RfcErrorInfo errorInfo); + + resultCode.ThrowOnError(errorInfo); + + return new SapServerAttributes(serverAttributes); + } + /// public void Launch() { diff --git a/src/SapNwRfc/SapServerAttributes.cs b/src/SapNwRfc/SapServerAttributes.cs new file mode 100644 index 0000000..f914cbf --- /dev/null +++ b/src/SapNwRfc/SapServerAttributes.cs @@ -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; + } +} diff --git a/src/SapNwRfc/SapServerStateChangeEventArgs.cs b/src/SapNwRfc/SapServerStateChangeEventArgs.cs index ffc50c2..336d436 100644 --- a/src/SapNwRfc/SapServerStateChangeEventArgs.cs +++ b/src/SapNwRfc/SapServerStateChangeEventArgs.cs @@ -17,11 +17,11 @@ internal SapServerStateChangeEventArgs(RfcStateChange stateChange) /// /// Gets the old server state. /// - public SapServerState OldState { get; } + public SapRfcServerState OldState { get; } /// /// Gets the new server state. /// - public SapServerState NewState { get; } + public SapRfcServerState NewState { get; } } }