contrib: add .net bindings

DotRocket is a C++/CLI assembly that binds the C-api to Managed
objects for .NET.
This commit is contained in:
Anders Knive Lassen 2011-03-11 18:01:09 +01:00 committed by Erik Faye-Lund
parent 4c8769c630
commit a5e224713a
15 changed files with 808 additions and 0 deletions

View File

@ -0,0 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DotRocket", "DotRocket\DotRocket.vcproj", "{C982166A-686F-4BAD-9370-62DADC1DCCD0}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DotRocketClient", "DotRocketClient\DotRocketClient.vcproj", "{711C0884-4DCF-47AA-87D6-B643F15A6727}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C982166A-686F-4BAD-9370-62DADC1DCCD0}.Debug|Win32.ActiveCfg = Debug|Win32
{C982166A-686F-4BAD-9370-62DADC1DCCD0}.Debug|Win32.Build.0 = Debug|Win32
{C982166A-686F-4BAD-9370-62DADC1DCCD0}.Release|Win32.ActiveCfg = Release|Win32
{C982166A-686F-4BAD-9370-62DADC1DCCD0}.Release|Win32.Build.0 = Release|Win32
{711C0884-4DCF-47AA-87D6-B643F15A6727}.Debug|Win32.ActiveCfg = Debug|Win32
{711C0884-4DCF-47AA-87D6-B643F15A6727}.Debug|Win32.Build.0 = Debug|Win32
{711C0884-4DCF-47AA-87D6-B643F15A6727}.Release|Win32.ActiveCfg = Release|Win32
{711C0884-4DCF-47AA-87D6-B643F15A6727}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,40 @@
#include "stdafx.h"
using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::CompilerServices;
using namespace System::Runtime::InteropServices;
using namespace System::Security::Permissions;
//
// 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:AssemblyTitleAttribute("DotRocket")];
[assembly:AssemblyDescriptionAttribute("")];
[assembly:AssemblyConfigurationAttribute("")];
[assembly:AssemblyCompanyAttribute("Microsoft")];
[assembly:AssemblyProductAttribute("DotRocket")];
[assembly:AssemblyCopyrightAttribute("Copyright (c) GNU Rocket Foundation 2011")];
[assembly:AssemblyTrademarkAttribute("")];
[assembly:AssemblyCultureAttribute("")];
//
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the value or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly:AssemblyVersionAttribute("1.0.*")];
[assembly:ComVisible(false)];
[assembly:CLSCompliantAttribute(true)];
[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)];

View File

@ -0,0 +1,46 @@
// This is the main DLL file.
#include "stdafx.h"
#include "DotRocket.h"
#include "../../../sync/sync.h"
#include "../../../sync/track.h"
using System::Runtime::InteropServices::Marshal;
using DotRocket::Track;
using DotRocket::PlayerDevice;
private ref class PlayerTrack: public Track {
const sync_track *track;
public:
PlayerTrack(const sync_track *track): track(track) {}
virtual float GetValue(double time) override
{
return sync_get_val(track, time);
};
};
PlayerDevice::PlayerDevice(System::String ^name)
{
char *cname = (char *)(void *)Marshal::StringToHGlobalAnsi(name);
device = sync_create_device(cname);
tracks = gcnew Dictionary<String ^, Track ^>();
}
Track ^PlayerDevice::GetTrack(String^ name)
{
Track ^track;
if (!tracks->TryGetValue(name, track)) {
char *ctrackName = (char *)(void *)Marshal::StringToHGlobalAnsi(name);
track = gcnew PlayerTrack(sync_get_track(device, ctrackName));
Marshal::FreeHGlobal((System::IntPtr)ctrackName);
tracks->Add(name, track);
}
return track;
}
PlayerDevice::!PlayerDevice()
{
sync_destroy_device(device);
}

View File

