Skip to content
This repository has been archived by the owner on Apr 20, 2024. It is now read-only.

Commit

Permalink
hardcode shared library name since due to expected const value
Browse files Browse the repository at this point in the history
  • Loading branch information
MGTheTrain committed Apr 15, 2024
1 parent 8cadf2c commit dd4ee80
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 51 deletions.
41 changes: 14 additions & 27 deletions bindings/c#/Mgtt.CoreWrapper/CoreWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,24 @@

using System.Runtime.InteropServices;

namespace Mgtt.CoreWrapper
namespace Mgtt.CoreWrapper;
public class CoreWrapper
{
public class CoreWrapper
{
// Static field to hold the library path
private static string libraryPath;
[DllImport("core_wrapper", EntryPoint = "add")]
public static extern int Add(int a, int b);

// Property to set and get the library path
public static string LibraryPath
{
get { return libraryPath; }
set { libraryPath = value; }
}
[DllImport("core_wrapper", EntryPoint = "subtract")]
public static extern int Subtract(int a, int b);

// Declare the methods with the specified library path using EntryPoint
[DllImport("{LibraryPath}", EntryPoint = "add")]
public static extern int Add(int a, int b);
[DllImport("core_wrapper", EntryPoint = "multiply")]
public static extern int Multiply(int a, int b);

[DllImport("{LibraryPath}", EntryPoint = "subtract")]
public static extern int Subtract(int a, int b);
[DllImport("core_wrapper", EntryPoint = "divide")]
public static extern float Divide(float a, float b);

[DllImport("{LibraryPath}", EntryPoint = "multiply")]
public static extern int Multiply(int a, int b);
[DllImport("core_wrapper", EntryPoint = "getCircleArea")]
public static extern float GetCircleArea(float radius);

[DllImport("{LibraryPath}", EntryPoint = "divide")]
public static extern float Divide(float a, float b);

[DllImport("{LibraryPath}", EntryPoint = "getCircleArea")]
public static extern float GetCircleArea(float radius);

[DllImport("{LibraryPath}", EntryPoint = "getCircleCircumference")]
public static extern float GetCircleCircumference(float radius);
}
[DllImport("core_wrapper", EntryPoint = "getCircleCircumference")]
public static extern float GetCircleCircumference(float radius);
}
4 changes: 0 additions & 4 deletions bindings/c#/Mgtt.CoreWrapper/Mgtt.CoreWrapper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
</ItemGroup>

</Project>
20 changes: 0 additions & 20 deletions bindings/c#/Mgtt.CoreWrapper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,11 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using CommandLine;

namespace Mgtt.CoreWrapper;
class Program
{
static int Main(string[] args)
{
Options options = null;
Parser.Default.ParseArguments<Options>(args)
.WithParsed(o => options = o);

if (options == null)
{
Console.WriteLine("Usage: dotnet run --coreLibraryPath <coreLibraryPath>");
return 1;
}

CoreWrapper.LibraryPath = options.CoreLibraryPath;

int resultAdd = CoreWrapper.Add(10, 5);
Console.WriteLine("Addition result: " + resultAdd);

Expand All @@ -62,9 +48,3 @@ static int Main(string[] args)
return 0;
}
}

public class Options
{
[Option("coreLibraryPath", Required = true, HelpText = "Path to the core library.")]
public string CoreLibraryPath { get; set; }
}

0 comments on commit dd4ee80

Please sign in to comment.