From 6b52ed440eb73bc9f3bbdcb14273fa151da5dd6e Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Thu, 21 May 2020 17:57:21 +0200 Subject: [PATCH] - .NET API: fixed bug in DataSet destructor --- dotnet/IEC61850forCSharp/DataSet.cs | 104 ++++++++++++++------------- src/iec61850/client/ied_connection.c | 2 +- 2 files changed, 55 insertions(+), 51 deletions(-) diff --git a/dotnet/IEC61850forCSharp/DataSet.cs b/dotnet/IEC61850forCSharp/DataSet.cs index 4a1e0fb0..2fcb1040 100644 --- a/dotnet/IEC61850forCSharp/DataSet.cs +++ b/dotnet/IEC61850forCSharp/DataSet.cs @@ -28,34 +28,34 @@ using IEC61850.Common; namespace IEC61850 { - namespace Client - { + namespace Client + { /// /// This class is used to represent a data set. It is used to store the values /// of a data set. /// public class DataSet : IDisposable - { - [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] - static extern void ClientDataSet_destroy (IntPtr self); + { + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + static extern void ClientDataSet_destroy(IntPtr self); - [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] - static extern IntPtr ClientDataSet_getValues (IntPtr self); + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + static extern IntPtr ClientDataSet_getValues(IntPtr self); - [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] - static extern IntPtr ClientDataSet_getReference (IntPtr self); + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + static extern IntPtr ClientDataSet_getReference(IntPtr self); - [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] - static extern int ClientDataSet_getDataSetSize (IntPtr self); + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + static extern int ClientDataSet_getDataSetSize(IntPtr self); - private IntPtr nativeObject; - private MmsValue values = null; - private string reference = null; + private IntPtr nativeObject; + private MmsValue values = null; + private string reference = null; - internal DataSet (IntPtr nativeObject) - { - this.nativeObject = nativeObject; - } + internal DataSet(IntPtr nativeObject) + { + this.nativeObject = nativeObject; + } /// /// Gets the object reference of the data set @@ -63,16 +63,17 @@ namespace IEC61850 /// /// object reference. /// - public string GetReference () - { - if (reference == null) { - IntPtr nativeString = ClientDataSet_getReference (nativeObject); + public string GetReference() + { + if (reference == null) + { + IntPtr nativeString = ClientDataSet_getReference(nativeObject); - reference = Marshal.PtrToStringAnsi (nativeString); - } + reference = Marshal.PtrToStringAnsi(nativeString); + } - return reference; - } + return reference; + } /// /// Gets the values associated with the data set object @@ -83,16 +84,17 @@ namespace IEC61850 /// /// The locally stored values of the data set (as MmsValue instance of type MMS_ARRAY) /// - public MmsValue GetValues () - { - if (values == null) { - IntPtr nativeValues = ClientDataSet_getValues (nativeObject); + public MmsValue GetValues() + { + if (values == null) + { + IntPtr nativeValues = ClientDataSet_getValues(nativeObject); - values = new MmsValue (nativeValues, false); - } + values = new MmsValue(nativeValues, false); + } return values.Clone(); - } + } /// @@ -101,32 +103,34 @@ namespace IEC61850 /// /// the number of elementes (data set members) /// - public int GetSize () - { - return ClientDataSet_getDataSetSize (nativeObject); - } + public int GetSize() + { + return ClientDataSet_getDataSetSize(nativeObject); + } public void Dispose() { - lock (this) { - if (nativeObject != IntPtr.Zero) { - ClientDataSet_destroy (nativeObject); + lock (this) + { + if (nativeObject != IntPtr.Zero) + { + ClientDataSet_destroy(nativeObject); nativeObject = IntPtr.Zero; } } } - ~DataSet () - { - ClientDataSet_destroy (nativeObject); - } + ~DataSet() + { + Dispose(); + } - internal IntPtr getNativeInstance () - { - return nativeObject; - } - } + internal IntPtr getNativeInstance() + { + return nativeObject; + } + } - } + } } diff --git a/src/iec61850/client/ied_connection.c b/src/iec61850/client/ied_connection.c index 7c01cf8f..3ca81e11 100644 --- a/src/iec61850/client/ied_connection.c +++ b/src/iec61850/client/ied_connection.c @@ -3253,7 +3253,7 @@ IedConnection_readDataSetValues(IedConnection self, IedClientError* error, const dataSetVal = MmsConnection_readNamedVariableListValuesAssociationSpecific(self->connection, &mmsError, itemId, true); else - dataSetVal= MmsConnection_readNamedVariableListValues(self->connection, &mmsError, + dataSetVal = MmsConnection_readNamedVariableListValues(self->connection, &mmsError, domainId, itemId, true); if (dataSetVal == NULL) {