Fix DisposeQueue issue by using EventThreadCallback class 43/121743/3
authorUmar <m.umar@partner.samsung.com>
Tue, 28 Mar 2017 16:04:15 +0000 (17:04 +0100)
committerUmar <m.umar@partner.samsung.com>
Wed, 29 Mar 2017 14:58:28 +0000 (15:58 +0100)
Change-Id: I9266ff91c0a081333eb88283bca519f97c17826e

plugins/dali-swig/Makefile.am
plugins/dali-swig/SWIG/events/application-event.i
plugins/dali-swig/manual/cpp/callbackbase_wrap.cpp [deleted file]
plugins/dali-swig/manual/cpp/event-thread-callback-wrap.cpp [new file with mode: 0644]
plugins/dali-swig/manual/csharp/DisposeQueue.cs
plugins/dali-swig/manual/csharp/EventThreadCallback.cs [new file with mode: 0644]
plugins/dali-swig/manual/csharp/ManualPINVOKE.cs

index 2ed325240be0a4b7df9374f8582db81c9bc74718..526fc627cb877926267f9946d24706db78310459 100755 (executable)
@@ -23,8 +23,8 @@ if BUILD_MCS
 
 all-local: libNDalic.so NDali.dll
 
-libNDalic.so: automatic/cpp/dali_wrap.o manual/cpp/keyboard_focus_manager_wrap.o manual/cpp/view-wrapper-impl-wrap.o manual/cpp/callbackbase_wrap.o manual/cpp/devel-property-wrap.o
-       g++ -shared automatic/cpp/dali_wrap.o manual/cpp/keyboard_focus_manager_wrap.o manual/cpp/view-wrapper-impl-wrap.o manual/cpp/callbackbase_wrap.o manual/cpp/devel-property-wrap.o -o libNDalic.so $(DALICORE_LIBS) $(DALIADAPTOR_LIBS) $(DALITOOLKIT_LIBS)
+libNDalic.so: automatic/cpp/dali_wrap.o manual/cpp/keyboard_focus_manager_wrap.o manual/cpp/view-wrapper-impl-wrap.o manual/cpp/event-thread-callback-wrap.o manual/cpp/devel-property-wrap.o
+       g++ -shared automatic/cpp/dali_wrap.o manual/cpp/keyboard_focus_manager_wrap.o manual/cpp/view-wrapper-impl-wrap.o manual/cpp/event-thread-callback-wrap.o manual/cpp/devel-property-wrap.o -o libNDalic.so $(DALICORE_LIBS) $(DALIADAPTOR_LIBS) $(DALITOOLKIT_LIBS)
 
 automatic/cpp/dali_wrap.o: $(BUILT_SOURCES)
        g++ -c -fpic $(CXXFLAGS) $(DALICORE_CFLAGS) $(DALIADAPTOR_CFLAGS) $(DALITOOLKIT_CFLAGS) automatic/cpp/dali_wrap.cpp -o automatic/cpp/dali_wrap.o
@@ -35,8 +35,8 @@ manual/cpp/keyboard_focus_manager_wrap.o: $(BUILT_SOURCES)
 manual/cpp/view-wrapper-impl-wrap.o: $(BUILT_SOURCES)
        g++ -c -fpic $(CXXFLAGS) $(DALICORE_CFLAGS) $(DALIADAPTOR_CFLAGS) $(DALITOOLKIT_CFLAGS) manual/cpp/view-wrapper-impl-wrap.cpp -o manual/cpp/view-wrapper-impl-wrap.o
 
