Преглед на файлове

more remote work. and some gradle magic

LH преди 6 години
родител
ревизия
eca7ede419

+ 8 - 0
iZpl/build.gradle

@@ -149,3 +149,11 @@ dependencies{
     }
     compile(project(':izpl-shared'))
 }
+
+
+    configurations {
+        apistub
+    }
+    artifacts {
+        apistub  apiJar
+    }

+ 96 - 6
iZplPlugins/JukeBox/build.gradle

@@ -1,9 +1,84 @@
 apply plugin:'java'
-task distZip(dependsOn: 'jar') {
-	//NO-OPtask als redirect
-}
 
+apply plugin: 'application'
+apply from: "$rootDir/utils/IO.gradle"
+
+version = '0.10.0.0-snapshot'
+mainClassName = 'de.nplusc.izc.izpl.plugins.jukebox.StandaloneMain'
 
+//task distZip(dependsOn: 'jar') {
+//	//NO-OPtask als redirect
+//}
+
+startScripts << { 
+  defaultJvmOpts = ["-Dlog4j.skipJansi=false"] // fahr zur hölle Log5J
+  def startScriptDir = outputDir.getAbsolutePath()
+  def winStartScript = startScriptDir + "/" + applicationName + ".bat"
+  def winStartScriptCopy = startScriptDir + "/" + applicationName + "c.bat"
+  def linuxStartScript = startScriptDir + "/" + applicationName
+  def overwriteExistingFile = true
+  copyFile(winStartScript, winStartScriptCopy, overwriteExistingFile)
+
+  //:init
+  
+  modifyFile(winStartScript) {
+    // javaw.exe doesn't have a console
+    if(it.contains("java.exe")){
+      return it.replace("java.exe", "javaw.exe")
+    }
+    // Command that launches the app
+    else if(it.startsWith("\"%JAVA_EXE%\" %DEFAULT_JVM_OPTS%")){
+      return "start \"\" /b " + it
+    }
+    else if (it.startsWith("set DEFAULT_JVM_OPTS="))
+    {
+        return it+" -Dlog4j.skipJansi=false"
+    }
+    else if(it.startsWith(":init"))
+    {
+        //HACK
+        return it+"\n"+"set VLC_PLUGIN_PATH=%APP_HOME%\\lib\\vlcbinaries\\plugins"
+    }
+    // Leave the line unchanged
+    else{
+      return it
+    }
+  }
+  
+    modifyFile(linuxStartScript) {
+    if (it.startsWith("DEFAULT_JVM_OPTS=\"\""))
+    {
+        return "DEFAULT_JVM_OPTS=\"-Dlog4j.skipJansi=false\""
+    }
+    // Leave the line unchanged
+    else{
+      return it
+    }
+  }
+  
+  modifyFile(winStartScriptCopy) {
+    if(it.startsWith(":init"))
+    {
+    //HACK
+        return it+"\n"+"set VLC_PLUGIN_PATH=%APP_HOME%\\lib\\vlcbinaries\\plugins" 
+    }
+    else if (it.startsWith("set DEFAULT_JVM_OPTS="))
+    {
+        return it+" -Dlog4j.skipJansi=false"
+    }
+    // Leave the line unchanged
+    else{
+      return it
+    }
+  }
+}
+distZip {
+  // Include the additional start script
+  into(project.name+"-"+project.version+"/bin/"){
+    from(startScripts.outputDir)
+	include '*c.bat'
+  }
+}
 
 
 
@@ -11,9 +86,24 @@ compileJava.options.encoding = 'UTF-8'
 dependencies
 {
 	compile fileTree(dir: 'lib', include: '*.jar')
-	compile project(':iZpl')
-   
-
+	compile (project(path: ':iZpl', configuration: 'apistub')){
+        transitive = false
+        
+        // HACK for the light-mode standalone
+    }
+    compile(project(':ToolKit')) {
+        transitive = false
+    }
+    compile(project(':izpl-shared')){
+        transitive = false
+    }
+    
+    compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.1'
+	compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.1'
+	compile group: 'org.apache.logging.log4j', name: 'log4j-iostreams', version: '2.11.1'
+    compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.11.1'
+    compile group: 'org.apache.logging.log4j', name: 'log4j-jul', version: '2.11.1'
+    compile "org.yaml:snakeyaml:1.14"
 }
 
 

