Anonymous avatar Anonymous committed a9551dd

Added presentation event, info and listener.

Comments (0)

Files changed (10)

src/org/lispdev/swank/ISwank.java

 
 import org.lispdev.swank.runnables.SwankDebugActivateRunnable;
 import org.lispdev.swank.runnables.SwankDebugReturnRunnable;
-import org.lispdev.swank.runnables.SwankPresentationEndRunnable;
-import org.lispdev.swank.runnables.SwankPresentationStartRunnable;
+import org.lispdev.swank.runnables.SwankPresentationRunnable;
 import org.lispdev.swank.runnables.SwankReadStringRunnable;
 import org.lispdev.swank.runnables.SwankRunnable;
 import org.lispdev.swank.runnables.SwankWriteStringRunnable;
   void addDebugReturnListener(SwankDebugReturnRunnable r);
   void addReadStringListener(SwankReadStringRunnable r);
   void addWriteStringListener(SwankWriteStringRunnable r);
-  void addPresentationStartListener(SwankPresentationStartRunnable r);
-  void addPresentationEndListener(SwankPresentationEndRunnable r);
+  void addPresentationListener(SwankPresentationRunnable r);
 
   /**
    * Remove listener

src/org/lispdev/swank/LispImplementation.java

 import org.lispdev.swank.infos.CompileStringInfo;
 import org.lispdev.swank.infos.CompileStringInfo.CompileMessage;
 import org.lispdev.swank.infos.DebugActivateInfo;
+import org.lispdev.swank.infos.WriteStringInfo;
 
 /**
  * Abstract Lisp Implementation class.
 
     return info;
   }
+
+  /*
+ <--(:write-string "\"abcde\"" :repl-result)
+
+ <--(:write-string "
+  ; in: LAMBDA NIL
+  ;     (SETF RES (READ-LINE))
+  ; ==>
+  ;   (SETQ RES (READ-LINE))
+  ;
+  ; caught WARNING:
+  ;   undefined variable: RES
+
+  ;
+  ; caught WARNING:
+  ;   This variable is undefined:
+  ;     RES
+  ;
+  ; compilation unit finished
+  ;   caught 2 WARNING conditions
+  ")
+
+   */
+  public WriteStringInfo getWriteString(LispNode n)
+  {
+    if( n == null || n.getParamsCount() < 2
+        || !n.get(0).value.equals(":write-string") )
+    {
+      Log.logError("Incorrect structure of write-string result: " +
+          String.valueOf(n));
+      return null;
+    }
+    WriteStringInfo res = new WriteStringInfo(n.get(1).value,
+        n.getParamsCount() > 2 && n.get(2).value.equals(":repl-result"));
+    return res;
+  }
 }

src/org/lispdev/swank/SwankInterface.java

 import org.lispdev.swank.runnables.SwankDebugActivateRunnable;
 import org.lispdev.swank.runnables.SwankDebugReturnRunnable;
 import org.lispdev.swank.runnables.SwankMacroExpandRunnable;
-import org.lispdev.swank.runnables.SwankPresentationEndRunnable;
-import org.lispdev.swank.runnables.SwankPresentationStartRunnable;
+import org.lispdev.swank.runnables.SwankPresentationRunnable;
 import org.lispdev.swank.runnables.SwankReadStringRunnable;
 import org.lispdev.swank.runnables.SwankRunnable;
 import org.lispdev.swank.runnables.SwankWriteStringRunnable;
     swank.addWriteStringListener(r);
   }
 
-  public void addPresentationStartListener(SwankPresentationStartRunnable r)
+  public void addPresentationListener(SwankPresentationRunnable r)
   {
-    swank.addPresentationStartListener(r);
-  }
-
-  public void addPresentationEndListener(SwankPresentationEndRunnable r)
-  {
-    swank.addPresentationEndListener(r);
+    swank.addPresentationListener(r);
   }
 
   public void removeListener(SwankRunnable r)

src/org/lispdev/swank/SwankInterfaceCore.java

 
 import org.eclipse.core.runtime.Assert;
 import org.eclipse.core.runtime.ListenerList;
+import org.lispdev.log.Log;
 import org.lispdev.swank.runnables.SwankDebugActivateRunnable;
 import org.lispdev.swank.runnables.SwankDebugReturnRunnable;
-import org.lispdev.swank.runnables.SwankPresentationEndRunnable;
-import org.lispdev.swank.runnables.SwankPresentationStartRunnable;
+import org.lispdev.swank.runnables.SwankPresentationRunnable;
 import org.lispdev.swank.runnables.SwankReadStringRunnable;
 import org.lispdev.swank.runnables.SwankRunnable;
 import org.lispdev.swank.runnables.SwankWriteStringRunnable;
     addListener(SwankEvent.WRITE_STRING, r);
   }
 
-  public void addPresentationStartListener(SwankPresentationStartRunnable r)
+  public void addPresentationListener(SwankPresentationRunnable r)
   {
     addListener(SwankEvent.PRESENTATION_START,r);
   }
 
-  public void addPresentationEndListener(SwankPresentationEndRunnable r)
-  {
-    addListener(SwankEvent.PRESENTATION_END, r);
-  }
-
   synchronized public void removeListener(SwankRunnable r)
   {
     for(ListenerList ll : listeners.values())
     }
   }
 
