Create new callback types for uninterruptible callbacks. 96/13796/4
Vincent COUVERT [Wed, 19 Feb 2014 15:55:52 +0000 (16:55 +0100)]
Change-Id: I8875dc839ce9e606772c9d766adc1bbb1463b676

scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/graphicObject/CallBack.java
scilab/modules/graphics/src/c/getHandleProperty/set_callback_type_property.c
scilab/modules/gui/src/java/org/scilab/modules/gui/events/callback/CommonCallBack.java
scilab/modules/gui/src/java/org/scilab/modules/gui/events/callback/ScilabCallBack.java

index 0054c53..0c2e082 100644 (file)
@@ -29,6 +29,7 @@ public class CallBack {
      * Scilab instruction command type constant
      */
     public static final int SCILAB_INSTRUCTION = 0;
+    public static final int SCILAB_NOT_INTERRUPTIBLE_INSTRUCTION = 10;
     /**
      * C or Fortran function type constant
      */
@@ -37,6 +38,7 @@ public class CallBack {
      * Scilab function type constant
      */
     public static final int SCILAB_FUNCTION = 2;
+    public static final int SCILAB_NOT_INTERRUPTIBLE_FUNCTION = 12;
     /**
      * Scilab function type constant (not trapped by scilab event listeners)
      */
index 4fd1189..5e3f068 100644 (file)
@@ -49,7 +49,7 @@ int set_callback_type_property(void* _pvCtx, int iObjUID, void* _pvData, int val
     callbackType = (int)((double*)_pvData)[0];
 
     /* Check the value */
-    if (callbackType < -1 || callbackType > 2)
+    if ((callbackType < -1 || callbackType > 2) && callbackType != 10 && callbackType != 12)
     {
         Scierror(999, _("Wrong value for '%s' property: %d, %d, %d or %d expected.\n"), "callback_type", -1, 0, 1, 2);
         return SET_PROPERTY_ERROR;
index f7e16d1..fb4798f 100644 (file)
@@ -73,6 +73,10 @@ public abstract class CommonCallBack extends AbstractAction {
             case CallBack.SCILAB_OUT_OF_XCLICK_AND_XGETMOUSE :
                 callback = ScilabCallBack.createOutOfXclickAndXgetmouse(command);
                 break;
+            case CallBack.SCILAB_NOT_INTERRUPTIBLE_FUNCTION:
+            case CallBack.SCILAB_NOT_INTERRUPTIBLE_INSTRUCTION:
+                callback = ScilabCallBack.create(command, false);
+                break;
             default:
                 callback = ScilabCallBack.create(command);
                 break;
index 79f643d..0341e1b 100644 (file)
@@ -27,6 +27,8 @@ public abstract class ScilabCallBack extends CommonCallBack {
 
     private static final long serialVersionUID = -4923246233703990342L;
 
+    private boolean isInterruptible = true;
+
     /**
      * Constructor
      * @param command : the command to execute.
@@ -35,6 +37,10 @@ public abstract class ScilabCallBack extends CommonCallBack {
         super(command, CallBack.UNTYPED);
     }
 
+    private ScilabCallBack(String command, boolean isInterruptible) {
+        super(command, CallBack.UNTYPED);
+        this.isInterruptible = isInterruptible;
+    }
     /**
      * Callback Factory to easily create a callback
      * just like in scilab.
@@ -42,14 +48,28 @@ public abstract class ScilabCallBack extends CommonCallBack {
      * @return a usable Scilab callback
      */
     public static ScilabCallBack create(String command) {
-        return (new ScilabCallBack(command) {
+        return create(command, true);
+    }
+
+    /**
+     * Callback Factory to easily create a callback
+     * just like in scilab.
+     * @param command : the command to execute.
+     * @return a usable Scilab callback
+     */
+    public static ScilabCallBack create(String command, boolean isInterruptible) {
+        return (new ScilabCallBack(command, isInterruptible) {
 
             private static final long serialVersionUID = -7286803341046313407L;
 
             public void callBack() {
                 Thread launchMe = new Thread() {
                     public void run() {
-                        InterpreterManagement.putCommandInScilabQueue(getCommand());
+                        if (isInterruptible()) {
+                            InterpreterManagement.putCommandInScilabQueue(getCommand());
+                        } else {
+                            InterpreterManagement.requestScilabExec(getCommand());
+                        }
                     }
                 };
                 launchMe.start();
@@ -57,6 +77,10 @@ public abstract class ScilabCallBack extends CommonCallBack {
         });
     }
 
+    boolean isInterruptible() {
+        return isInterruptible;
+    }
+
     /**
      * Callback Factory to easily create a callback
      * just like in scilab.