From e499f84a2f4c049ba170cf028ad57d380152267e Mon Sep 17 00:00:00 2001
From: ulrich
Date: Tue, 23 Mar 2021 09:54:46 +0000
Subject: [PATCH] Code aufgeraeumt

---
 src/de/uhilger/avdirektor/handler/SeekHandler.java       |   24 ------------
 src/de/uhilger/avdirektor/Server.java                    |    6 +-
 src/de/uhilger/avdirektor/handler/PingHandler.java       |   17 ++++++--
 src/de/uhilger/avdirektor/handler/PlayHandler.java       |   47 ++++++++---------------
 src/de/uhilger/avdirektor/handler/StopServerHandler.java |    3 +
 src/de/uhilger/avdirektor/App.java                       |    6 ++
 6 files changed, 39 insertions(+), 64 deletions(-)

diff --git a/src/de/uhilger/avdirektor/App.java b/src/de/uhilger/avdirektor/App.java
index 9653669..873fa47 100644
--- a/src/de/uhilger/avdirektor/App.java
+++ b/src/de/uhilger/avdirektor/App.java
@@ -51,7 +51,11 @@
   public static final String SP_RUECK_600 = "rueck600";  
 
   public static final String OPT_LOCAL_AUDIO = "-o%20local";
-  public static final String OPT_HDMI_AUDIO = "-o hdmi";
+  public static final String OPT_HDMI_AUDIO = "-o%20hdmi";
+  
+  public static final String F_PLAY = "play";
+  public static final String F_SEEK = "seek";
+  public static final String F_PING = "ping";
   
   public static final String BLANK = " ";
   
diff --git a/src/de/uhilger/avdirektor/Server.java b/src/de/uhilger/avdirektor/Server.java
index 0fd929d..4635cec 100644
--- a/src/de/uhilger/avdirektor/Server.java
+++ b/src/de/uhilger/avdirektor/Server.java
@@ -34,11 +34,11 @@
     logger.info("Server starting on port " + port);
 
     HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
-    server.createContext("/avd/play", new PlayHandler("play"));
-    server.createContext("/avd/seek", new SeekHandler("seek"));
+    server.createContext("/avd/play", new PlayHandler(App.F_PLAY));
+    server.createContext("/avd/seek", new SeekHandler(App.F_SEEK));
     server.createContext("/avd/stop", new CmdHandler(App.CMD_STOP));
     server.createContext("/avd/pause", new CmdHandler(App.CMD_PAUSE_RESUME));
-    server.createContext("/avd/ping", new PingHandler());
+    server.createContext("/avd/ping", new PingHandler(App.F_PING));
     server.createContext("/avd/server/stop", new StopServerHandler());
     //server.setExecutor(null); // creates a default executor
     server.setExecutor(Executors.newFixedThreadPool(20));
diff --git a/src/de/uhilger/avdirektor/handler/PingHandler.java b/src/de/uhilger/avdirektor/handler/PingHandler.java
index b94fad4..219391c 100644
--- a/src/de/uhilger/avdirektor/handler/PingHandler.java
+++ b/src/de/uhilger/avdirektor/handler/PingHandler.java
@@ -6,9 +6,6 @@
 package de.uhilger.avdirektor.handler;
 
 import com.sun.net.httpserver.HttpExchange;
-import com.sun.net.httpserver.HttpHandler;
-import java.io.IOException;
-import java.io.OutputStream;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -16,10 +13,15 @@
  *
  * @author ulrich
  */
