From e06191beea336b561da5f6219803d74af268f990 Mon Sep 17 00:00:00 2001 From: Andrey Uzbekov Date: Mon, 12 Apr 2021 15:10:20 +0300 Subject: [PATCH] +Separate Intel.Realsense.Net library for network devices. It is being created on BUILD_NETWORK_DEVICE=ON cmake flag as well as cs-tutorial-7-net-dev example tutorial tha uses this library. --- wrappers/csharp/CMakeLists.txt | 7 ++- .../.nuget/Intel.RealSense.targets | 16 +++++++ .../csharp/Intel.RealSense.Net/CMakeLists.txt | 46 +++++++++++++++++++ .../Devices/CMakeLists.txt | 4 ++ .../Devices/NetDevice.cs | 6 +-- .../Intel.RealSense.Net/GlobalSuppressions.cs | 8 ++++ .../Intel.RealSense.Net/NativeMethods.cs | 42 +++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 +++++++++++++++ .../Intel.RealSense.Net/packages.config | 4 ++ .../Intel.RealSense/Devices/CMakeLists.txt | 2 +- .../Intel.RealSense/Devices/ProxyDevice.cs | 22 +++++++++ .../cs-tutorial-7-net-dev/CMakeLists.txt | 1 + .../Properties/AssemblyInfo.cs | 8 ++-- .../cs-tutorial-7-net-dev/Window.xaml.cs | 1 + 14 files changed, 193 insertions(+), 10 deletions(-) create mode 100644 wrappers/csharp/Intel.RealSense.Net/.nuget/Intel.RealSense.targets create mode 100644 wrappers/csharp/Intel.RealSense.Net/CMakeLists.txt create mode 100644 wrappers/csharp/Intel.RealSense.Net/Devices/CMakeLists.txt rename wrappers/csharp/{Intel.RealSense => Intel.RealSense.Net}/Devices/NetDevice.cs (89%) create mode 100644 wrappers/csharp/Intel.RealSense.Net/GlobalSuppressions.cs create mode 100644 wrappers/csharp/Intel.RealSense.Net/NativeMethods.cs create mode 100644 wrappers/csharp/Intel.RealSense.Net/Properties/AssemblyInfo.cs create mode 100644 wrappers/csharp/Intel.RealSense.Net/packages.config create mode 100644 wrappers/csharp/Intel.RealSense/Devices/ProxyDevice.cs diff --git a/wrappers/csharp/CMakeLists.txt b/wrappers/csharp/CMakeLists.txt index 4c892467ff..d8cb640f6c 100644 --- a/wrappers/csharp/CMakeLists.txt +++ b/wrappers/csharp/CMakeLists.txt @@ -9,7 +9,10 @@ add_subdirectory(tutorial/depth) add_subdirectory(tutorial/capture) add_subdirectory(tutorial/processing) add_subdirectory(tutorial/software-dev) -add_subdirectory(tutorial/pose) add_subdirectory(tutorial/d400-occ) add_subdirectory(tutorial/load-json) -add_subdirectory(tutorial/net-dev) + +if(BUILD_NETWORK_DEVICE) + add_subdirectory(Intel.RealSense.Net) + add_subdirectory(tutorial/net-dev) +endif() \ No newline at end of file diff --git a/wrappers/csharp/Intel.RealSense.Net/.nuget/Intel.RealSense.targets b/wrappers/csharp/Intel.RealSense.Net/.nuget/Intel.RealSense.targets new file mode 100644 index 0000000000..fc9840306a --- /dev/null +++ b/wrappers/csharp/Intel.RealSense.Net/.nuget/Intel.RealSense.targets @@ -0,0 +1,16 @@ + + + + + %(FileName)%(Extension) + PreserveNewest + + + + + + %(FileName)%(Extension) + PreserveNewest + + + \ No newline at end of file diff --git a/wrappers/csharp/Intel.RealSense.Net/CMakeLists.txt b/wrappers/csharp/Intel.RealSense.Net/CMakeLists.txt new file mode 100644 index 0000000000..87959b3fb8 --- /dev/null +++ b/wrappers/csharp/Intel.RealSense.Net/CMakeLists.txt @@ -0,0 +1,46 @@ +cmake_minimum_required( VERSION 3.8.0 ) + +project(Intel.RealSense.Net) + +set(LRS_DOTNET_TARGET ${PROJECT_NAME}) + +add_library(${PROJECT_NAME} + NativeMethods.cs + .nuget/Intel.RealSense.targets + GlobalSuppressions.cs + Properties/AssemblyInfo.cs + packages.config + stylecop.json +) + +include(Devices/CMakeLists.txt) + +csharp_set_designer_cs_properties( + .nuget/Intel.RealSense.Net.targets +) + + +set_property(SOURCE App.xaml PROPERTY VS_XAML_TYPE "ApplicationDefinition") + +set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "v${DOTNET_VERSION_LIBRARY}") + +add_dependencies(${PROJECT_NAME} Intel.RealSense) + +set_target_properties (${PROJECT_NAME} PROPERTIES + FOLDER Wrappers/csharp +) + +set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DOTNET_REFERENCES + "System" +) + +target_compile_options(${PROJECT_NAME} PRIVATE /define:${CMAKE_SYSTEM_NAME}) + +set_source_files_properties(stylecop.json PROPERTIES VS_TOOL_OVERRIDE "AdditionalFiles") + +install(TARGETS ${PROJECT_NAME} + EXPORT realsense2Targets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + #LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + #ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} +) diff --git a/wrappers/csharp/Intel.RealSense.Net/Devices/CMakeLists.txt b/wrappers/csharp/Intel.RealSense.Net/Devices/CMakeLists.txt new file mode 100644 index 0000000000..c787faffac --- /dev/null +++ b/wrappers/csharp/Intel.RealSense.Net/Devices/CMakeLists.txt @@ -0,0 +1,4 @@ +target_sources(${LRS_DOTNET_TARGET} + PRIVATE + "${CMAKE_CURRENT_LIST_DIR}/NetDevice.cs" +) diff --git a/wrappers/csharp/Intel.RealSense/Devices/NetDevice.cs b/wrappers/csharp/Intel.RealSense.Net/Devices/NetDevice.cs similarity index 89% rename from wrappers/csharp/Intel.RealSense/Devices/NetDevice.cs rename to wrappers/csharp/Intel.RealSense.Net/Devices/NetDevice.cs index d9d1191aff..f30f7de010 100644 --- a/wrappers/csharp/Intel.RealSense/Devices/NetDevice.cs +++ b/wrappers/csharp/Intel.RealSense.Net/Devices/NetDevice.cs @@ -1,15 +1,15 @@ // License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2017 Intel Corporation. All Rights Reserved. -namespace Intel.RealSense +namespace Intel.RealSense.Net { using System; using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; + using Intel.RealSense; - - public class NetDevice : Device + public class NetDevice : ProxyDevice { public NetDevice(string address) : base(init(address)) { diff --git a/wrappers/csharp/Intel.RealSense.Net/GlobalSuppressions.cs b/wrappers/csharp/Intel.RealSense.Net/GlobalSuppressions.cs new file mode 100644 index 0000000000..2d0772ef53 --- /dev/null +++ b/wrappers/csharp/Intel.RealSense.Net/GlobalSuppressions.cs @@ -0,0 +1,8 @@ +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:Prefix local calls with this", Justification = "Pending")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1201:Elements must appear in the correct order", Justification = "Pending")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1202:Elements must be ordered by access", Justification = "Pending")] \ No newline at end of file diff --git a/wrappers/csharp/Intel.RealSense.Net/NativeMethods.cs b/wrappers/csharp/Intel.RealSense.Net/NativeMethods.cs new file mode 100644 index 0000000000..35797e6434 --- /dev/null +++ b/wrappers/csharp/Intel.RealSense.Net/NativeMethods.cs @@ -0,0 +1,42 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2017 Intel Corporation. All Rights Reserved. + +#pragma warning disable SA1600 // Elements must be documented +#pragma warning disable SA1124 // Do not use regions + +namespace Intel.RealSense.Net +{ + using System; + using System.Reflection.Emit; + using System.Runtime.InteropServices; + using System.Security; + using System.Security.Permissions; + + [SuppressUnmanagedCodeSecurity] + [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] + internal static class NativeMethods + { + +#if DEBUG + private const string dllName = "realsense2d"; + private const string dllNetName = "realsense2-netd"; +#else + private const string dllName = "realsense2"; + private const string dllNetName = "realsense2-net"; +#endif + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_context_add_software_device(ContextHandle ctx, IntPtr device, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(ErrorMarshaler))] out object error); + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_get_api_version([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(ErrorMarshaler))] out object error); + + #region rs_net_device + [DllImport(dllNetName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_create_net_device(int api_version, string address, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(ErrorMarshaler))] out object error); + #endregion + } +} + +#pragma warning restore SA1600 // Elements must be documented +#pragma warning restore SA1124 // Do not use regions diff --git a/wrappers/csharp/Intel.RealSense.Net/Properties/AssemblyInfo.cs b/wrappers/csharp/Intel.RealSense.Net/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..b1adde2ac0 --- /dev/null +++ b/wrappers/csharp/Intel.RealSense.Net/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2017 Intel Corporation. All Rights Reserved. + +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Intel(R) RealSense(TM) SDK C# Net Wrapper")] +[assembly: AssemblyDescription("Intel(R) RealSense(TM) SDK C# Net Wrapper")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Intel(R) Corporation")] +[assembly: AssemblyProduct("Intel(R) RealSense(TM) SDK C# Net Wrapper")] +[assembly: AssemblyCopyright("Copyright © 2021, Intel Corporation. All rights reserved")] +[assembly: AssemblyTrademark("Intel(R) RealSense(TM)")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("71c85ee0-c7c2-4e2e-8020-6af818537a15")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/wrappers/csharp/Intel.RealSense.Net/packages.config b/wrappers/csharp/Intel.RealSense.Net/packages.config new file mode 100644 index 0000000000..947d6d05b6 --- /dev/null +++ b/wrappers/csharp/Intel.RealSense.Net/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/wrappers/csharp/Intel.RealSense/Devices/CMakeLists.txt b/wrappers/csharp/Intel.RealSense/Devices/CMakeLists.txt index 44acda659d..9740225ab7 100644 --- a/wrappers/csharp/Intel.RealSense/Devices/CMakeLists.txt +++ b/wrappers/csharp/Intel.RealSense/Devices/CMakeLists.txt @@ -13,5 +13,5 @@ target_sources(${LRS_DOTNET_TARGET} "${CMAKE_CURRENT_LIST_DIR}/UpdatableDevice.cs" "${CMAKE_CURRENT_LIST_DIR}/UpdateDevice.cs" "${CMAKE_CURRENT_LIST_DIR}/FirmwareLogsDevice.cs" - "${CMAKE_CURRENT_LIST_DIR}/NetDevice.cs" + "${CMAKE_CURRENT_LIST_DIR}/ProxyDevice.cs" ) diff --git a/wrappers/csharp/Intel.RealSense/Devices/ProxyDevice.cs b/wrappers/csharp/Intel.RealSense/Devices/ProxyDevice.cs new file mode 100644 index 0000000000..fd783ce16e --- /dev/null +++ b/wrappers/csharp/Intel.RealSense/Devices/ProxyDevice.cs @@ -0,0 +1,22 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2017 Intel Corporation. All Rights Reserved. +// +// This proxy device is for accessing Device constructor that is internal, by successors in different namespaces and assemblies +// This way is more controllable for accessing base Device object instead of making it's constructors public +// Example of usage: NetDevice in Intel.Realsense.Net.dll that is a successor of ProxyDevice + +namespace Intel.RealSense +{ + using System; + using System.Collections; + using System.Collections.Generic; + using System.Runtime.InteropServices; + + + public class ProxyDevice : Device + { + public ProxyDevice(IntPtr ptr) : base(ptr) + { + } + } +} diff --git a/wrappers/csharp/cs-tutorial-7-net-dev/CMakeLists.txt b/wrappers/csharp/cs-tutorial-7-net-dev/CMakeLists.txt index 005d7e3cb3..e42c2ddba0 100644 --- a/wrappers/csharp/cs-tutorial-7-net-dev/CMakeLists.txt +++ b/wrappers/csharp/cs-tutorial-7-net-dev/CMakeLists.txt @@ -14,6 +14,7 @@ set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION # set_property(TARGET ${PROJECT_NAME} PROPERTY WIN32_EXECUTABLE TRUE) add_dependencies(${PROJECT_NAME} Intel.RealSense) +add_dependencies(${PROJECT_NAME} Intel.RealSense.Net) set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DOTNET_REFERENCES "System" diff --git a/wrappers/csharp/cs-tutorial-7-net-dev/Properties/AssemblyInfo.cs b/wrappers/csharp/cs-tutorial-7-net-dev/Properties/AssemblyInfo.cs index 162b6319d5..27e0264d43 100644 --- a/wrappers/csharp/cs-tutorial-7-net-dev/Properties/AssemblyInfo.cs +++ b/wrappers/csharp/cs-tutorial-7-net-dev/Properties/AssemblyInfo.cs @@ -5,11 +5,11 @@ // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("Intel(R) RealSense(TM) SDK C# Wrapper Tutorial-7")] -[assembly: AssemblyDescription("Intel(R) RealSense(TM) SDK C# Wrapper Examples")] +[assembly: AssemblyTitle("Intel(R) RealSense(TM) SDK C# Net Wrapper Tutorial-7")] +[assembly: AssemblyDescription("Intel(R) RealSense(TM) SDK C# Net Wrapper Examples")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Intel(R) Corporation")] -[assembly: AssemblyProduct("Intel(R) RealSense(TM) SDK C# Wrapper")] +[assembly: AssemblyProduct("Intel(R) RealSense(TM) SDK C# Net Wrapper Tutorial-7")] [assembly: AssemblyCopyright("Copyright © 2021, Intel Corporation. All rights reserved")] [assembly: AssemblyTrademark("Intel(R) RealSense(TM)")] [assembly: AssemblyCulture("")] @@ -20,7 +20,7 @@ [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("71c85ee0-c7c2-4e2e-8020-6af818537a14")] +[assembly: Guid("71c85ee0-c7c2-4e2e-8020-6af818537a16")] // Version information for an assembly consists of the following four values: // diff --git a/wrappers/csharp/cs-tutorial-7-net-dev/Window.xaml.cs b/wrappers/csharp/cs-tutorial-7-net-dev/Window.xaml.cs index 5001e0ee44..31c1b1feda 100644 --- a/wrappers/csharp/cs-tutorial-7-net-dev/Window.xaml.cs +++ b/wrappers/csharp/cs-tutorial-7-net-dev/Window.xaml.cs @@ -14,6 +14,7 @@ using System.Windows.Navigation; using System.Windows.Shapes; using System.Windows.Threading; +using Intel.RealSense.Net; namespace Intel.RealSense {