update server to auto-restart when files are changed
[fleet.git] / src / edu / berkeley / fleet / fpga / Server.java
index a3a4099..03b0442 100644 (file)
@@ -7,12 +7,21 @@ import java.util.*;
 
 public class Server {
 
+    static long jarFileTime = 0;
+    static long bitFileTime = 0;
+    static {
+        try {
+            jarFileTime = new File("fleet.jar").lastModified();
+            bitFileTime = new File("build/fpga/main.bit").lastModified();
+        } catch (Exception e) { throw new RuntimeException(e); }
+    }
+
     public static ServerSocket ss;
     public static void main(String[] args) throws Exception {
         System.err.println("programming...");
         Process proc = Runtime.getRuntime().exec(new String[] {
-                "/afs/megacz.com/work/ml410/program.sh",
-                "/afs/megacz.com/work/ml410/main.bit"
+                "misc/program.sh",
+                "build/fpga/main.bit"
             });
         BufferedReader br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
         String str = null;
@@ -25,6 +34,23 @@ public class Server {
             return;
         }
         System.err.println("done programming.");
+        new Thread() {
+            public void run() {
+                try {
+                    while(true) {
+                        Thread.sleep(500);
+                        if (jarFileTime != new File("fleet.jar").lastModified()) {
+                            System.err.println("jarfile modified; exiting...");
+                            System.exit(0);
+                        }
+                        if (bitFileTime != new File("build/fpga/main.bit").lastModified()) {
+                            System.err.println("bitfile modified; exiting...");
+                            System.exit(0);
+                        }
+                    }
+                } catch (Exception e) { throw new RuntimeException(e); }
+            }
+        }.start();
         ss = new ServerSocket(3133);
         while(true) {
             try {