-manual/cpp/callbackbase_wrap.o: $(BUILT_SOURCES)
-       g++ -c -fpic $(CXXFLAGS) $(DALICORE_CFLAGS) $(DALIADAPTOR_CFLAGS) $(DALITOOLKIT_CFLAGS) manual/cpp/callbackbase_wrap.cpp -o manual/cpp/callbackbase_wrap.o
+manual/cpp/event-thread-callback-wrap.o: $(BUILT_SOURCES)
+       g++ -c -fpic $(CXXFLAGS) $(DALICORE_CFLAGS) $(DALIADAPTOR_CFLAGS) $(DALITOOLKIT_CFLAGS) manual/cpp/event-thread-callback-wrap.cpp -o manual/cpp/event-thread-callback-wrap.o
 
 manual/cpp/devel-property-wrap.o: $(BUILT_SOURCES)
        g++ -c -fpic $(CXXFLAGS) $(DALICORE_CFLAGS) $(DALIADAPTOR_CFLAGS) $(DALITOOLKIT_CFLAGS) manual/cpp/devel-property-wrap.cpp -o manual/cpp/devel-property-wrap.o
index 3db23f4bb4cf37823dbf88468367c893527ea509..3050ae7fafbf7d6562dc169f035ffb3bb17e6893 100644 (file)
     // Callback for Application InitSignal
     private void OnApplicationInit(IntPtr data)
     {
+      // Initialize DisposeQueue Singleton class. This is also required to create DisposeQueue on main thread.
+      DisposeQueue.Instance.Initialize();
+
       NUIApplicationInitEventArgs e = new NUIApplicationInitEventArgs();
 
       // Populate all members of "e" (NUIApplicationInitEventArgs) with real data
       return ret;
     }
 
-    public bool AddIdle(System.Delegate func) {
-      System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(func);
-      System.IntPtr ip2 = NDalicManualPINVOKE.MakeCallback(new System.Runtime.InteropServices.HandleRef(this, ip));
-
-      bool ret = NDalicPINVOKE.Application_AddIdle(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip2));
-
-      if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-      return ret;
-    }
-
     %}
     %enddef
 
