robotdotnet / WPILib

DotNet implementation of WPILib for FIRST Robotics Competition (FRC)
27 stars 8 forks source link

P invoke changes #46

Closed ThadHouse closed 8 years ago

ThadHouse commented 8 years ago

This includes all the changes to make P/Invoke dynamically load the HAL. Before, the code would have seperate signatures for P/Invoke, which would then be assigned to the delegates using reflection. Now, HAL-Base calls an Init function in either HAL-RoboRIO or HAL-Simulation. These functions in turn assign the delegates. For the simulation, which allows compile time checking, because if a method signature changes, the code will no longer compile. For the RoboRIO, it now gets the address of all native methods at bootup. This means that the code will throw an error if it cannot find the method immediately, instead of waiting until it gets called to fail. But checking every method at boot is still much better then what we used to have.

In addition, the way we distribute the native libraries has changed. Before, we used to only have 1. With changes made to the FIRST side, WPILib will now include 3, maybe 5 native libraries, and network tables includes 3, maybe 5 libraries. Distributing all of those would be a pain, especially since with the way nuget works, it adds all of them to the team's projects, which just creates a lot of clutter. The solution to this was to embed the native libraries into the DLL's. What we then do is at bootup we determine if we are RoboRIO, Win32, Win64, Unix32, or Unix64, and extract only the libraries needed to the system. This reduces file clutter, and the time tradeoff to write a 300kb file to disk is minimal. On unix systems, we still use the .so extension. However, on Windows, I am trying to use a .dlln extension. The reason for this is that reflection was at times getting confused between native and managed dlls, and the code to programmatically figure out before reflection loading which dlls are managed was not very nice looking. Since the files are just temp anyway, using another extension shouldn't be an issue, and saves some headache in other places of the code.

ThadHouse commented 8 years ago

Going to be merging this and #52 in the next 30 minutes or so. Then going to run a mass resharper run through the code, because there are a lot of extra using, and code spacing issues that I would like to fix.

jkoritzinsky commented 8 years ago

Awesome!