summaryrefslogtreecommitdiff
path: root/src/examples/efl_mono
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2017-11-23 22:01:25 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2017-12-04 15:47:51 -0300
commit41c073b2e61e8c0562cbdf25bdad8a3133275f81 (patch)
treee53a7d237b1eb840457b8ce1c5e056eaceb6f51e /src/examples/efl_mono
parent8b1a72e972a3396c51a16654bc05c3a23ad6afc0 (diff)
efl_mono: Add examples code.
Buildsystem support will be enabled in a future commit
Diffstat (limited to 'src/examples/efl_mono')
-rw-r--r--src/examples/efl_mono/.gitignore1
-rw-r--r--src/examples/efl_mono/EoInherit01.cs64
-rw-r--r--src/examples/efl_mono/FunctionPointer01.cs45
-rw-r--r--src/examples/efl_mono/Makefile.am123
-rw-r--r--src/examples/efl_mono/example_numberwrapper.c87
-rw-r--r--src/examples/efl_mono/example_numberwrapper.eo30
6 files changed, 350 insertions, 0 deletions
diff --git a/src/examples/efl_mono/.gitignore b/src/examples/efl_mono/.gitignore
new file mode 100644
index 0000000..7a426d3
--- /dev/null
+++ b/src/examples/efl_mono/.gitignore
@@ -0,0 +1 @@
/example_numberwrapper.out
diff --git a/src/examples/efl_mono/EoInherit01.cs b/src/examples/efl_mono/EoInherit01.cs
new file mode 100644
index 0000000..6b899ae
--- /dev/null
+++ b/src/examples/efl_mono/EoInherit01.cs
@@ -0,0 +1,64 @@
1using static System.Console;
2
3class PlusTenNumberWrapper : example.NumberwrapperInherit
4{
5 public PlusTenNumberWrapper(efl.Object parent = null)
6 : base(parent)
7 {}
8
9 public bool derivedCalled = false;
10
11 override public void SetNumber(int n)
12 {
13 // Call native EFL method
14 base.SetNumber(n + 10);
15 derivedCalled = true;
16 }
17}
18
19public class ExampleEoInherit01
20{
21 public static void Main()
22 {
23 eina.Config.Init();
24 efl.eo.Config.Init();
25
26 var inheritObj = new PlusTenNumberWrapper();
27
28 WriteLine("## Using inherit object ##\n");
29
30 int given = 111;
31
32 // Call the C# override from the C method
33 example.NumberwrapperConcrete.example_numberwrapper_number_set(inheritObj.raw_handle, given);
34
35 WriteLine($"Override successfully called? {inheritObj.derivedCalled}!\n");
36
37 // Call C function from C# object
38 int stored = inheritObj.GetNumber();
39
40 WriteLine($"Given value: {given}");
41 WriteLine($"Stored value: {stored}\n");
42
43 // Call C# override directly
44 given = 333;
45 inheritObj.SetNumber(given);
46
47 stored = inheritObj.GetNumber();
48
49 WriteLine($"Given value: {given}");
50 WriteLine($"Stored value: {stored}\n");
51
52 WriteLine("## Using original object ##\n");
53
54 // Check original EFL object
55 var origObj = new example.NumberwrapperConcrete();
56 given = 111;
57 origObj.SetNumber(given);
58 stored = origObj.GetNumber();
59
60 WriteLine($"Given value: {given}");
61 WriteLine($"Stored value: {stored}\n");
62 }
63}
64
diff --git a/src/examples/efl_mono/FunctionPointer01.cs b/src/examples/efl_mono/FunctionPointer01.cs
new file mode 100644
index 0000000..2954473
--- /dev/null
+++ b/src/examples/efl_mono/FunctionPointer01.cs
@@ -0,0 +1,45 @@
1using static System.Console;
2
3public class ExampleFunctionPointer01
4{
5 private static bool static_called = false;
6
7 private static int twiceCb(int n)
8 {
9 static_called = true;
10 return n * 2;
11 }
12
13 public static void Main()
14 {
15 eina.Config.Init();
16 efl.eo.Config.Init();
17
18 var obj = new example.NumberwrapperConcrete();
19
20 // Set internal value
21 obj.SetNumber(12);
22
23 // With static method
24 obj.SetNumberCallback(twiceCb);
25
26 var ret = obj.CallCallback();
27
28 WriteLine($"Callback called? {static_called}.");
29 WriteLine($"Returned value: {ret}.\n");
30
31 // With lambda
32 bool lamda_called = false;
33
34 obj.SetNumberCallback(n => {
35 lamda_called = true;
36 return n * 3;
37 });
38
39 ret = obj.CallCallback();
40
41 WriteLine($"Lambda called? {lamda_called}.");
42 WriteLine($"Returned value: {ret}.\n");
43 }
44}
45
diff --git a/src/examples/efl_mono/Makefile.am b/src/examples/efl_mono/Makefile.am
new file mode 100644
index 0000000..6bae1d9
--- /dev/null
+++ b/src/examples/efl_mono/Makefile.am
@@ -0,0 +1,123 @@
1MAINTAINERCLEANFILES = Makefile.in
2
3if HAVE_CSHARP
4
5include $(top_srcdir)/src/Makefile_Eolian_Helper.am
6include $(top_srcdir)/src/Makefile_Eolian_Mono_Helper.am
7include $(top_srcdir)/src/Makefile_Efl_Mono_MSBuild_Gen_Helper.am
8
9SRCS =
10EXTRA_FILES =
11EXTRA_PROGRAMS =
12GENERATED =
13CLEANFILES =
14
15# Simple object used by the examples
16
17EOLIAN_FLAGS := $(EOLIAN_FLAGS)
18EOLIAN_FLAGS += \
19-I$(srcdir) \
20-I$(top_srcdir)/src/lib/eo \
21-I$(top_srcdir)/src/lib/efl
22
23COMMON_FLAGS = \
24@EINA_CFLAGS@ @EINA_LDFLAGS@ \
25-L$(top_builddir)/src/lib/eina/.libs -leina \
26@EO_CFLAGS@ @EO_LDFLAGS@ \
27-L$(top_builddir)/src/lib/eo/.libs -leo \
28@EFL_CFLAGS@ @EFL_LDFLAGS@ \
29-L$(top_builddir)/src/lib/efl/.libs -lefl
30
31if HAVE_WIN32
32COMMON_FLAGS += \
33@EVIL_CFLAGS@ @EVIL_LDFLAGS@ \
34@EFL_WINDOWS_VERSION_CFLAGS@ \
35-L$(top_builddir)/src/lib/evil/.libs -levil
36else
37COMMON_FLAGS += \
38-fPIC -DPIC
39endif
40
41
42%.eo.c: %.eo
43 $(AM_V_EOL)$(EOLIAN_GEN) $(EOLIAN_FLAGS) -gc -o c:$@ $<
44
45%.eo.h: %.eo
46 $(AM_V_EOL)$(EOLIAN_GEN) $(EOLIAN_FLAGS) -gh -o h:$@ $<
47
48example_numberwrapper.c: example_numberwrapper.eo.h example_numberwrapper.eo.c
49
50numberwrapper_lib_name = example_numberwrapper.out
51
52$(numberwrapper_lib_name): example_numberwrapper.c
53 $(CC) -shared -o $@ $< -DEFL_BETA_API_SUPPORT -I. $(COMMON_FLAGS)
54
55SRCS += example_numberwrapper.c
56EXTRA_FILES += example_numberwrapper.eo
57GENERATED += example_numberwrapper.eo.h example_numberwrapper.eo.c $(numberwrapper_lib_name)
58
59# CSharp examples
60
61SRCS += \
62EoInherit01.cs \
63FunctionPointer01.cs
64
65EXTRA_PROGRAMS += \
66EoInherit01.exe \
67FunctionPointer01.exe
68
69example_numberwrapper.eo.cs: example_numberwrapper.eo
70 $(AM_V_EOLMONO) \
71 $(EOLIAN_MONO) $(EOLIAN_FLAGS) $(EOLIAN_MONO_FLAGS) --dllimport $(numberwrapper_lib_name) -o $@ -r $(top_builddir)/src/bindings/mono/efl_mono/efl_libs.csv $<
72
73EoInherit01_exe_SOURCES = EoInherit01.cs
74EoInherit01_srcs = $(EoInherit01_exe_SOURCES) example_numberwrapper.eo.cs
75EoInherit01.exe$(EXEEXT): $(EoInherit01_srcs) $(am_dirstamp) $(top_builddir)/src/lib/efl_mono/libefl_mono.dll$(EXEEXT) $(numberwrapper_lib_name)
76 @rm -f $@
77 $(AM_V_MCS) $(MCS) $(MCS_FLAGS) -r:$(abs_top_builddir)/src/lib/efl_mono/libefl_mono.dll$(EXEEXT) -out:$@ $(filter %.cs, $(^))
78
79$(abs_top_builddir)/EoInherit01.csproj: $(EoInherit01_srcs) $(am_dirstamp) $(numberwrapper_lib_name)
80 @rm -f $@
81 $(EFL_MONO_MSBUILD_GEN) $(MSBUILD_GEN_FLAGS) -o $@ -a EoInherit01.exe -r libefl_mono.dll -t exe $(patsubst %.cs,src/examples/efl_mono/%.cs,$(filter %.cs, $(^)))
82
83
84FunctionPointer01_exe_SOURCES = FunctionPointer01.cs
85FunctionPointer01_srcs = $(FunctionPointer01_exe_SOURCES) example_numberwrapper.eo.cs
86FunctionPointer01.exe$(EXEEXT): $(FunctionPointer01_srcs) $(am_dirstamp) $(top_builddir)/src/lib/efl_mono/libefl_mono.dll$(EXEEXT) $(numberwrapper_lib_name)
87 @rm -f $@
88 $(AM_V_MCS) $(MCS) $(MCS_FLAGS) -r:$(abs_top_builddir)/src/lib/efl_mono/libefl_mono.dll$(EXEEXT) -out:$@ $(filter %.cs, $(^))
89
90$(abs_top_builddir)/FunctionPointer01.csproj: $(FunctionPointer01_srcs) $(am_dirstamp) $(numberwrapper_lib_name)
91 @rm -f $@
92 $(EFL_MONO_MSBUILD_GEN) $(MSBUILD_GEN_FLAGS) -o $@ -a FunctionPointer01.exe -r libefl_mono.dll -t exe $(patsubst %.cs,src/examples/efl_mono/%.cs,$(filter %.cs, $(^)))
93
94msbuildcsprojs: $(abs_top_builddir)/EoInherit01.csproj $(abs_top_builddir)/FunctionPointer01.csproj
95
96GENERATED += example_numberwrapper.eo.cs
97
98
99# Finishing
100
101EXTRA_DIST = $(EXTRA_FILES)
102
103CLEANFILES += $(GENERATED)
104
105examples: $(EXTRA_PROGRAMS)
106
107clean-local:
108 rm -f $(EXTRA_PROGRAMS) $(GENERATED)
109
110install-examples:
111 $(MKDIR_P) $(DESTDIR)$(datadir)/efl_mono/examples
112 cd $(srcdir) && $(install_sh_DATA) -c $(SRCS) $(EXTRA_FILES) $(DESTDIR)$(datadir)/efl_mono/examples
113
114uninstall-local:
115 for f in $(SRCS) $(EXTRA_FILES); do \
116 rm -f $(DESTDIR)$(datadir)/efl_mono/examples/$$f ; \
117 done
118
119if ALWAYS_BUILD_EXAMPLES
120noinst_PROGRAMS = $(EXTRA_PROGRAMS)
121endif
122
123endif
diff --git a/src/examples/efl_mono/example_numberwrapper.c b/src/examples/efl_mono/example_numberwrapper.c
new file mode 100644
index 0000000..f80dee6
--- /dev/null
+++ b/src/examples/efl_mono/example_numberwrapper.c
@@ -0,0 +1,87 @@
1
2#ifdef HAVE_CONFIG_H
3#include "config.h"
4#endif
5
6#include <Eo.h>
7
8#undef EOAPI
9#undef EAPI
10#define EOAPI EAPI EAPI_WEAK
11
12#ifdef _WIN32
13# ifdef EFL_EO_BUILD
14# ifdef DLL_EXPORT
15# define EAPI __declspec(dllexport)
16# else
17# define EAPI
18# endif /* ! DLL_EXPORT */
19# else
20# define EAPI __declspec(dllimport)
21# endif /* ! EFL_EO_BUILD */
22#else
23# ifdef __GNUC__
24# if __GNUC__ >= 4
25# define EAPI __attribute__ ((visibility("default")))
26# else
27# define EAPI
28# endif
29# else
30# define EAPI
31# endif
32#endif /* ! _WIN32 */
33
34#include "example_numberwrapper.eo.h"
35
36
37typedef struct Example_Numberwrapper_Data
38{
39 int number;
40 NumberCb cb;
41 void *cb_data;
42 Eina_Free_Cb free_cb;
43} Example_Numberwrapper_Data;
44
45// ##################### //
46// Example.Numberwrapper //
47// ##################### //
48
49
50void _example_numberwrapper_number_set(EINA_UNUSED Eo *obj, Example_Numberwrapper_Data *pd, int n)
51{
52 pd->number = n;
53}
54
55int _example_numberwrapper_number_get(EINA_UNUSED Eo *obj, Example_Numberwrapper_Data *pd)
56{
57 return pd->number;
58}
59
60
61void _example_numberwrapper_number_callback_set(EINA_UNUSED Eo *obj, Example_Numberwrapper_Data *pd, void *cb_data, NumberCb cb, Eina_Free_Cb cb_free_cb)
62{
63 if (pd->free_cb)
64 pd->free_cb(pd->cb_data);
65
66 pd->cb = cb;
67 pd->cb_data = cb_data;
68 pd->free_cb = cb_free_cb;
69}
70
71
72int _example_numberwrapper_callback_call(EINA_UNUSED Eo *obj, Example_Numberwrapper_Data *pd)
73{
74 if (!pd->cb)
75 {
76 static Eina_Error no_cb_err = 0;
77 if (!no_cb_err)
78 no_cb_err = eina_error_msg_static_register("Trying to call with no callback set");
79 eina_error_set(no_cb_err);
80 return -1;
81 }
82
83 return pd->cb(pd->cb_data, pd->number);
84}
85
86#include "example_numberwrapper.eo.c"
87
diff --git a/src/examples/efl_mono/example_numberwrapper.eo b/src/examples/efl_mono/example_numberwrapper.eo
new file mode 100644
index 0000000..85f2ce4
--- /dev/null
+++ b/src/examples/efl_mono/example_numberwrapper.eo
@@ -0,0 +1,30 @@
1function NumberCb {
2 params {
3 n: int;
4 }
5 return: int;
6};
7
8class Example.Numberwrapper (Efl.Object) {
9 methods {
10 @property number {
11 get {
12 }
13 set {
14 }
15 values {
16 n: int;
17 }
18 }
19
20 number_callback_set {
21 params {
22 cb: NumberCb;
23 }
24 }
25
26 callback_call {
27 return: int;
28 }
29 }
30}