- .NET API: Added ClientConnection.Abort method (LIB61850-488)

v1.6
Michael Zillgith 1 month ago
parent 96a7106a99
commit d1dd90ed83

@ -1688,7 +1688,7 @@ namespace IEC61850
} }
} }
public class ClientConnection public class ClientConnection : IDisposable
{ {
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr ClientConnection_getPeerAddress(IntPtr self); static extern IntPtr ClientConnection_getPeerAddress(IntPtr self);
@ -1696,31 +1696,90 @@ namespace IEC61850
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr ClientConnection_getLocalAddress(IntPtr self); static extern IntPtr ClientConnection_getLocalAddress(IntPtr self);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
static extern bool ClientConnection_abort(IntPtr self);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr ClientConnection_claimOwnership(IntPtr self);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern void ClientConnection_release(IntPtr self);
internal IntPtr self; internal IntPtr self;
internal ClientConnection (IntPtr self) { internal ClientConnection(IntPtr self)
this.self = self; {
this.self = ClientConnection_claimOwnership(self);
} }
public string GetPeerAddress() public string GetPeerAddress()
{ {
IntPtr peerAddrPtr = ClientConnection_getPeerAddress (self); lock (this)
{
if (self != IntPtr.Zero)
{
IntPtr peerAddrPtr = ClientConnection_getPeerAddress(self);
if (peerAddrPtr != IntPtr.Zero) if (peerAddrPtr != IntPtr.Zero)
return Marshal.PtrToStringAnsi (peerAddrPtr); return Marshal.PtrToStringAnsi(peerAddrPtr);
else }
}
return null; return null;
} }
public string GetLocalAddress() public string GetLocalAddress()
{
lock (this)
{
if (self != IntPtr.Zero)
{ {
IntPtr localAddrPtr = ClientConnection_getLocalAddress(self); IntPtr localAddrPtr = ClientConnection_getLocalAddress(self);
if (localAddrPtr != IntPtr.Zero) if (localAddrPtr != IntPtr.Zero)
return Marshal.PtrToStringAnsi(localAddrPtr); return Marshal.PtrToStringAnsi(localAddrPtr);
else }
}
return null; return null;
} }
/// <summary>
/// Abort/Close the client connection
/// </summary>
/// <returns>true, when connection has been closed, false when connection was already close</returns>
public bool Abort()
{
lock (this)
{
if (self != IntPtr.Zero)
{
return ClientConnection_abort(self);
}
}
return false;
}
public void Dispose()
{
lock (this)
{
if (self != IntPtr.Zero)
{
ClientConnection_release(self);
self = IntPtr.Zero;
}
}
}
~ClientConnection ()
{
Dispose();
}
} }
public class MmsGooseControlBlock public class MmsGooseControlBlock

Loading…
Cancel
Save