diff --git a/plugins/dali-swig/manual/cpp/callbackbase_wrap.cpp b/plugins/dali-swig/manual/cpp/callbackbase_wrap.cpp
deleted file mode 100644 (file)
index 6b925d4..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef CSHARP_CALLBACK_BASE
-#define CSHARP_CALLBACK_BASE
-#endif
-
-#include "common.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-SWIGEXPORT void * SWIGSTDCALL CSharp_Dali_MakeCallback(void * jarg1) {
-  void * jresult ;
-  void (*arg1)(void) = (void (*)(void)) 0 ;
-  Dali::CallbackBase *result = 0 ;
-
-  arg1 = (void (*)(void))jarg1;
-  {
-    try {
-      result = (Dali::CallbackBase *)Dali::MakeCallback(arg1);
-    } catch (std::out_of_range& e) {
-      {
-        SWIG_CSharpException(SWIG_IndexError, const_cast<char*>(e.what())); return 0;
-      };
-    } catch (std::exception& e) {
-      {
-        SWIG_CSharpException(SWIG_RuntimeError, const_cast<char*>(e.what())); return 0;
-      };
-    } catch (...) {
-      {
-        SWIG_CSharpException(SWIG_UnknownError, "unknown error"); return 0;
-      };
-    }
-  }
-
-  jresult = (void *)result;
-
-  return jresult;
-}
-
-#ifdef __cplusplus
-}
-#endif
-
diff --git a/plugins/dali-swig/manual/cpp/event-thread-callback-wrap.cpp b/plugins/dali-swig/manual/cpp/event-thread-callback-wrap.cpp
new file mode 100644 (file)
index 0000000..736c697
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef CSHARP_EVENT_THREAD_CALLBACK
+#define CSHARP_EVENT_THREAD_CALLBACK
+#endif
+
+#include "common.h"
+#include <dali/devel-api/adaptor-framework/event-thread-callback.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (SWIGSTDCALL* SWIG_CallbackMakeCallback)(void);
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_Dali_new_EventThreadCallback(SWIG_CallbackMakeCallback callbackOnMakeCallback) {
+  void * jresult ;
+  void (*arg1)(void) = (void (*)(void)) 0 ;
+  Dali::EventThreadCallback *result = 0 ;
+
+  arg1 = (void (*)(void))callbackOnMakeCallback;
+  {
+    try {
+      result = (Dali::EventThreadCallback *)new Dali::EventThreadCallback((Dali::CallbackBase *)Dali::MakeCallback(arg1));
+    } catch (std::out_of_range& e) {
+      {
+        SWIG_CSharpException(SWIG_IndexError, const_cast<char*>(e.what())); return 0;
+      };
+    } catch (std::exception& e) {
+      {
+        SWIG_CSharpException(SWIG_RuntimeError, const_cast<char*>(e.what())); return 0;
+      };
+    } catch (...) {
+      {
+        SWIG_CSharpException(SWIG_UnknownError, "unknown error"); return 0;
+      };
+    }
+  }
+  jresult = (void *)result;
+  return jresult;
+}
+
+SWIGEXPORT void SWIGSTDCALL CSharp_Dali_delete_EventThreadCallback(void * jarg1) {
+  Dali::EventThreadCallback *arg1 = (Dali::EventThreadCallback *) 0 ;
+
+  arg1 = (Dali::EventThreadCallback *)jarg1;
+  {
+    try {
+      delete arg1;
+    } catch (std::out_of_range& e) {
+      {
+        SWIG_CSharpException(SWIG_IndexError, const_cast<char*>(e.what())); return ;
+      };
+    } catch (std::exception& e) {
+      {
+        SWIG_CSharpException(SWIG_RuntimeError, const_cast<char*>(e.what())); return ;
+      };
+    } catch (...) {
+      {
+        SWIG_CSharpException(SWIG_UnknownError, "unknown error"); return ;
+      };
+    }
+  }
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_Dali_EventThreadCallback_Trigger(void * jarg1) {
+  Dali::EventThreadCallback *arg1 = (Dali::EventThreadCallback *) 0 ;
+
+  arg1 = (Dali::EventThreadCallback *)jarg1;
+  {
+    try {
+      (arg1)->Trigger();
+    } catch (std::out_of_range& e) {
+      {
+        SWIG_CSharpException(SWIG_IndexError, const_cast<char*>(e.what())); return ;
+      };
+    } catch (std::exception& e) {
+      {
+        SWIG_CSharpException(SWIG_RuntimeError, const_cast<char*>(e.what())); return ;
+      };
+    } catch (...) {
+      {
+        SWIG_CSharpException(SWIG_UnknownError, "unknown error"); return ;
+      };
+    }
+  }
+}
+
+#ifdef __cplusplus
+}
+#endif //CSHARP_EVENT_THREAD_CALLBACK
+
index a62843bf161c10bc9363835d72900e65a4828d51..35acafd54ceda7b1e6d53d016ee6fb2a92e007e8 100644 (file)
@@ -12,19 +12,16 @@ using System.Collections.Generic;
 
 namespace Dali
 {
-
     public class DisposeQueue
     {
-        private static DisposeQueue _disposableQueue = new DisposeQueue();
+        private static readonly DisposeQueue _disposableQueue = new DisposeQueue();
         private List<IDisposable> _disposables = new List<IDisposable>();
         private Object _listLock = new object();
-        private delegate int ProcessDisposablesDelegate(IntPtr ptr);
-        private ProcessDisposablesDelegate _disposequeueProcessDisposablesDelegate;
+        private EventThreadCallback _eventThreadCallback;
+        private EventThreadCallback.CallbackDelegate _disposeQueueProcessDisposablesDelegate;
 
         private DisposeQueue()
         {
-          _disposequeueProcessDisposablesDelegate = new ProcessDisposablesDelegate(ProcessDisposables);
-          Application.Instance.AddIdle(_disposequeueProcessDisposablesDelegate);
         }
 
         ~DisposeQueue()
@@ -36,17 +33,25 @@ namespace Dali
             get { return _disposableQueue; }
         }
 
+        public void Initialize()
+        {
+            _disposeQueueProcessDisposablesDelegate = new EventThreadCallback.CallbackDelegate(ProcessDisposables);
+            _eventThreadCallback = new EventThreadCallback(_disposeQueueProcessDisposablesDelegate);
+        }
+
         public void Add(IDisposable disposable)
         {
-            lock(_listLock)
+            lock (_listLock)
             {
                 _disposables.Add(disposable);
             }
+
+            _eventThreadCallback.Trigger();
         }
 
-        private int ProcessDisposables(IntPtr ptr)
+        private void ProcessDisposables()
         {
-            lock(_listLock)
+            lock (_listLock)
             {
                 foreach (IDisposable disposable in _disposables)
                 {
@@ -54,7 +59,6 @@ namespace Dali
                 }
                 _disposables.Clear();
             }
-            return 0;
         }
     }
 }
