summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2017-06-19 21:26:59 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2017-07-13 18:25:44 -0300
commit2165f370b0d6c032e939a150c775cbd9b921acb3 (patch)
tree3565f597c8901b1440612674713833efe1b378e9
parentc7d377efd3f7612c8eb89c0ce0b4da29978665ca (diff)
mono: Support error handling on events
If an exception occurs in a managed callback, the exception is caught and the error reported to the stderr throught eina.Log.Error. An eina error is set to be raised when the code comes back to the managed side.
-rw-r--r--src/bin/eolian_mono/eolian/mono/klass.hh18
-rw-r--r--src/tests/efl_mono/Errors.cs21
2 files changed, 35 insertions, 4 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/klass.hh b/src/bin/eolian_mono/eolian/mono/klass.hh
index 3bcdaf028a..135e61c2bb 100644
--- a/src/bin/eolian_mono/eolian/mono/klass.hh
+++ b/src/bin/eolian_mono/eolian/mono/klass.hh
@@ -479,7 +479,7 @@ struct klass
479 return true; 479 return true;
480 480
481 if (!as_generator(scope_tab << "private readonly object eventLock = new object();\n" 481 if (!as_generator(scope_tab << "private readonly object eventLock = new object();\n"
482 << scope_tab << "Dictionary<string, int> event_cb_count = new Dictionary<string, int>();\n") 482 << scope_tab << "private Dictionary<string, int> event_cb_count = new Dictionary<string, int>();\n")
483 .generate(sink, NULL, context)) 483 .generate(sink, NULL, context))
484 return false; 484 return false;
485 485
@@ -496,6 +496,7 @@ struct klass
496 << scope_tab << scope_tab << scope_tab << scope_tab << "eina.Log.Error(\"Failed to add event proxy for event ${key}\");\n" 496 << scope_tab << scope_tab << scope_tab << scope_tab << "eina.Log.Error(\"Failed to add event proxy for event ${key}\");\n"
497 << scope_tab << scope_tab << scope_tab << scope_tab << "return false;\n" 497 << scope_tab << scope_tab << scope_tab << scope_tab << "return false;\n"
498 << scope_tab << scope_tab << scope_tab << "}\n" 498 << scope_tab << scope_tab << scope_tab << "}\n"
499 << scope_tab << scope_tab << scope_tab << "eina.Error.RaiseIfOcurred();\n"
499 << scope_tab << scope_tab << "} \n" 500 << scope_tab << scope_tab << "} \n"
500 << scope_tab << scope_tab << "event_cb_count[key]++;\n" 501 << scope_tab << scope_tab << "event_cb_count[key]++;\n"
501 << scope_tab << scope_tab << "return true;\n" 502 << scope_tab << scope_tab << "return true;\n"
@@ -511,6 +512,7 @@ struct klass
511 << scope_tab << scope_tab << scope_tab << scope_tab << "eina.Log.Error(\"Failed to remove event proxy for event ${key}\");\n" 512 << scope_tab << scope_tab << scope_tab << scope_tab << "eina.Log.Error(\"Failed to remove event proxy for event ${key}\");\n"
512 << scope_tab << scope_tab << scope_tab << scope_tab << "return false;\n" 513 << scope_tab << scope_tab << scope_tab << scope_tab << "return false;\n"
513 << scope_tab << scope_tab << scope_tab << "}\n" 514 << scope_tab << scope_tab << scope_tab << "}\n"
515 << scope_tab << scope_tab << scope_tab << "eina.Error.RaiseIfOcurred();\n"
514 << scope_tab << scope_tab << "} else if (event_count == 0) {\n" 516 << scope_tab << scope_tab << "} else if (event_count == 0) {\n"
515 << scope_tab << scope_tab << scope_tab << "eina.Log.Error(\"Trying to remove proxy for event ${key} when there is nothing registered.\");\n" 517 << scope_tab << scope_tab << scope_tab << "eina.Log.Error(\"Trying to remove proxy for event ${key} when there is nothing registered.\");\n"
516 << scope_tab << scope_tab << scope_tab << "return false;\n" 518 << scope_tab << scope_tab << scope_tab << "return false;\n"
@@ -562,7 +564,12 @@ struct klass
562 << scope_tab << "public void on_" << event_name << "_NativeCallback(System.IntPtr data, ref efl.Event evt)\n" 564 << scope_tab << "public void on_" << event_name << "_NativeCallback(System.IntPtr data, ref efl.Event evt)\n"
563 << scope_tab << "{\n" 565 << scope_tab << "{\n"
564 << scope_tab << event_args 566 << scope_tab << event_args
565 << scope_tab << scope_tab << "On_" << event_name << "(args);\n" 567 << scope_tab << scope_tab << "try {\n"
568 << scope_tab << scope_tab << scope_tab << "On_" << event_name << "(args);\n"
569 << scope_tab << scope_tab << "} catch (Exception e) {\n"
570 << scope_tab << scope_tab << scope_tab << "eina.Log.Error(e.Message);\n"
571 << scope_tab << scope_tab << scope_tab << "eina.Error.Set(eina.Error.EFL_ERROR);\n"
572 << scope_tab << scope_tab << "}\n"
566 << scope_tab << "}\n" 573 << scope_tab << "}\n"
567 << scope_tab << "efl.Event_Cb evt_" << event_name << "_delegate;\n" 574 << scope_tab << "efl.Event_Cb evt_" << event_name << "_delegate;\n"
568 << scope_tab << "event EventHandler" << wrapper_args_template << " " << cls.cxx_name << "." << upper_name << "{\n") 575 << scope_tab << "event EventHandler" << wrapper_args_template << " " << cls.cxx_name << "." << upper_name << "{\n")
@@ -644,7 +651,12 @@ struct klass
644 << scope_tab << "protected void on_" << wrapper_evt_name << "_NativeCallback(System.IntPtr data, ref efl.Event evt)" 651 << scope_tab << "protected void on_" << wrapper_evt_name << "_NativeCallback(System.IntPtr data, ref efl.Event evt)"
645 << scope_tab << "{\n" 652 << scope_tab << "{\n"
646 << scope_tab << event_args 653 << scope_tab << event_args
647 << scope_tab << scope_tab << "On_" << wrapper_evt_name << "(args);\n" 654 << scope_tab << scope_tab << "try {\n"
655 << scope_tab << scope_tab << scope_tab << "On_" << wrapper_evt_name << "(args);\n"
656 << scope_tab << scope_tab << "} catch (Exception e) {\n"
657 << scope_tab << scope_tab << scope_tab << "eina.Log.Error(e.Message);\n"
658 << scope_tab << scope_tab << scope_tab << "eina.Error.Set(eina.Error.EFL_ERROR);\n"
659 << scope_tab << scope_tab << "}\n"
648 << scope_tab << "}\n" 660 << scope_tab << "}\n"
649 << scope_tab << "event EventHandler" << wrapper_args_template << " " << *(lower_case[string] << ".") << klass.cxx_name << ".") 661 << scope_tab << "event EventHandler" << wrapper_args_template << " " << *(lower_case[string] << ".") << klass.cxx_name << ".")
650 .generate(sink, escape_namespace(klass.namespaces), context)) 662 .generate(sink, escape_namespace(klass.namespaces), context))
diff --git a/src/tests/efl_mono/Errors.cs b/src/tests/efl_mono/Errors.cs
index 042e4ae0e4..c8c05a7afa 100644
--- a/src/tests/efl_mono/Errors.cs
+++ b/src/tests/efl_mono/Errors.cs
@@ -94,6 +94,25 @@ class TestEolianError
94 } 94 }
95 95
96 // events 96 // events
97 // virtual callbacks 97 class Listener
98 {
99 public bool called = false;
100 public void callback(object sender, EventArgs e) {
101 throw (new CustomException("Event exception"));
102 }
103 public void another_callback(object sender, EventArgs e) {}
104 }
105
106 public static void eina_error_event_raise_exception()
107 {
108 // An event whose managed delegate generates an exception
109 // must set an eina_error so it can be reported back to
110 // the managed code
111 efl.Loop loop = new efl.LoopConcrete();
112 Listener listener = new Listener();
113 loop.CALLBACK_ADD += listener.callback;
114
115 Test.AssertRaises<efl.EflException>(() => loop.IDLE += listener.another_callback);
116 }
98} 117}
99} 118}