@ -0,0 +1,52 @@
// DotRocket.h
#pragma once
struct sync_device;
struct sync_track;
using namespace System;
using namespace System::Collections::Generic;
namespace DotRocket
{
public ref class Track abstract
{
public:
virtual float GetValue(double time) = 0;
};
public delegate void PauseEventHandler(bool flag);
public delegate void SetRowEventHandler(int row);
public delegate bool IsPlayingEventHandler();
public ref class Device abstract
{
public:
virtual bool Update(int row) { return true; }
virtual bool Connect(System::String ^host, unsigned short port)
{
throw gcnew Exception("Connect() not valid on this type of DotRocket.Device");
}
virtual Track^ GetTrack(String ^name) = 0;
event PauseEventHandler ^OnPause;
event SetRowEventHandler ^OnSetRow;
event IsPlayingEventHandler ^OnIsPlaying;
void Pause(bool flag) { OnPause(flag); }
void SetRow(int row) { OnSetRow(row); }
bool IsPlaying() { return OnIsPlaying(); }
};
// Player-specific implementation
public ref class PlayerDevice: public Device
{
sync_device *device;
Dictionary<String ^, Track ^> ^tracks;
public:
PlayerDevice(System::String ^name);
~PlayerDevice() { this->!PlayerDevice(); }
!PlayerDevice();
virtual Track^ GetTrack(String ^name) override;
};
}

View File

@ -0,0 +1,229 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Name="DotRocket"
ProjectGUID="{C982166A-686F-4BAD-9370-62DADC1DCCD0}"
RootNamespace="rocket"
Keyword="ManagedCProj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="2"
ManagedExtensions="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG"
RuntimeLibrary="3"
UsePrecompiledHeader="2"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="..\..\..\Release\sync_player.lib"
GenerateDebugInformation="true"
AssemblyDebug="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="2"
ManagedExtensions="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG"
RuntimeLibrary="2"
UsePrecompiledHeader="2"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="..\..\..\Release\sync_player.lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
<AssemblyReference
RelativePath="System.dll"
AssemblyName="System, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"
MinFrameworkVersion="131072"
/>
<AssemblyReference
RelativePath="System.Data.dll"
AssemblyName="System.Data, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=x86"
MinFrameworkVersion="131072"
/>
<AssemblyReference
RelativePath="System.XML.dll"
AssemblyName="System.Xml, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"
MinFrameworkVersion="131072"
/>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\AssemblyInfo.cpp"
>
</File>
<File
RelativePath=".\DotRocket.cpp"
>
</File>
<File
RelativePath=".\Stdafx.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\DotRocket.h"
>
</File>
<File
RelativePath=".\resource.h"
>
</File>
<File
RelativePath=".\Stdafx.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,5 @@
// stdafx.cpp : source file that includes just the standard includes
// DotRocket.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"

View File

@ -0,0 +1,7 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently
#pragma once

View File

@ -0,0 +1,3 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by app.rc

View File

@ -0,0 +1,40 @@
#include "stdafx.h"
using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::CompilerServices;
using namespace System::Runtime::InteropServices;
using namespace System::Security::Permissions;
//
// 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:AssemblyTitleAttribute("DotRocketClient")];
[assembly:AssemblyDescriptionAttribute("")];
[assembly:AssemblyConfigurationAttribute("")];
[assembly:AssemblyCompanyAttribute("Microsoft")];
[assembly:AssemblyProductAttribute("DotRocketClient")];
[assembly:AssemblyCopyrightAttribute("Copyright (c) GNU Rocket Foundation 2011")];
[assembly:AssemblyTrademarkAttribute("")];
[assembly:AssemblyCultureAttribute("")];
//
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the value or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly:AssemblyVersionAttribute("1.0.*")];
[assembly:ComVisible(false)];
[assembly:CLSCompliantAttribute(true)];
[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)];

View File

