- .NET API: MmsValue - added Clone method and implemented IDisposable interface

pull/93/head
Michael Zillgith 7 years ago
parent d0f4c06d62
commit 4ba6d9903d

@ -36,7 +36,7 @@ namespace IEC61850
/// <summary>
/// This class is used to hold MMS data values of different types.
/// </summary>
public class MmsValue : IEnumerable
public class MmsValue : IEnumerable, IDisposable
{
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr MmsValue_toString (IntPtr self);
@ -182,6 +182,9 @@ namespace IEC61850
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr MmsVariableSpecification_getChildValue(IntPtr self, IntPtr value, string childId);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr MmsValue_clone(IntPtr self);
internal IntPtr valueReference; /* reference to native MmsValue instance */
private bool responsableForDeletion; /* if .NET wrapper is responsable for the deletion of the native MmsValue instance */
@ -237,10 +240,22 @@ namespace IEC61850
valueReference = MmsValue_newVisibleString(value);
}
~MmsValue ()
public void Dispose()
{
lock (this) {
if (valueReference != IntPtr.Zero) {
if (responsableForDeletion)
MmsValue_delete (valueReference);
valueReference = IntPtr.Zero;
}
}
}
~MmsValue ()
{
Dispose();
}
/// <summary>
@ -888,6 +903,19 @@ namespace IEC61850
}
}
/// <summary>
/// Get an identical copy of this instance
/// </summary>
public MmsValue Clone()
{
IntPtr clonePtr = MmsValue_clone(valueReference);
if (clonePtr == IntPtr.Zero)
return null;
return new MmsValue(clonePtr, true);
}
public override bool Equals (object obj)
{
MmsValue otherValue = (MmsValue) obj;

Loading…
Cancel
Save