summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bin/eolian_mono/eolian/mono/events.hh40
-rw-r--r--src/bindings/mono/eo_mono/EoWrapper.cs86
2 files changed, 63 insertions, 63 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/events.hh b/src/bin/eolian_mono/eolian/mono/events.hh
index 6c5f12e..2e4ca32 100644
--- a/src/bin/eolian_mono/eolian/mono/events.hh
+++ b/src/bin/eolian_mono/eolian/mono/events.hh
@@ -447,36 +447,30 @@ struct event_definition_generator
447 scope_tab << "{\n" 447 scope_tab << "{\n"
448 << scope_tab << scope_tab << "add\n" 448 << scope_tab << scope_tab << "add\n"
449 << scope_tab << scope_tab << "{\n" 449 << scope_tab << scope_tab << "{\n"
450 << scope_tab << scope_tab << scope_tab << "lock (eflBindingEventLock)\n" 450 << scope_tab << scope_tab << scope_tab << "Efl.EventCb callerCb = (IntPtr data, ref Efl.Event.NativeStruct evt) =>\n"
451 << scope_tab << scope_tab << scope_tab << "{\n" 451 << scope_tab << scope_tab << scope_tab << "{\n"
452 << scope_tab << scope_tab << scope_tab << scope_tab << "Efl.EventCb callerCb = (IntPtr data, ref Efl.Event.NativeStruct evt) =>\n" 452 << scope_tab << scope_tab << scope_tab << scope_tab << "var obj = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data).Target;\n"
453 << scope_tab << scope_tab << scope_tab << scope_tab << "if (obj != null)\n"
453 << scope_tab << scope_tab << scope_tab << scope_tab << "{\n" 454 << scope_tab << scope_tab << scope_tab << scope_tab << "{\n"
454 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "var obj = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data).Target;\n" 455 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << event_args
455 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "if (obj != null)\n" 456 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "try\n"
456 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "{\n" 457 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "{\n"
457 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << event_args 458 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "value?.Invoke(obj, args);\n"
458 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "try\n"
459 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "{\n"
460 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "value?.Invoke(obj, args);\n"
461 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "}\n"
462 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "catch (Exception e)\n"
463 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "{\n"
464 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "Eina.Log.Error(e.ToString());\n"
465 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);\n"
466 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "}\n"
467 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "}\n" 459 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "}\n"
468 << scope_tab << scope_tab << scope_tab << scope_tab << "};\n\n" 460 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "catch (Exception e)\n"
469 << scope_tab << scope_tab << scope_tab << scope_tab << "string key = \"_" << upper_c_name << "\";\n" 461 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "{\n"
470 << scope_tab << scope_tab << scope_tab << scope_tab << "AddNativeEventHandler(" << library_name << ", key, callerCb, value);\n" 462 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "Eina.Log.Error(e.ToString());\n"
471 << scope_tab << scope_tab << scope_tab << "}\n" // End of lock block 463 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);\n"
464 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "}\n"
465 << scope_tab << scope_tab << scope_tab << scope_tab << "}\n"
466 << scope_tab << scope_tab << scope_tab << "};\n\n"
467 << scope_tab << scope_tab << scope_tab << "string key = \"_" << upper_c_name << "\";\n"
468 << scope_tab << scope_tab << scope_tab << "AddNativeEventHandler(" << library_name << ", key, callerCb, value);\n"
472 << scope_tab << scope_tab << "}\n\n" 469 << scope_tab << scope_tab << "}\n\n"
473 << scope_tab << scope_tab << "remove\n" 470 << scope_tab << scope_tab << "remove\n"
474 << scope_tab << scope_tab << "{\n" 471 << scope_tab << scope_tab << "{\n"
475 << scope_tab << scope_tab << scope_tab << "lock (eflBindingEventLock)\n" 472 << scope_tab << scope_tab << scope_tab << "string key = \"_" << upper_c_name << "\";\n"
476 << scope_tab << scope_tab << scope_tab << "{\n" 473 << scope_tab << scope_tab << scope_tab << "RemoveNativeEventHandler(" << library_name << ", key, value);\n"
477 << scope_tab << scope_tab << scope_tab << scope_tab << "string key = \"_" << upper_c_name << "\";\n"
478 << scope_tab << scope_tab << scope_tab << scope_tab << "RemoveNativeEventHandler(" << library_name << ", key, value);\n"
479 << scope_tab << scope_tab << scope_tab << "}\n" // End of lock block
480 << scope_tab << scope_tab << "}\n" 474 << scope_tab << scope_tab << "}\n"
481 << scope_tab << "}\n\n" 475 << scope_tab << "}\n\n"
482 ).generate(sink, attributes::unused, context); 476 ).generate(sink, attributes::unused, context);
diff --git a/src/bindings/mono/eo_mono/EoWrapper.cs b/src/bindings/mono/eo_mono/EoWrapper.cs
index 79d597c..eae4eea 100644
--- a/src/bindings/mono/eo_mono/EoWrapper.cs
+++ b/src/bindings/mono/eo_mono/EoWrapper.cs
@@ -20,7 +20,7 @@ namespace Eo
20public abstract class EoWrapper : IWrapper, IDisposable 20public abstract class EoWrapper : IWrapper, IDisposable
21{ 21{
22 /// <summary>Object used to synchronize access to EFL events.</summary> 22 /// <summary>Object used to synchronize access to EFL events.</summary>
23 protected readonly object eflBindingEventLock = new object(); 23 private readonly object eflBindingEventLock = new object();
24 private bool generated = true; 24 private bool generated = true;
25 private System.IntPtr handle = IntPtr.Zero; 25 private System.IntPtr handle = IntPtr.Zero;
26 26
@@ -215,30 +215,33 @@ public abstract class EoWrapper : IWrapper, IDisposable
215 /// <param name="evtDelegate">Managed delegate that will be called by evtCaller on event raising.</param> 215 /// <param name="evtDelegate">Managed delegate that will be called by evtCaller on event raising.</param>
216 protected void AddNativeEventHandler(string lib, string key, Efl.EventCb evtCaller, object evtDelegate) 216 protected void AddNativeEventHandler(string lib, string key, Efl.EventCb evtCaller, object evtDelegate)
217 { 217 {
218 IntPtr desc = Efl.EventDescription.GetNative(lib, key); 218 lock (eflBindingEventLock)
219 if (desc == IntPtr.Zero)
220 { 219 {
221 Eina.Log.Error($"Failed to get native event {key}"); 220 IntPtr desc = Efl.EventDescription.GetNative(lib, key);
222 return; 221 if (desc == IntPtr.Zero)
223 } 222 {
223 Eina.Log.Error($"Failed to get native event {key}");
224 return;
225 }
224 226
225 var wsPtr = Efl.Eo.Globals.efl_mono_wrapper_supervisor_get(handle); 227 var wsPtr = Efl.Eo.Globals.efl_mono_wrapper_supervisor_get(handle);
226 var ws = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(wsPtr); 228 var ws = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(wsPtr);
227 if (ws.EoEvents.ContainsKey((desc, evtDelegate))) 229 if (ws.EoEvents.ContainsKey((desc, evtDelegate)))
228 { 230 {
229 Eina.Log.Warning($"Event proxy for event {key} already registered!"); 231 Eina.Log.Warning($"Event proxy for event {key} already registered!");
230 return; 232 return;
231 } 233 }
232 234
233 IntPtr evtCallerPtr = Marshal.GetFunctionPointerForDelegate(evtCaller); 235 IntPtr evtCallerPtr = Marshal.GetFunctionPointerForDelegate(evtCaller);
234 if (!Efl.Eo.Globals.efl_event_callback_priority_add(handle, desc, 0, evtCallerPtr, wsPtr)) 236 if (!Efl.Eo.Globals.efl_event_callback_priority_add(handle, desc, 0, evtCallerPtr, wsPtr))
235 { 237 {
236 Eina.Log.Error($"Failed to add event proxy for event {key}"); 238 Eina.Log.Error($"Failed to add event proxy for event {key}");
237 return; 239 return;
238 } 240 }
239 241
240 ws.EoEvents[(desc, evtDelegate)] = (evtCallerPtr, evtCaller); 242 ws.EoEvents[(desc, evtDelegate)] = (evtCallerPtr, evtCaller);
241 Eina.Error.RaiseIfUnhandledException(); 243 Eina.Error.RaiseIfUnhandledException();
244 }
242 } 245 }
243 246
244 /// <summary>Removes the given event handler for the given event. For internal use only.</summary> 247 /// <summary>Removes the given event handler for the given event. For internal use only.</summary>
@@ -247,30 +250,33 @@ public abstract class EoWrapper : IWrapper, IDisposable
247 /// <param name="evtDelegate">The delegate to be removed.</param> 250 /// <param name="evtDelegate">The delegate to be removed.</param>
248 protected void RemoveNativeEventHandler(string lib, string key, object evtDelegate) 251 protected void RemoveNativeEventHandler(string lib, string key, object evtDelegate)
249 { 252 {
250 IntPtr desc = Efl.EventDescription.GetNative(lib, key); 253 lock (eflBindingEventLock)
251 if (desc == IntPtr.Zero)
252 { 254 {
253 Eina.Log.Error($"Failed to get native event {key}"); 255 IntPtr desc = Efl.EventDescription.GetNative(lib, key);
254 return; 256 if (desc == IntPtr.Zero)
255 }
256
257 var wsPtr = Efl.Eo.Globals.efl_mono_wrapper_supervisor_get(handle);
258 var ws = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(wsPtr);
259 var evtPair = (desc, evtDelegate);
260 if (ws.EoEvents.TryGetValue(evtPair, out var caller))
261 {
262 if (!Efl.Eo.Globals.efl_event_callback_del(handle, desc, caller.evtCallerPtr, wsPtr))
263 { 257 {
264 Eina.Log.Error($"Failed to remove event proxy for event {key}"); 258 Eina.Log.Error($"Failed to get native event {key}");
265 return; 259 return;
266 } 260 }
267 261
268 ws.EoEvents.Remove(evtPair); 262 var wsPtr = Efl.Eo.Globals.efl_mono_wrapper_supervisor_get(handle);
269 Eina.Error.RaiseIfUnhandledException(); 263 var ws = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(wsPtr);
270 } 264 var evtPair = (desc, evtDelegate);
271 else 265 if (ws.EoEvents.TryGetValue(evtPair, out var caller))
272 { 266 {
273 Eina.Log.Error($"Trying to remove proxy for event {key} when it is not registered."); 267 if (!Efl.Eo.Globals.efl_event_callback_del(handle, desc, caller.evtCallerPtr, wsPtr))
268 {
269 Eina.Log.Error($"Failed to remove event proxy for event {key}");
270 return;
271 }
272
273 ws.EoEvents.Remove(evtPair);
274 Eina.Error.RaiseIfUnhandledException();
275 }
276 else
277 {
278 Eina.Log.Error($"Trying to remove proxy for event {key} when it is not registered.");
279 }
274 } 280 }
275 } 281 }
276 282