]> O.S.I.I.S - jp/crow.git/commitdiff
add MDEmbedTest proj
authorjpbruyere <jp.bruyere@hotmail.com>
Sun, 4 Jun 2017 10:29:28 +0000 (12:29 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Sun, 4 Jun 2017 10:29:28 +0000 (12:29 +0200)
Crow.sln
MDEmbedTest/MDEmbedTest.cproj [new file with mode: 0644]
MDEmbedTest/Makefile [new file with mode: 0644]
MDEmbedTest/main.c [new file with mode: 0644]
MDEmbedTest/main.o [new file with mode: 0644]
MDEmbedTest/mdembed [new file with mode: 0755]
MDEmbedTest/test.cs [new file with mode: 0644]
MDEmbedTest/test.exe [new file with mode: 0755]
MDEmbedTest/test2.cs [new file with mode: 0644]
MDEmbedTest/test2.exe [new file with mode: 0755]
testDrm/TestCrow.cs

index 446bb1ddc77fe7ce4915afc9c7e01c766656e98c..726778656e2a23065a5c2f3114e7f44ca368a6ba 100644 (file)
--- 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 (file)
index 0000000..3c209af
--- /dev/null
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>8.0.30703</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{A41EEF9F-6F0C-402E-9AD0-C23B7A32B05D}</ProjectGuid>
+    <Compiler>
+      <Compiler ctype="GccCompiler" />
+    </Compiler>
+    <Language>C</Language>
+    <Target>Bin</Target>
+    <ReleaseVersion>0.5</ReleaseVersion>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <OutputPath>bin\Debug</OutputPath>
+    <Externalconsole>true</Externalconsole>
+    <OutputName>MDEmbedTest</OutputName>
+    <CompileTarget>Bin</CompileTarget>
+    <DefineSymbols>DEBUG MONODEVELOP</DefineSymbols>
+    <SourceDirectory>.</SourceDirectory>
+    <CustomCommands>
+      <CustomCommands>
+        <Command type="Build" command="make" />
+        <Command type="Execute" command="make run" externalConsole="True" pauseExternalConsole="True" />
+      </CustomCommands>
+    </CustomCommands>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <OutputPath>bin\Release</OutputPath>
+    <Externalconsole>true</Externalconsole>
+    <OutputName>MDEmbedTest</OutputName>
+    <CompileTarget>Bin</CompileTarget>
+    <OptimizationLevel>3</OptimizationLevel>
+    <DefineSymbols>MONODEVELOP</DefineSymbols>
+    <SourceDirectory>.</SourceDirectory>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="main.c" />
+    <Compile Include="test.cs" />
+  </ItemGroup>
+  <ProjectExtensions>
+    <MonoDevelop>
+      <Properties>
+        <MonoDevelop.Autotools.MakefileInfo IntegrationEnabled="True" RelativeMakefileName="Makefile">
+          <BuildFilesVar />
+          <DeployFilesVar />
+          <ResourcesVar />
+          <OthersVar />
+          <GacRefVar />
+          <AsmRefVar />
+          <ProjectRefVar />
+        </MonoDevelop.Autotools.MakefileInfo>
+      </Properties>
+    </MonoDevelop>
+  </ProjectExtensions>
+  <ItemGroup>
+    <None Include="Makefile" />
+    <None Include="test2.cs" />
+  </ItemGroup>
+</Project>
\ No newline at end of file
diff --git a/MDEmbedTest/Makefile b/MDEmbedTest/Makefile
new file mode 100644 (file)
index 0000000..631fa27
--- /dev/null
@@ -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 (file)
index 0000000..45a01cd
--- /dev/null
@@ -0,0 +1,78 @@
+#include <mono/jit/jit.h>
+#include <mono/metadata/environment.h>
+#include <stdlib.h>
+#include <GL/gl.h>
+#include <GL/glext.h>
+
+/*
+ * 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 (file)
index 0000000..eb52af1
Binary files /dev/null and b/MDEmbedTest/main.o differ
diff --git a/MDEmbedTest/mdembed b/MDEmbedTest/mdembed
new file mode 100755 (executable)
index 0000000..db17b65
Binary files /dev/null and b/MDEmbedTest/mdembed differ
diff --git a/MDEmbedTest/test.cs b/MDEmbedTest/test.cs
new file mode 100644 (file)
index 0000000..6a24f92
--- /dev/null
@@ -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 (executable)
index 0000000..b49eb85
Binary files /dev/null and b/MDEmbedTest/test.exe differ
diff --git a/MDEmbedTest/test2.cs b/MDEmbedTest/test2.cs
new file mode 100644 (file)
index 0000000..eb23a83
--- /dev/null
@@ -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 (executable)
index 0000000..c98fc48
Binary files /dev/null and b/MDEmbedTest/test2.exe differ
index bc6ba00d11a4d794a64c6c9ad4cbe9002189c72b..552b71981616b0f1402d819669dec1e463a660c8 100644 (file)
@@ -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");
-                       }
+                       }*/
                }
        }
 }