diff --git a/plugins/dali-swig/manual/csharp/EventThreadCallback.cs b/plugins/dali-swig/manual/csharp/EventThreadCallback.cs
new file mode 100644 (file)
index 0000000..a9434a4
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+namespace Dali
+{
+
+    public class EventThreadCallback : global::System.IDisposable
+    {
+        private global::System.Runtime.InteropServices.HandleRef swigCPtr;
+        protected bool swigCMemOwn;
+        public delegate void CallbackDelegate();
+
+        internal EventThreadCallback(global::System.IntPtr cPtr, bool cMemoryOwn)
+        {
+            swigCMemOwn = cMemoryOwn;
+            swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
+        }
+
+        internal static global::System.Runtime.InteropServices.HandleRef getCPtr(EventThreadCallback obj)
+        {
+            return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
+        }
+
+        ~EventThreadCallback()
+        {
+            Dispose();
+        }
+
+        public virtual void Dispose()
+        {
+            lock (this)
+            {
+                if (swigCPtr.Handle != global::System.IntPtr.Zero)
+                {
+                    if (swigCMemOwn)
+                    {
+                        swigCMemOwn = false;
+                        NDalicManualPINVOKE.delete_EventThreadCallback(swigCPtr);
+                    }
+                    swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+                }
+                global::System.GC.SuppressFinalize(this);
+            }
+        }
+
+        public EventThreadCallback(CallbackDelegate func) : this(NDalicManualPINVOKE.new_EventThreadCallback(func), true)
+        {
+            if (NDalicPINVOKE.SWIGPendingException.Pending)
+                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        public void Trigger()
+        {
+            NDalicManualPINVOKE.EventThreadCallback_Trigger(swigCPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending)
+                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+    }
+
+}
index 669417488a1f16938c1cb99cf1d4c9f7f78c07a0..a7ce0a2dae2e4322131a0a537458de7b0bf07b5c 100755 (executable)
@@ -184,8 +184,14 @@ namespace Dali
         [global::System.Runtime.InteropServices.DllImport("NDalic", EntryPoint="CSharp_Dali_ViewWrapperImpl_ApplyThemeStyle")]
         public static extern void ViewWrapperImpl_ApplyThemeStyle(global::System.Runtime.InteropServices.HandleRef jarg1);
 
-        [global::System.Runtime.InteropServices.DllImport("NDalic", EntryPoint="CSharp_Dali_MakeCallback")]
-        public static extern global::System.IntPtr MakeCallback(global::System.Runtime.InteropServices.HandleRef jarg1);
+        [global::System.Runtime.InteropServices.DllImport("NDalic", EntryPoint="CSharp_Dali_new_EventThreadCallback")]
+        public static extern global::System.IntPtr new_EventThreadCallback(EventThreadCallback.CallbackDelegate delegate1);
+
+        [global::System.Runtime.InteropServices.DllImport("NDalic", EntryPoint="CSharp_Dali_delete_EventThreadCallback")]
+        public static extern void delete_EventThreadCallback(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+        [global::System.Runtime.InteropServices.DllImport("NDalic", EntryPoint="CSharp_Dali_EventThreadCallback_Trigger")]
+        public static extern void EventThreadCallback_Trigger(global::System.Runtime.InteropServices.HandleRef jarg1);
 
         [global::System.Runtime.InteropServices.DllImport("NDalic", EntryPoint="CSharp_Actor_Property_SIBLING_ORDER_get")]
         public static extern int Actor_Property_SIBLING_ORDER_get();