Permalink
...
Comparing changes
Open a pull request
- 15 commits
- 12 files changed
- 0 commit comments
- 2 contributors
Commits on Jan 05, 2016
|
|
ThadHouse |
ba30a0c
|
Commits on Jan 15, 2016
|
|
ThadHouse |
d942de3
|
|||
|
|
ThadHouse |
1d54164
|
Commits on Jan 16, 2016
|
|
ThadHouse |
08ac214
|
Commits on Jan 18, 2016
|
|
ThadHouse |
31632da
|
Commits on Jan 19, 2016
|
|
ThadHouse |
23af27a
|
Commits on Jan 21, 2016
|
|
ThadHouse |
08f512d
|
|||
|
|
ThadHouse |
0d74aec
|
Commits on Feb 02, 2016
|
|
ThadHouse |
d63ba94
|
Commits on Feb 03, 2016
|
|
ThadHouse |
0eca370
|
|||
|
|
ThadHouse |
1f7980a
|
|||
|
|
ThadHouse |
f754890
|
Commits on Feb 06, 2016
|
|
jkoritzinsky |
6d9772c
|
|||
|
|
ThadHouse |
27f7c68
|
Commits on Feb 07, 2016
|
|
ThadHouse |
70db749
|
Unified
Split
Showing
with
286 additions
and 100 deletions.
- +2 −2 NetworkTablesCore.Test/TestNetworkTableAPIListeners.cs
- +6 −0 NetworkTablesCore/Native/CoreMethods.cs
- +56 −13 NetworkTablesCore/Native/Interop.cs
- +42 −0 NetworkTablesCore/Native/LibraryLoader.cs
- +54 −42 NetworkTablesCore/Native/LoaderUtilities.cs
- BIN NetworkTablesCore/NativeLibraries/armv7/libntcore.so
- BIN NetworkTablesCore/NativeLibraries/armv7/libstdc++.so
- +96 −39 NetworkTablesCore/NetworkTable.cs
- +1 −0 NetworkTablesCore/NetworkTablesCore.csproj
- +22 −1 NetworkTablesCore/Tables/IRemote.cs
- +6 −2 NetworkTablesCore/Tables/IRemoteConnectionListener.cs
- +1 −1 appveyor.yml
View
4
NetworkTablesCore.Test/TestNetworkTableAPIListeners.cs
| @@ -27,12 +27,12 @@ internal class MockConnectionListener : IRemoteConnectionListener | ||
| public IRemote ConnectedRemote = null; | ||
| public IRemote DisconnectedRemote = null; | ||
| - public void Connected(IRemote remote) | ||
| + public void Connected(IRemote remote, ConnectionInfo info) | ||
| { | ||
| ConnectedRemote = remote; | ||
| } | ||
| - public void Disconnected(IRemote remote) | ||
| + public void Disconnected(IRemote remote, ConnectionInfo info) | ||
| { | ||
| DisconnectedRemote = remote; | ||
| } | ||
View
6
NetworkTablesCore/Native/CoreMethods.cs
| @@ -525,13 +525,19 @@ internal static void StopClient() | ||
| StopRpcServer(); | ||
| StopNotifier(); | ||
| Interop.NT_StopClient(); | ||
| + //Clear callback dictionaries | ||
| + s_entryCallbacks.Clear(); | ||
| + s_connectionCallbacks.Clear(); | ||
| } | ||
| internal static void StopServer() | ||
| { | ||
| StopRpcServer(); | ||
| StopNotifier(); | ||
| Interop.NT_StopServer(); | ||
| + //Clear callback dictionaries | ||
| + s_entryCallbacks.Clear(); | ||
| + s_connectionCallbacks.Clear(); | ||
| } | ||
| internal static void StopNotifier() | ||
View
69
NetworkTablesCore/Native/Interop.cs
| @@ -1,5 +1,6 @@ | ||
| using System; | ||
| using System.IO; | ||
| +using System.Reflection; | ||
| using System.Runtime.InteropServices; | ||
| using System.Security; | ||
| // ReSharper disable InconsistentNaming | ||
| @@ -20,6 +21,9 @@ internal class Interop | ||
| // ReSharper disable PrivateFieldCanBeConvertedToLocalVariable | ||
| private static readonly IntPtr s_library; | ||
| private static readonly ILibraryLoader s_loader; | ||
| + private static readonly OsType s_osType; | ||
| + private static string s_libraryLocation = null; | ||
| + private static bool s_useCommandLineFile = false; | ||
| // ReSharper restore PrivateFieldCanBeConvertedToLocalVariable | ||
| static Interop() | ||
| @@ -28,8 +32,6 @@ static Interop() | ||
| { | ||
| try | ||
| { | ||
| - bool useCommandLineFile = false; | ||
| - string extractedLocation = null; | ||
| string[] commandArgs = Environment.GetCommandLineArgs(); | ||
| foreach (var commandArg in commandArgs) | ||
| @@ -44,33 +46,56 @@ static Interop() | ||
| //If the file exists, just return it so dlopen can load it. | ||
| if (File.Exists(file)) | ||
| { | ||
| - extractedLocation = file; | ||
| - useCommandLineFile = true; | ||
| + s_libraryLocation = file; | ||
| + s_useCommandLineFile = true; | ||
| } | ||
| } | ||
| } | ||
| - OsType type = LoaderUtilities.GetOsType(); | ||
| + s_osType = LoaderUtilities.GetOsType(); | ||
| - if (!useCommandLineFile) | ||
| + if (!s_useCommandLineFile) | ||
| { | ||
| - | ||
| - if (!LoaderUtilities.CheckOsValid(type)) | ||
| + | ||
| + if (!LoaderUtilities.CheckOsValid(s_osType)) | ||
| throw new InvalidOperationException("OS Not Supported"); | ||
| string embeddedResourceLocation; | ||
| - LoaderUtilities.GetLibraryName(type, out embeddedResourceLocation, out extractedLocation); | ||
| + LoaderUtilities.GetLibraryName(s_osType, out embeddedResourceLocation, out s_libraryLocation); | ||
| bool successfullyExtracted = LoaderUtilities.ExtractLibrary(embeddedResourceLocation, | ||
| - extractedLocation); | ||
| + ref s_libraryLocation); | ||
| if (!successfullyExtracted) | ||
| throw new FileNotFoundException( | ||
| "Library file could not be found in the resorces. Please contact RobotDotNet for support for this issue"); | ||
| } | ||
| - s_library = LoaderUtilities.LoadLibrary(extractedLocation, type, out s_loader); | ||
| + if (s_osType == OsType.Armv7HardFloat) | ||
| + { | ||
| + //Make sure the proper libstdc++.so.6 gets extracted. | ||
| + string resourceLocation = "NetworkTables.NativeLibraries.armv7.libstdc++.so"; | ||
| + string extractLoc = "libstdc++.so.6"; | ||
| + LoaderUtilities.ExtractLibrary(resourceLocation, ref extractLoc); | ||
| + } | ||
| - if (s_library == IntPtr.Zero) throw new BadImageFormatException($"Library file {extractedLocation} could not be loaded successfully."); | ||
| + s_library = LoaderUtilities.LoadLibrary(s_libraryLocation, s_osType, out s_loader); | ||
| + | ||
| + if (s_library == IntPtr.Zero) | ||
| + { | ||
| + if (s_osType == OsType.Armv7HardFloat) | ||
| + { | ||
| + //We are arm v7. We might need the special libstdc++.so.6; | ||
| + Console.WriteLine("You are on an Arm V7 device. On most of these devices, a " | ||
| + + "special library needs to be loaded. This library has been extracted" + | ||
| + " to the current directory. Please prepend your run command with\n" + | ||
| + "env LD_LIBRARY_PATH=.:LD_LIBRARY_PATH yourcommand\nand run again."); | ||
| + throw new InvalidOperationException("Follow the instructions printed above to solve this error."); | ||
| + } | ||
| + else | ||
| + { | ||
| + throw new BadImageFormatException($"Library file {s_libraryLocation} could not be loaded successfully."); | ||
| + } | ||
| + } | ||
| InitializeDelegates(s_library, s_loader); | ||
| } | ||
| @@ -82,8 +107,10 @@ static Interop() | ||
| } | ||
| s_libraryLoaded = true; | ||
| - //Adds our unload code. | ||
| + //Adds our unload code. OK to set both as only 1 | ||
| + //Will ever get called. | ||
| AppDomain.CurrentDomain.ProcessExit += OnProcessExit; | ||
| + AppDomain.CurrentDomain.DomainUnload += OnProcessExit; | ||
| } | ||
| } | ||
| @@ -96,6 +123,22 @@ private static void OnProcessExit(object sender, EventArgs e) | ||
| NT_StopServer(); | ||
| NT_StopRpcServer(); | ||
| NT_StopNotifier(); | ||
| + | ||
| + s_loader.UnloadLibrary(s_library); | ||
| + | ||
| + try | ||
| + { | ||
| + //Don't delete file if we are using a specified file. | ||
| + if (!s_useCommandLineFile && File.Exists(s_libraryLocation)) | ||
| + { | ||
| + File.Delete(s_libraryLocation); | ||
| + } | ||
| + } | ||
| + catch | ||
| + { | ||
| + //Any errors just ignore. | ||
| + } | ||
| + | ||
| } | ||
| private static void InitializeDelegates(IntPtr library, ILibraryLoader loader) | ||
View
42
NetworkTablesCore/Native/LibraryLoader.cs
| @@ -7,6 +7,8 @@ internal interface ILibraryLoader | ||
| { | ||
| IntPtr LoadLibrary(string filename); | ||
| IntPtr GetProcAddress(IntPtr dllHandle, string name); | ||
| + | ||
| + void UnloadLibrary(IntPtr handle); | ||
| } | ||
| [ExcludeFromCodeCoverage] | ||
| @@ -28,11 +30,19 @@ IntPtr ILibraryLoader.GetProcAddress(IntPtr dllHandle, string name) | ||
| return addr; | ||
| } | ||
| + void ILibraryLoader.UnloadLibrary(IntPtr handle) | ||
| + { | ||
| + FreeLibrary(handle); | ||
| + } | ||
| + | ||
| [DllImport("kernel32")] | ||
| private static extern IntPtr LoadLibrary(string fileName); | ||
| [DllImport("kernel32.dll")] | ||
| private static extern IntPtr GetProcAddress(IntPtr handle, string procedureName); | ||
| + | ||
| + [DllImport("kernel32")] | ||
| + private static extern bool FreeLibrary(IntPtr handle); | ||
| } | ||
| [ExcludeFromCodeCoverage] | ||
| @@ -62,6 +72,11 @@ IntPtr ILibraryLoader.GetProcAddress(IntPtr dllHandle, string name) | ||
| return result; | ||
| } | ||
| + void ILibraryLoader.UnloadLibrary(IntPtr handle) | ||
| + { | ||
| + dlclose(handle); | ||
| + } | ||
| + | ||
| [DllImport("libdl.so")] | ||
| private static extern IntPtr dlopen(string fileName, int flags); | ||
| @@ -70,6 +85,9 @@ IntPtr ILibraryLoader.GetProcAddress(IntPtr dllHandle, string name) | ||
| [DllImport("libdl.so")] | ||
| private static extern IntPtr dlerror(); | ||
| + | ||
| + [DllImport("libdl.so")] | ||
| + private static extern int dlclose(IntPtr handle); | ||
| } | ||
| @@ -100,6 +118,11 @@ IntPtr ILibraryLoader.GetProcAddress(IntPtr dllHandle, string name) | ||
| return result; | ||
| } | ||
| + void ILibraryLoader.UnloadLibrary(IntPtr handle) | ||
| + { | ||
| + dlclose(handle); | ||
| + } | ||
| + | ||
| [DllImport("dl")] | ||
| private static extern IntPtr dlopen(string fileName, int flags); | ||
| @@ -108,6 +131,9 @@ IntPtr ILibraryLoader.GetProcAddress(IntPtr dllHandle, string name) | ||
| [DllImport("dl")] | ||
| private static extern IntPtr dlerror(); | ||
| + | ||
| + [DllImport("dl")] | ||
| + private static extern int dlclose(IntPtr handle); | ||
| } | ||
| @@ -138,6 +164,11 @@ IntPtr ILibraryLoader.GetProcAddress(IntPtr dllHandle, string name) | ||
| return result; | ||
| } | ||
| + void ILibraryLoader.UnloadLibrary(IntPtr handle) | ||
| + { | ||
| + dlclose(handle); | ||
| + } | ||
| + | ||
| [DllImport("dl")] | ||
| private static extern IntPtr dlopen(string fileName, int flags); | ||
| @@ -146,6 +177,9 @@ IntPtr ILibraryLoader.GetProcAddress(IntPtr dllHandle, string name) | ||
| [DllImport("dl")] | ||
| private static extern IntPtr dlerror(); | ||
| + | ||
| + [DllImport("dl")] | ||
| + private static extern int dlclose(IntPtr handle); | ||
| } | ||
| [ExcludeFromCodeCoverage] | ||
| @@ -175,6 +209,11 @@ IntPtr ILibraryLoader.GetProcAddress(IntPtr dllHandle, string name) | ||
| return result; | ||
| } | ||
| + void ILibraryLoader.UnloadLibrary(IntPtr handle) | ||
| + { | ||
| + dlclose(handle); | ||
| + } | ||
| + | ||
| [DllImport("libdl-2.20.so")] | ||
| private static extern IntPtr dlopen(string fileName, int flags); | ||
| @@ -183,5 +222,8 @@ IntPtr ILibraryLoader.GetProcAddress(IntPtr dllHandle, string name) | ||
| [DllImport("libdl-2.20.so")] | ||
| private static extern IntPtr dlerror(); | ||
| + | ||
| + [DllImport("libdl-2.20.so")] | ||
| + private static extern int dlclose(IntPtr handle); | ||
| } | ||
| } | ||
Oops, something went wrong.