summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYeongjong Lee <yj34.lee@samsung.com>2019-11-11 11:33:03 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2019-11-12 10:17:25 -0300
commit77c1777ca2a9594e04b9b2bac1fc241fdff68445 (patch)
treed55b1bda957ebe599a67d632ac53770cad019862
parent73494aa71cb5d69092999036eee60b8b4f94ecc5 (diff)
mono: reduce duplicated event code
Summary: Introduction GetInternalEventCallback function to reduce duplicated event code. Test Plan: ninja test Reviewers: lauromoura Reviewed By: lauromoura Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D10638
-rw-r--r--src/bin/eolian_mono/eolian/mono/events.hh37
-rw-r--r--src/bindings/mono/eo_mono/EoWrapper.cs38
2 files changed, 49 insertions, 26 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/events.hh b/src/bin/eolian_mono/eolian/mono/events.hh
index 8ca0c76..e6a7857 100644
--- a/src/bin/eolian_mono/eolian/mono/events.hh
+++ b/src/bin/eolian_mono/eolian/mono/events.hh
@@ -37,7 +37,7 @@ struct unpack_event_args_visitor
37 typedef bool result_type; 37 typedef bool result_type;
38 bool operator()(grammar::attributes::regular_type_def const& regular) const 38 bool operator()(grammar::attributes::regular_type_def const& regular) const
39 { 39 {
40 std::string const& arg = "evt.Info"; 40 std::string const& arg = "info";
41 std::string arg_type = name_helpers::type_full_managed_name(regular); 41 std::string arg_type = name_helpers::type_full_managed_name(regular);
42 42
43 if (regular.is_struct()) 43 if (regular.is_struct())
@@ -45,7 +45,7 @@ struct unpack_event_args_visitor
45 // Structs are usually passed by pointer to events, like having a ptr<> modifier 45 // Structs are usually passed by pointer to events, like having a ptr<> modifier
46 // Uses implicit conversion from IntPtr 46 // Uses implicit conversion from IntPtr
47 return as_generator( 47 return as_generator(
48 " evt.Info" 48 " info"
49 ).generate(sink, attributes::unused, *context); 49 ).generate(sink, attributes::unused, *context);
50 } 50 }
51 else if (type.is_ptr) 51 else if (type.is_ptr)
@@ -121,17 +121,17 @@ struct unpack_event_args_visitor
121 // Type defined in Eo is passed here. (e.g. enum type defined in Eo) 121 // Type defined in Eo is passed here. (e.g. enum type defined in Eo)
122 // Uses conversion from IntPtr with type casting to the given type. 122 // Uses conversion from IntPtr with type casting to the given type.
123 return as_generator( 123 return as_generator(
124 " (" << arg_type << ")evt.Info" 124 " (" << arg_type << ")info"
125 ).generate(sink, attributes::unused, *context); 125 ).generate(sink, attributes::unused, *context);
126 } 126 }
127 } 127 }
128 bool operator()(grammar::attributes::klass_name const& cls) const 128 bool operator()(grammar::attributes::klass_name const& cls) const
129 { 129 {
130 return as_generator("(Efl.Eo.Globals.CreateWrapperFor(evt.Info) as " + name_helpers::klass_full_concrete_name(cls) + ")").generate(sink, attributes::unused, *context); 130 return as_generator("(Efl.Eo.Globals.CreateWrapperFor(info) as " + name_helpers::klass_full_concrete_name(cls) + ")").generate(sink, attributes::unused, *context);
131 } 131 }
132 bool operator()(attributes::complex_type_def const&) const 132 bool operator()(attributes::complex_type_def const&) const
133 { 133 {
134 return as_generator("new " << eolian_mono::type << "(evt.Info, false, false)").generate(sink, type, *context); 134 return as_generator("new " << eolian_mono::type << "(info, false, false)").generate(sink, type, *context);
135 } 135 }
136}; 136};
137 137
@@ -411,8 +411,8 @@ struct event_definition_generator
411 411
412 auto sub_context = change_indentation(indent.inc().inc(), context); 412 auto sub_context = change_indentation(indent.inc().inc(), context);
413 413
414 if (!as_generator(wrapper_args_type << " args = new " << wrapper_args_type << "();\n" 414 if (!as_generator(", info => new " << wrapper_args_type << "{ "
415 << scope_tab(6) << "args.arg = ").generate(arg_initializer_sink, attributes::unused, context)) 415 << "arg = ").generate(arg_initializer_sink, attributes::unused, context))
416 return false; 416 return false;
417 if (!(*etype).original_type.visit(unpack_event_args_visitor<decltype(arg_initializer_sink), decltype(sub_context)>{arg_initializer_sink, &sub_context, *etype})) 417 if (!(*etype).original_type.visit(unpack_event_args_visitor<decltype(arg_initializer_sink), decltype(sub_context)>{arg_initializer_sink, &sub_context, *etype}))
418 return false; 418 return false;
@@ -420,7 +420,7 @@ struct event_definition_generator
420 if (!(*etype).original_type.visit(pack_event_info_and_call_visitor<decltype(event_call_site_sink), decltype(sub_context)>{event_call_site_sink, &sub_context, *etype})) 420 if (!(*etype).original_type.visit(pack_event_info_and_call_visitor<decltype(event_call_site_sink), decltype(sub_context)>{event_call_site_sink, &sub_context, *etype}))
421 return false; 421 return false;
422 422
423 arg_initializer += ";\n"; 423 arg_initializer += " }";
424 424
425 event_args = arg_initializer; 425 event_args = arg_initializer;
426 } 426 }
@@ -540,24 +540,9 @@ struct event_definition_generator
540 return as_generator( 540 return as_generator(
541 scope_tab << "{\n" 541 scope_tab << "{\n"
542 << scope_tab << scope_tab << "add\n" 542 << scope_tab << scope_tab << "add\n"
543 << scope_tab << scope_tab << "{\n" 543 << scope_tab << scope_tab << "{\n"//evt.type.is_engaged()
544 << scope_tab << scope_tab << scope_tab << "Efl.EventCb callerCb = (IntPtr data, ref Efl.Event.NativeStruct evt) =>\n" 544 << scope_tab << scope_tab << scope_tab << "Efl.EventCb callerCb = GetInternalEventCallback(value"
545 << scope_tab << scope_tab << scope_tab << "{\n" 545 << (evt.type.is_engaged() ? event_args : "") << ");\n"
546 << scope_tab << scope_tab << scope_tab << scope_tab << "var obj = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data).Target;\n"
547 << scope_tab << scope_tab << scope_tab << scope_tab << "if (obj != null)\n"
548 << scope_tab << scope_tab << scope_tab << scope_tab << "{\n"
549 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << event_args
550 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "try\n"
551 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "{\n"
552 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "value?.Invoke(obj, args);\n"
553 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "}\n"
554 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "catch (Exception e)\n"
555 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "{\n"
556 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "Eina.Log.Error(e.ToString());\n"
557 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);\n"
558 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "}\n"
559 << scope_tab << scope_tab << scope_tab << scope_tab << "}\n"
560 << scope_tab << scope_tab << scope_tab << "};\n\n"
561 << scope_tab << scope_tab << scope_tab << "string key = \"_" << upper_c_name << "\";\n" 546 << scope_tab << scope_tab << scope_tab << "string key = \"_" << upper_c_name << "\";\n"
562 << scope_tab << scope_tab << scope_tab << "AddNativeEventHandler(" << library_name << ", key, callerCb, value);\n" 547 << scope_tab << scope_tab << scope_tab << "AddNativeEventHandler(" << library_name << ", key, callerCb, value);\n"
563 << scope_tab << scope_tab << "}\n\n" 548 << scope_tab << scope_tab << "}\n\n"
diff --git a/src/bindings/mono/eo_mono/EoWrapper.cs b/src/bindings/mono/eo_mono/EoWrapper.cs
index 4209fa7..0ab80e5 100644
--- a/src/bindings/mono/eo_mono/EoWrapper.cs
+++ b/src/bindings/mono/eo_mono/EoWrapper.cs
@@ -325,6 +325,44 @@ public abstract class EoWrapper : IWrapper, IDisposable
325 } 325 }
326 } 326 }
327 } 327 }
328 internal Efl.EventCb GetInternalEventCallback<T>(EventHandler<T> handler, Func<IntPtr, T> createArgsInstance) where T:EventArgs
329 {
330 return (IntPtr data, ref Efl.Event.NativeStruct evt) =>
331 {
332 var obj = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data).Target;
333 if (obj != null)
334 {
335 try
336 {
337 handler?.Invoke(obj, createArgsInstance(evt.Info));
338 }
339 catch (Exception e)
340 {
341 Eina.Log.Error(e.ToString());
342 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
343 }
344 }
345 };
346 }
347 internal Efl.EventCb GetInternalEventCallback(EventHandler handler)
348 {
349 return (IntPtr data, ref Efl.Event.NativeStruct evt) =>
350 {
351 var obj = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data).Target;
352 if (obj != null)
353 {
354 try
355 {
356 handler?.Invoke(obj, EventArgs.Empty);
357 }
358 catch (Exception e)
359 {
360 Eina.Log.Error(e.ToString());
361 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
362 }
363 }
364 };
365 }
328 366
329 private static void OwnershipUniqueCallback(IntPtr data, ref Efl.Event.NativeStruct evt) 367 private static void OwnershipUniqueCallback(IntPtr data, ref Efl.Event.NativeStruct evt)
330 { 368 {