/* Calypso - Media Player Remote Control via HTTP for Raspberry Pi Copyright (C) 2021-2023 Ulrich Hilger This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero 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 Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package de.uhilger.calypso.neu; import java.util.logging.Logger; import java.util.logging.Level; import java.util.List; import java.util.ArrayList; import java.util.Iterator; public class MeldeThread extends Thread { private static final Logger logger = Logger.getLogger(MeldeThread.class.getName()); private Process omxplayer; private int exitValue; private List lauscher = new ArrayList<>(); private String meldeUrlStr; public void setProcess(Process p) { this.omxplayer = p; } public int getExitValue() { return exitValue; } public void setMeldeUrl(String meldeUrlStr) { this.meldeUrlStr = meldeUrlStr; } /** * ausfuehren des Threads */ @Override public void run() { try { exitValue = omxplayer.waitFor(); prozessBeendetMelden(); lauscher.clear(); lauscher = null; } catch(InterruptedException ex) { logger.log(Level.FINE, ex.getMessage(), ex); } finally { aufraeumen(); } } private void aufraeumen() { lauscher.clear(); lauscher = null; } public void lauscherHinzufuegen(ProzessLauscher l) { lauscher.add(l); } public void lauscherEntfernen(ProzessLauscher l) { lauscher.remove(l); } private void prozessBeendetMelden() { logger.log(Level.FINER, "Alle Lauscher werden ueber beendeten Abspielprozess verstaendigt.."); Iterator i = lauscher.iterator(); while(i.hasNext()) { ProzessLauscher l = i.next(); l.prozessBeendet(meldeUrlStr); } } }