-public class PingHandler implements HttpHandler {
+public class PingHandler extends CmdHandler {
   
   private static final Logger logger = Logger.getLogger(PingHandler.class.getName());
 
+  public PingHandler(String cmd) {
+    super(cmd);
+  }
+
+  /*
   @Override
   public void handle(HttpExchange t) throws IOException {
     logger.log(Level.FINE, "RequestURI: {0}", t.getRequestURI().toString());
@@ -30,5 +32,12 @@
     os.write(response.getBytes());
     os.close();    
   }
+  */
+  
+  protected String process(HttpExchange t, String params) {
+    String antwort = cmd;
+    logger.log(Level.FINE, antwort);
+    return antwort;
+  }  
   
 }
diff --git a/src/de/uhilger/avdirektor/handler/PlayHandler.java b/src/de/uhilger/avdirektor/handler/PlayHandler.java
index 62d3f14..3a8db5d 100644
--- a/src/de/uhilger/avdirektor/handler/PlayHandler.java
+++ b/src/de/uhilger/avdirektor/handler/PlayHandler.java
@@ -9,6 +9,22 @@
 import java.util.logging.Logger;
 
 /**
+ * Play
+ * 
+ * rpi4-az:9090/avd/play?titel=/Filme/S/sound_city.m4v&th=60&ti=60&o=local
+ * 
+ *  OMXPlayer.abspielenMitParameternUndRueckmeldung(
+ *    String urlStr, String parameter, String meldeUrlStr, String token)
+ *
+ *  Parameter des Aufrufs play als query (th threshold, ti timeout)
+ *
+ *  ?titel=/Filme/S/sound_city.m4v
+ *  &ti=60
+ *  &th=60
+ *  &o=local|hdmi|both
+ *  &r=http://uhilger.de/mc/api/usw
+ *
+ *  r muss ganz wegbleiben, wenn keine Rueckmeldung gewuescht ist
  * 
  * @author ulrich
  */
@@ -19,37 +35,6 @@
   public PlayHandler(String cmd) {
     super(cmd);
   }
-
-  /*
-    rpi4-az:9090/avd/play?titel=/Filme/S/sound_city.m4v&th=60&ti=60&o=local
-  
-    OMXPlayer.abspielenMitParameternUndRueckmeldung(
-      String urlStr, String parameter, String meldeUrlStr, String token)
-  
-    Parameter des Aufrufs play als query (th threshold, ti timeout)
-  
-    ?titel=/Filme/S/sound_city.m4v
-    &ti=60
-    &th=60
-    &o=local|hdmi|both
-    &r=http://uhilger.de/mc/api/usw
-  
-    r muss ganz wegbleiben, wenn keine Rueckmeldung gewuescht ist
-
-  */
-  /*
-  @Override
-  public void handle(HttpExchange t) throws IOException {
-    logger.log(Level.FINE, "RequestURI: {0}", t.getRequestURI().toString());
-    
-    StringBuilder params = buildParams(t);
-    
-    String antwort = abspielenMitParameternUndRueckmeldung( 
-            getParam(map, "titel"), params.toString(), getParam(map, "r"), "1");    
-    
-    sendResponse(t, "play", antwort);
-  }
-  */
 
   @Override
   protected String process(HttpExchange t, String params) {
diff --git a/src/de/uhilger/avdirektor/handler/SeekHandler.java b/src/de/uhilger/avdirektor/handler/SeekHandler.java
index 4261681..2fbf20c 100644
--- a/src/de/uhilger/avdirektor/handler/SeekHandler.java
+++ b/src/de/uhilger/avdirektor/handler/SeekHandler.java
@@ -1,10 +1,6 @@
 package de.uhilger.avdirektor.handler;
 
 import com.sun.net.httpserver.HttpExchange;
-import com.sun.net.httpserver.HttpHandler;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -20,26 +16,6 @@
     super(cmd);
   }
 
-  /*
-  @Override
-  public void handle(HttpExchange t) throws IOException {
-    logger.log(Level.FINE, "RequestURI: {0}", t.getRequestURI().toString());
-    
-    StringBuilder params = super.buildParams(t);
-    params.append(" --pos ");
-    params.append(getParam(map, "p"));
-    
-    String antwort = abspielenMitParameternUndRueckmeldung( 
-            getParam(map, "titel"), params.toString(), getParam(map, "r"), "1");    
-    
-    String response = getResponseString(map, "play", antwort);
-    t.sendResponseHeaders(200, response.length());
-    OutputStream os = t.getResponseBody();
-    os.write(response.getBytes());
-    os.close();    
-  }
-  */
-  
   @Override
   protected String process(HttpExchange t, String params) {
     String antwort = abspielenMitParameternUndRueckmeldung( 
diff --git a/src/de/uhilger/avdirektor/handler/StopServerHandler.java b/src/de/uhilger/avdirektor/handler/StopServerHandler.java
index 44c4bd6..8954035 100644
--- a/src/de/uhilger/avdirektor/handler/StopServerHandler.java
+++ b/src/de/uhilger/avdirektor/handler/StopServerHandler.java
@@ -11,11 +11,12 @@
  *
  * @author ulrich
  */
-public class StopServerHandler implements HttpHandler {
+public class StopServerHandler extends OMXPlayer implements HttpHandler {
 
   @Override
   public void handle(HttpExchange exchange) throws IOException {
     Logger.getLogger(StopServerHandler.class.getName()).info(exchange.getRequestURI().toString());    
+    this.kommando(App.CMD_STOP);
     String response = "Server stopped";
     exchange.sendResponseHeaders(200, response.length());
     OutputStream os = exchange.getResponseBody();

--
Gitblit v1.9.3