@ -0,0 +1,88 @@
// This is the main DLL file.
#include "stdafx.h"
#include "../../../sync/sync.h"
#include "../../../sync/track.h"
using System::Runtime::InteropServices::Marshal;
#include "DotRocketClient.h"
using DotRocket::Track;
using DotRocket::Device;
using DotRocket::ClientDevice;
private ref class ClientTrack: public Track {
const sync_track *track;
public:
ClientTrack(const sync_track *track) : track(track) {}
virtual float GetValue(double time) override
{
return sync_get_val(track, time);
};
};
ref class Callbacks {
public:
static Device ^DeviceCurrenltyBeingProcessed = nullptr;
};
void cb_pause(void *arg, int row)
{
Callbacks::DeviceCurrenltyBeingProcessed->Pause(row);
}
void cb_set_row(void *arg, int row)
{
Callbacks::DeviceCurrenltyBeingProcessed->SetRow(row);
}
int cb_is_playing(void *arg)
{
return !!Callbacks::DeviceCurrenltyBeingProcessed->IsPlaying();
}
sync_cb callbacks[] = {
cb_pause,
cb_set_row,
cb_is_playing
};
ClientDevice::ClientDevice(System::String^ name)
{
char *cname = (char *)(void *)Marshal::StringToHGlobalAnsi(name);
device = sync_create_device(cname);
tracks = gcnew Dictionary<String^, Track^>();
}
Track ^ClientDevice::GetTrack(String^ name)
{
Track ^track;
if (!tracks->TryGetValue(name, track)) {
char *ctrackName = (char *)(void *)Marshal::StringToHGlobalAnsi(name);
track = gcnew ClientTrack(sync_get_track(device, ctrackName));
Marshal::FreeHGlobal((System::IntPtr)ctrackName);
tracks->Add(name, track);
}
return track;
}
ClientDevice::!ClientDevice()
{
sync_destroy_device(device);
}
bool ClientDevice::Connect(System::String^ host, unsigned short port)
{
char *chost = (char *)(void *)Marshal::StringToHGlobalAnsi(host);
int result = sync_connect((sync_device *)device, chost, port);
Marshal::FreeHGlobal((System::IntPtr)chost);
return !result;
}
bool ClientDevice::Update(int row)
{
Callbacks::DeviceCurrenltyBeingProcessed = this;
return !sync_update(device, row, callbacks, device);
}

View File

@ -0,0 +1,24 @@
// DotRocketClient.h
#pragma once
struct sync_device;
struct sync_track;
using namespace System;
using namespace System::Collections::Generic;
namespace DotRocket {
public ref class ClientDevice: public Device {
protected:
sync_device *device;
Dictionary<System::String ^, Track ^> ^tracks;
public:
ClientDevice(System::String ^name);
~ClientDevice() { this->!ClientDevice(); }
!ClientDevice();
virtual Track^ GetTrack(String ^name) override;
virtual bool Connect(System::String ^host, unsigned short port) override;
virtual bool Update(int row) override;
};
}

View File

@ -0,0 +1,233 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Name="DotRocketClient"
ProjectGUID="{711C0884-4DCF-47AA-87D6-B643F15A6727}"
RootNamespace="rocket"
Keyword="ManagedCProj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="2"
ManagedExtensions="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG"
RuntimeLibrary="3"
UsePrecompiledHeader="2"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="&quot;..\..\..\Release Client\sync_player.lib&quot;"
GenerateDebugInformation="true"
AssemblyDebug="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="2"
ManagedExtensions="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG"
RuntimeLibrary="2"
UsePrecompiledHeader="2"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="&quot;..\..\..\Release Client\sync_player.lib&quot;"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
<AssemblyReference
RelativePath="System.dll"
AssemblyName="System, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"
MinFrameworkVersion="131072"
/>
<AssemblyReference
RelativePath="System.Data.dll"
AssemblyName="System.Data, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=x86"
MinFrameworkVersion="131072"
/>
<AssemblyReference
RelativePath="System.XML.dll"
AssemblyName="System.Xml, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"
MinFrameworkVersion="131072"
/>
<ProjectReference
ReferencedProjectIdentifier="{C982166A-686F-4BAD-9370-62DADC1DCCD0}"
RelativePathToProject=".\DotRocket\DotRocket.vcproj"
/>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\AssemblyInfo.cpp"
>
</File>
<File
RelativePath=".\DotRocketClient.cpp"
>
</File>
<File
RelativePath=".\Stdafx.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\DotRocketClient.h"
>
</File>
<File
RelativePath=".\resource.h"
>
</File>
<File
RelativePath=".\Stdafx.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,5 @@
// stdafx.cpp : source file that includes just the standard includes
// DotRocketClient.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"

View File

@ -0,0 +1,7 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently
#pragma once

View File

@ -0,0 +1,3 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by app.rc