/*
AV-Direktor - Control OMXPlayer on Raspberry Pi via HTTP
Copyright (C) 2021 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;
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;
}
public void run() {
try {
exitValue = omxplayer.waitFor();
prozessBeendetMelden();
} catch(Exception 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() {
Iterator i = lauscher.iterator();
while(i.hasNext()) {
ProzessLauscher l = i.next();
l.prozessBeendet(meldeUrlStr);
}
}
}