From: jpbruyere Date: Sun, 4 Jun 2017 10:29:28 +0000 (+0200) Subject: add MDEmbedTest proj X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=44e2a7781a10a6c40fe267a3d4195b3fbd8a871b;p=jp%2Fcrow.git add MDEmbedTest proj --- diff --git a/Crow.sln b/Crow.sln index 446bb1dd..72677865 100644 --- a/Crow.sln +++ b/Crow.sln @@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DRI.net", "..\DRI.net\DRI.n EndProject Project("{2857B73E-F847-4B02-9238-064979017E93}") = "libcrow", "..\libcrow\libcrow.cproj", "{6CD55032-B8D6-4238-AA91-F9145E1217D4}" EndProject +Project("{2857B73E-F847-4B02-9238-064979017E93}") = "MDEmbedTest", "MDEmbedTest\MDEmbedTest.cproj", "{A41EEF9F-6F0C-402E-9AD0-C23B7A32B05D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -37,6 +39,10 @@ Global {74289092-9F70-4941-AFCB-DFD7BE2140B6}.Release|Any CPU.Build.0 = Release|Any CPU {A37A7E14-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A37A7E14-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A41EEF9F-6F0C-402E-9AD0-C23B7A32B05D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A41EEF9F-6F0C-402E-9AD0-C23B7A32B05D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A41EEF9F-6F0C-402E-9AD0-C23B7A32B05D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A41EEF9F-6F0C-402E-9AD0-C23B7A32B05D}.Release|Any CPU.Build.0 = Release|Any CPU {B6D911CD-1D09-42FC-B300-9187190F2AE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B6D911CD-1D09-42FC-B300-9187190F2AE1}.Release|Any CPU.ActiveCfg = Release|Any CPU {B6D911CD-1D09-42FC-B300-9187190F2AE1}.Release|Any CPU.Build.0 = Release|Any CPU diff --git a/MDEmbedTest/MDEmbedTest.cproj b/MDEmbedTest/MDEmbedTest.cproj new file mode 100644 index 00000000..3c209afc --- /dev/null +++ b/MDEmbedTest/MDEmbedTest.cproj @@ -0,0 +1,63 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {A41EEF9F-6F0C-402E-9AD0-C23B7A32B05D} + + + + C + Bin + 0.5 + + + true + bin\Debug + true + MDEmbedTest + Bin + DEBUG MONODEVELOP + . + + + + + + + + + bin\Release + true + MDEmbedTest + Bin + 3 + MONODEVELOP + . + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MDEmbedTest/Makefile b/MDEmbedTest/Makefile new file mode 100644 index 00000000..631fa272 --- /dev/null +++ b/MDEmbedTest/Makefile @@ -0,0 +1,31 @@ +export PKG_CONFIG_PATH = /opt/mono/lib/pkgconfig + +CC = gcc +CFLAGS = -Wall -Wextra -O2 -g -DDEBUG +LDFLAGS = + +TARGET = mdembed +SOURCES = main.c +OBJECTS = $(SOURCES:.c=.o) + +CFLAGS += `pkg-config --cflags --libs mono-2` +CFLAGS += `pkg-config --cflags --libs cairo` +CFLAGS += `pkg-config --cflags --libs gl` + +.PHONY: all +all: ${TARGET} test.exe test2.exe + +$(TARGET): $(OBJECTS) + $(CC) $(CFLAGS) ${LDFLAGS} -o $(TARGET) $(OBJECTS) +test.exe : test.cs + mcs -unsafe test.cs +test2.exe : test2.cs + mcs -unsafe test2.cs + +.PHONY: clean +clean: + -rm -f ${TARGET} ${OBJECTS} test.exe test2.exe + +.PHONY: run +run: + -./${TARGET} test.exe \ No newline at end of file diff --git a/MDEmbedTest/main.c b/MDEmbedTest/main.c new file mode 100644 index 00000000..45a01cd3 --- /dev/null +++ b/MDEmbedTest/main.c @@ -0,0 +1,78 @@ +#include +#include +#include +#include +#include + +/* + * Very simple mono embedding example. + * Compile with: + * gcc -o teste teste.c `pkg-config --cflags --libs mono-2` -lm + * mcs test.cs + * Run with: + * ./teste test.exe + */ + +static MonoString* +gimme () { + return mono_string_new (mono_domain_get (), "All your monos are belong to us!"); +} + +static void main_function (MonoDomain *domain, const char *file, int argc, char** argv) +{ + MonoAssembly *assembly; + MonoAssembly *a2; + + assembly = mono_domain_assembly_open (domain, file); + if (!assembly) + exit (2); + a2 = mono_domain_assembly_open (domain, "test2.exe"); + if (!a2) + exit (2); + /* + * mono_jit_exec() will run the Main() method in the assembly. + * The return value needs to be looked up from + * System.Environment.ExitCode. + */ + mono_jit_exec (domain, assembly, argc, argv); + mono_jit_exec (domain, a2, argc, argv); +} + +int +main(int argc, char* argv[]) { + MonoDomain *domain; + const char *file; + int retval; + + if (argc < 2){ + fprintf (stderr, "Please provide an assembly to load\n"); + return 1; + } + file = argv [1]; + + /* + * Load the default Mono configuration file, this is needed + * if you are planning on using the dllmaps defined on the + * system configuration + */ + mono_config_parse (NULL); + /* + * mono_jit_init() creates a domain: each assembly is + * loaded and run in a MonoDomain. + */ + domain = mono_jit_init (file); + /* + * We add our special internal call, so that C# code + * can call us back. + */ + mono_add_internal_call ("MonoEmbed::gimme", gimme); + + main_function (domain, file, argc - 1, argv + 1); + + retval = mono_environment_exitcode_get (); + + mono_jit_cleanup (domain); + return retval; +} + + diff --git a/MDEmbedTest/main.o b/MDEmbedTest/main.o new file mode 100644 index 00000000..eb52af13 Binary files /dev/null and b/MDEmbedTest/main.o differ diff --git a/MDEmbedTest/mdembed b/MDEmbedTest/mdembed new file mode 100755 index 00000000..db17b65d Binary files /dev/null and b/MDEmbedTest/mdembed differ diff --git a/MDEmbedTest/test.cs b/MDEmbedTest/test.cs new file mode 100644 index 00000000..6a24f927 --- /dev/null +++ b/MDEmbedTest/test.cs @@ -0,0 +1,11 @@ +using System; +using System.Runtime.CompilerServices; + +class MonoEmbed { + [MethodImplAttribute(MethodImplOptions.InternalCall)] + unsafe extern static string gimme(); + + static void Main() { + Console.WriteLine (gimme ()); + } +} diff --git a/MDEmbedTest/test.exe b/MDEmbedTest/test.exe new file mode 100755 index 00000000..b49eb856 Binary files /dev/null and b/MDEmbedTest/test.exe differ diff --git a/MDEmbedTest/test2.cs b/MDEmbedTest/test2.cs new file mode 100644 index 00000000..eb23a837 --- /dev/null +++ b/MDEmbedTest/test2.cs @@ -0,0 +1,11 @@ +using System; +using System.Runtime.CompilerServices; + +class MonoEmbed { + [MethodImplAttribute(MethodImplOptions.InternalCall)] + unsafe extern static string gimme(); + + static void Main() { + Console.WriteLine ("test2 => " + gimme ()); + } +} diff --git a/MDEmbedTest/test2.exe b/MDEmbedTest/test2.exe new file mode 100755 index 00000000..c98fc48a Binary files /dev/null and b/MDEmbedTest/test2.exe differ diff --git a/testDrm/TestCrow.cs b/testDrm/TestCrow.cs index bc6ba00d..552b7198 100644 --- a/testDrm/TestCrow.cs +++ b/testDrm/TestCrow.cs @@ -34,7 +34,7 @@ namespace testDrm public class TestCrow { //const string lib = "/mnt/data2/devel/crow/libcrow/bin/Debug/libcrow.so"; - const string lib = "/home/jp/devel/testsharedlib/bin/Debug/libcrow.so"; + const string lib = "libcrow.so"; [StructLayout(LayoutKind.Sequential)] public struct testStruct { @@ -48,26 +48,22 @@ namespace testDrm public int a = 10,b=20; } - [DllImport(lib, CallingConvention = CallingConvention.Cdecl)] - internal static extern void testAppDomain(); - - [DllImport(lib, CallingConvention = CallingConvention.Cdecl)] - internal static extern int gimmePI (ref testStruct t); - [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal static extern int gimme (ref testStruct t); - - [MethodImplAttribute(MethodImplOptions.InternalCall)] - public extern object UnsafeGetValue (object obj); + unsafe extern static string gimme(); + [DllImport(lib, CallingConvention = CallingConvention.Cdecl)] + internal static extern void registerICall (); static void Main(){ - using (Interface iface = new Interface ()) { + registerICall (); + Console.WriteLine (gimme()); + + /*using (Interface iface = new Interface ()) { Console.WriteLine ("is dirty: {0}", iface.IsDirty); iface.ProcessResize (new Rectangle (0, 0, 1024, 768)); iface.LoadInterface ("#testDrm.ui.go.crow"); iface.Update (); iface.DumpTo ("/home/jp/test.png"); - } + }*/ } } }