+  /**
+   * Assume that there are no nested presentations.
+   * Also assume that write string happens just once between
+   * presentation start and presentation end.
+   */
+  private String presentation = null;
+
   synchronized private void signalListeners(LispNode result, SwankEvent event)
   {
+    switch(event)
+    {
+      case PRESENTATION_START:
+        presentation = result.get(1).value;
+        return;
+      case PRESENTATION_END:
+        if( !result.get(1).value.equals(presentation) )
+        {
+          Log.logError("Presentation end is different from presentation start");
+        }
+        presentation = null;
+        return;
+      case WRITE_STRING:
+        if( presentation != null )
+        {
+          ListenerList ll = getListeners(SwankEvent.PRESENTATION_START);
+          if( ll == null )
+          {
+            return;
+          }
+
+          for(Object o : ll.getListeners())
+          {
+            SwankPresentationRunner runner =
+              new SwankPresentationRunner(result, presentation, event,
+                  (SwankPresentationRunnable)o);
+            runnableDriver.asyncExec(runner);
+          }
+          return;
+        }
+      default:
+    }
+
     ListenerList ll = getListeners(event);
     if( ll == null )
     {
       return;
     }
+
     for(Object o : ll.getListeners())
     {
       SwankRunner runner = new SwankRunner(result, event, (SwankRunnable)o);
   private static class SwankRunner implements Runnable
   {
     private final LispNode result;
-    private final SwankRunnable runnable;
+    protected final SwankRunnable runnable;
     private final SwankEvent event;
 
     public SwankRunner(LispNode result, SwankEvent event,
     }
   }
 
+  private static class SwankPresentationRunner extends SwankRunner
+  {
+    private final String id;
+
+    public SwankPresentationRunner(LispNode result, String presentation,
+        SwankEvent e, SwankPresentationRunnable r)
+    {
+      super(result,e,r);
+      id = presentation;
+    }
+
+    @Override
+    public void run()
+    {
+      synchronized(runnable)
+      {
+        ((SwankPresentationRunnable)runnable).setPresentation(id);
+        super.run();
+      }
+    }
+  }
+
   private class ListenerThread extends Thread
   {
     private BufferedReader in;

src/org/lispdev/swank/SwankInterfaceTest.java

 import org.lispdev.swank.runnables.SwankDebugActivateRunnable;
 import org.lispdev.swank.runnables.SwankDebugReturnRunnable;
 import org.lispdev.swank.runnables.SwankMacroExpandRunnable;
+import org.lispdev.swank.runnables.SwankPresentationRunnable;
 import org.lispdev.swank.runnables.SwankReadStringRunnable;
 import org.lispdev.swank.runnables.SwankRunnable;
-import org.lispdev.swank.runnables.SwankWriteStringRunnable;
 
 public class SwankInterfaceTest extends SwankInterface
 {
   public void test_sendEval()
   {
     final String[] res = new String[2];
-    final SwankWriteStringRunnable writeListener = new SwankWriteStringRunnable(si.getLispImplementation()){
+    final SwankPresentationRunnable writeListener = new SwankPresentationRunnable(si.getLispImplementation()){
       @Override
       public void run()
       {
         {
           if( res[i] == null )
           {
-            res[i] = result.getf(":write-string").value;
+            res[i] = getInfo().text;
             break;
           }
         }
       }
     };
-    si.swank.addWriteStringListener(writeListener);
+    si.swank.addPresentationListener(writeListener);
     final SwankRunnable callBack = new SwankRunnable(si.getLispImplementation()){
       @Override
       public void run()

src/org/lispdev/swank/infos/PresentationInfo.java

+package org.lispdev.swank.infos;
+
+public class PresentationInfo extends WriteStringInfo
+{
+  public final String id;
+
+  public PresentationInfo(String id, String text, boolean result)
+  {
+    super(text,result);
+    this.id = id;
+  }
+}

src/org/lispdev/swank/infos/WriteStringInfo.java

+package org.lispdev.swank.infos;
+
+public class WriteStringInfo
+{
+  public final String text;
+  /**
+   * is it repl-result or not
+   */
+  public final boolean result;
+
+  public WriteStringInfo(String text, boolean result)
+  {
+    this.text = text;
+    this.result = result;
+  }
+}

src/org/lispdev/swank/runnables/SwankPresentationEndRunnable.java

-package org.lispdev.swank.runnables;
-
-import org.lispdev.swank.LispImplementation;
-
-public abstract class SwankPresentationEndRunnable extends SwankRunnable
-{
-
-  public SwankPresentationEndRunnable(LispImplementation implementation)
-  {
-    super(implementation);
-  }
-
-  @Override
-  synchronized public Object getInfo()
-  {
-    // TODO Auto-generated method stub
-    return null;
-  }
-
-}

src/org/lispdev/swank/runnables/SwankPresentationRunnable.java

+package org.lispdev.swank.runnables;
+
+import org.lispdev.swank.LispImplementation;
+import org.lispdev.swank.infos.PresentationInfo;
+import org.lispdev.swank.infos.WriteStringInfo;
+
+public abstract class SwankPresentationRunnable extends SwankRunnable
+{
+  private String id;
+
+  public void setPresentation(String presentation)
+  {
+    this.id = presentation;
+  }
+
+  public SwankPresentationRunnable(LispImplementation implementation)
+  {
+    super(implementation);
+  }
+
+  @Override
+  synchronized public PresentationInfo getInfo()
+  {
+    WriteStringInfo tmp = implem.getWriteString(result);
+    PresentationInfo res = new PresentationInfo(id, tmp.text, tmp.result);
+    return res;
+  }
+}

src/org/lispdev/swank/runnables/SwankPresentationStartRunnable.java

-package org.lispdev.swank.runnables;
-
-import org.lispdev.swank.LispImplementation;
-
-public abstract class SwankPresentationStartRunnable extends SwankRunnable
-{
-
-  public SwankPresentationStartRunnable(LispImplementation implementation)
-  {
-    super(implementation);
-  }
-
-  @Override
-  synchronized public Object getInfo()
-  {
-    // TODO Auto-generated method stub
-    return null;
-  }
-
-}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.