From 32c3eb5239eac52e08c97d5f96d7fe8cdc875029 Mon Sep 17 00:00:00 2001 From: mullerj Date: Tue, 27 Aug 2024 21:06:13 -0400 Subject: [PATCH] NormObject Refactor * Updated NormObjectGetInfo to use byte array * Updated design --- src/dotnet/design/Mil/Navy/Nrl/Norm/NormApi.puml | 2 +- .../design/Mil/Navy/Nrl/Norm/NormFile.puml | 2 +- src/dotnet/src/Mil.Navy.Nrl.Norm/NormApi.cs | 2 +- src/dotnet/src/Mil.Navy.Nrl.Norm/NormObject.cs | 16 ++-------------- 4 files changed, 5 insertions(+), 17 deletions(-) diff --git a/src/dotnet/design/Mil/Navy/Nrl/Norm/NormApi.puml b/src/dotnet/design/Mil/Navy/Nrl/Norm/NormApi.puml index 824d07a..1be3b84 100644 --- a/src/dotnet/design/Mil/Navy/Nrl/Norm/NormApi.puml +++ b/src/dotnet/design/Mil/Navy/Nrl/Norm/NormApi.puml @@ -91,7 +91,7 @@ class NormApi <> { + {static} <> NormObjectGetType(objectHandle:long) : NormObjectType + {static} <> NormObjectHasInfo(objectHandle:long) : bool + {static} <> NormObjectGetInfoLength(objectHandle:long) : int - + {static} <> NormObjectGetInfo(objectHandle:long, buffer:nint, bufferLen:int) : int + + {static} <> NormObjectGetInfo(objectHandle:long, buffer:byte[], bufferLen:int) : int + {static} <> NormObjectGetSize(objectHandle:long) : int + {static} <> NormObjectGetBytesPending(objectHandle:long) : long + {static} <> NormObjectCancel(objectHandle:long) : void diff --git a/src/dotnet/design/Mil/Navy/Nrl/Norm/NormFile.puml b/src/dotnet/design/Mil/Navy/Nrl/Norm/NormFile.puml index f26b63a..b2e2a9b 100644 --- a/src/dotnet/design/Mil/Navy/Nrl/Norm/NormFile.puml +++ b/src/dotnet/design/Mil/Navy/Nrl/Norm/NormFile.puml @@ -2,7 +2,7 @@ class NormFile { + <> FILENAME_MAX : int = 260 <> NormFile(handle:long) - + Name : string <> + + <> Name : string <> + Rename(filePath:string) : void } NormObject <|-- NormFile diff --git a/src/dotnet/src/Mil.Navy.Nrl.Norm/NormApi.cs b/src/dotnet/src/Mil.Navy.Nrl.Norm/NormApi.cs index d1085ef..876941f 100644 --- a/src/dotnet/src/Mil.Navy.Nrl.Norm/NormApi.cs +++ b/src/dotnet/src/Mil.Navy.Nrl.Norm/NormApi.cs @@ -961,7 +961,7 @@ namespace Mil.Navy.Nrl.Norm /// function can be used to determine the length of NORM_INFO content for the object even if a NULL buffer value and /// zero bufferLen is provided. A zero value is returned if NORM_INFO content has not yet been received (or is nonexistent) for the specified object. [DllImport(NORM_LIBRARY)] - public static extern int NormObjectGetInfo(long objectHandle, nint buffer, int bufferLen); + public static extern int NormObjectGetInfo(long objectHandle, [Out] byte[] buffer, int bufferLen); /// /// This function can be used to determine the size (in bytes) of the transport object specified by the objectHandle parameter. diff --git a/src/dotnet/src/Mil.Navy.Nrl.Norm/NormObject.cs b/src/dotnet/src/Mil.Navy.Nrl.Norm/NormObject.cs index f3ded3a..1362e00 100644 --- a/src/dotnet/src/Mil.Navy.Nrl.Norm/NormObject.cs +++ b/src/dotnet/src/Mil.Navy.Nrl.Norm/NormObject.cs @@ -1,6 +1,4 @@ -using System.Runtime.InteropServices; - -namespace Mil.Navy.Nrl.Norm +namespace Mil.Navy.Nrl.Norm { /// /// The base transport object. @@ -44,17 +42,7 @@ namespace Mil.Navy.Nrl.Norm var length = NormObjectGetInfoLength(_handle); var buffer = new byte[length]; - var bufferHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned); - - try - { - var bufferPtr = bufferHandle.AddrOfPinnedObject(); - NormObjectGetInfo(_handle, bufferPtr, length); - } - finally - { - bufferHandle.Free(); - } + NormObjectGetInfo(_handle, buffer, length); return buffer; }