+ 4 - 3
iZplPlugins/JukeBox/src/main/java/de/nplusc/izc/izpl/plugins/jukebox/JukeBox.java

@@ -255,7 +255,7 @@ public class JukeBox extends javax.swing.JFrame implements UIPlugin,MouseListene
         }
         else
         {
-            l.info("Loaded as featurePlugin, delaying the init");
+            l.info("Loaded as featurePlugin or standalone, delaying the init");
         }
                
     }
@@ -518,7 +518,8 @@ public class JukeBox extends javax.swing.JFrame implements UIPlugin,MouseListene
     {
         if(param!=null&&!param.equals(""))
         {
-            
+            jukeboxBackend = new RemoteBackend(param, this);
+            jukeboxBackend.initBackend();
         }
         else
         {
@@ -535,7 +536,7 @@ public class JukeBox extends javax.swing.JFrame implements UIPlugin,MouseListene
     @Override
     public void openUserInterface()
     {
-        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+        EventQueue.invokeLater(()->this.setVisible(true));
     }
 
     @Override

+ 3 - 3
iZplPlugins/JukeBox/src/main/java/de/nplusc/izc/izpl/plugins/jukebox/JukeboxClientHandler.java

@@ -71,9 +71,9 @@ public class JukeboxClientHandler
                     Object packet = new Yaml().load(request);
                     if(packet instanceof Packet)
                     {
-                        l.info("PACKET received");
+                        l.trace("PACKET received");
                         l.trace(request);
-                        //API.getDispatcher().handleEvent((Packet)packet,this);
+                        parsePacket((Packet) packet);
                     }
                     else
                     {
@@ -178,7 +178,7 @@ public class JukeboxClientHandler
                 List<String> titles = srv.getScheduledTracks();
                 HashMap<String,Object> data = new HashMap<>();
                 Packet response = new Packet();
-                data.put("RESPONSE", "TITLES");
+                data.put("RESPONSE", "QUEUE");
                 data.put("DATA", titles);
                 response.setData(data);
                 respondToLinkedClient(response);

+ 161 - 8
iZplPlugins/JukeBox/src/main/java/de/nplusc/izc/izpl/plugins/jukebox/RemoteBackend.java

@@ -18,8 +18,17 @@ package de.nplusc.izc.izpl.plugins.jukebox;
 
 import de.nplusc.izc.iZpl.API.shared.InvalidPlayListFileException;
 import de.nplusc.izc.iZpl.API.shared.networking.Packet;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
+import java.net.Socket;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.yaml.snakeyaml.Yaml;
 
 /**
  *
@@ -27,7 +36,19 @@ import java.util.List;
  */
 public class RemoteBackend implements Backend
 {
-
+    Socket sck;
+    private static final Logger l = LogManager.getLogger();
+    private final String targetIP;
+    private String returnMsg = "";
+    private PlaybackStatusUpdater frontend;
+    private String[] titles = {};
+    private List<String> schedule = new ArrayList<>();
+    public RemoteBackend(String target, PlaybackStatusUpdater frontend)
+    {
+        targetIP = target;
+        this.frontend = frontend;
+    }
+    
     @Override
     public void play()
     {
@@ -49,7 +70,81 @@ public class RemoteBackend implements Backend
     @Override
     public void initBackend()
     {
-        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+        try {
+            sck=new Socket(targetIP, JukeBox.JUKEBOX_PORT);
+            try {
+                BufferedReader r = new BufferedReader(new InputStreamReader(sck.getInputStream()));
+                PrintStream out = new PrintStream(sck.getOutputStream());
+                Thread t = new Thread(()->{
+                    while(sck.isConnected())
+                    {
+                        String request = "";
+                        try {
+                            String ln = r.readLine();
+                            l.trace("packet line = "+ln);
+                            while(ln!=null&&!ln.equals("---"))
+                            {
+                                request+=ln+"\n";
+                                
+                                ln=r.readLine();
+                            }
+                            if(ln==null)
+                            {
+                                l.warn("Null-Read");
+                                System.exit(0);
+                            }
+                            
+                        } catch (IOException ex) {
+                            l.warn("NETZAP");
+                            System.exit(0);
+                            break;
+                        }
+                        l.trace(request);
+                        Object packet = new Yaml().load(request);
+                        if(packet instanceof Packet)
+                        {
+                            
+                            l.trace("PACKET");
+                            dispatchResponse((Packet)packet);
+                        }
+                        else
+                        {
+                            //error();
+                        }
+                    }
+                });
+                t.setName("InputCruncher");
+                t.start();
+                Thread t2 = new Thread(()->{
+                    //System.out.println("Gefangen!");
+                    while(sck.isConnected())
+                    {
+                        synchronized(targetIP)
+                        {
+                            try {
+                                targetIP.wait();
+                            } catch (InterruptedException ex) {
+                            }
+                            l.trace("MSG sent");
+                            l.trace("PKT="+returnMsg);
+                            out.println(returnMsg);
+                            out.flush();
+                            returnMsg="";
+                        }
+                    }
+                    //System.out.println("Flucht ist zwecklos");
+                });
+                t2.setName("OutputCruncher");
+                t2.start();
+                
+            }
+            catch (IOException ex)
+            {}
+        } 
+        catch (IOException ex) 
+        {   
+            ex.printStackTrace();
+        }
     }
 
     @Override
@@ -74,14 +169,14 @@ public class RemoteBackend implements Backend
     public String[] getTitles() throws InvalidPlayListFileException
     {
         sendCommand("getTitles", null); //TODO
-        return null;
+        return titles; 
     }
 
     @Override
     public List<String> getScheduledTracks()
     {
         sendCommand("getScheduled", null); //TODO
-        return null;
+        return schedule;
     }
 
     @Override
@@ -90,15 +185,73 @@ public class RemoteBackend implements Backend
         APIWrapper.quickQuit();
     }
     
-    
+
     
     private void sendCommand(String action, String param)
     {
         HashMap<String,Object> data = new HashMap<>();
-        Packet response = new Packet();
+        Packet request = new Packet();
         data.put("COMMAND", "action");
         data.put("PARAM", param);
-        response.setData(data);
-                    
+        request.setData(data);
+        synchronized(targetIP)
+         {
+             System.out.println("POKE");
+             returnMsg=new Yaml().dump(request)+"\n---\n";
+             targetIP.notify();
+         }
+    }
+    
+    private void dispatchResponse(Packet p)
+    {
+        HashMap<String,Object> data = p.getData();
+        if(data.get("RESPONSE") !=null)
+        {
+            String respType = (String) data.get("RESPONSE");
+            
+            switch(respType)
+            {
+                case "UPDATE":
+                    if(data.get("TOPIC") != null)
+                    {
+                        String topic = (String) data.get("TOPIC");
+                        String param = (String) data.get("VALUE");
+                        switch(topic)
+                        {
+                            case "LENGTH":
+                                frontend.updateTrackLength(Integer.valueOf(param));
+                                break;
+                            case "TITLE":
+                                frontend.updateTrackTitle(topic);
+                                break;
+                            case "POSITION":
+                                frontend.updateCurrentPlaybackPosition(Integer.valueOf(param));
+                                break;
+                            case "TRACKS":
+                                sendCommand("getTitles", null); //TODO
+                                break;
+                            case "QUEUE":
+                                sendCommand("getScheduled", null); //TODO
+                                break;
+                            case "PLAYING":
+                                frontend.setPlayStatus(Boolean.valueOf(param));
+                                break;
+                        }
+                    }
+                    break;
+                case "TITLES":
+                    List<String> titles = (List<String>) data.get("DATA");
+                    this.titles = titles.toArray(this.titles);
+                    frontend.triggerTableRefresh();
+                    break;
+                case "QUEUE":
+                    schedule = (List<String>) data.get("DATA");
+                    frontend.triggerScheduleRefresh();
+                    break;
+            }
+            
+        }
+        
+        
     }
 }

+ 31 - 0
iZplPlugins/JukeBox/src/main/java/de/nplusc/izc/izpl/plugins/jukebox/StandaloneMain.java

@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2018 iZc
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package de.nplusc.izc.izpl.plugins.jukebox;
+
+/**
+ *
+ * @author iZc <nplusc.de>
+ */
+public class StandaloneMain
+{
+    public static void main(String[] args)
+    {
+        JukeBox jbx = new JukeBox();
+        jbx.parseParameter(args[0]);
+        jbx.openUserInterface();
+    }
+}