commit | author | age
|
60719c
|
1 |
/* |
933ccd
|
2 |
Calypso - Media Player Remote Control via HTTP for Raspberry Pi |
U |
3 |
Copyright (C) 2021-2023 Ulrich Hilger |
60719c
|
4 |
|
U |
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU Affero General Public License as |
|
7 |
published by the Free Software Foundation, either version 3 of the |
|
8 |
License, or (at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU Affero General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU Affero General Public License |
|
16 |
along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
17 |
*/ |
8e2038
|
18 |
|
929228
|
19 |
package de.uhilger.calypso.neu; |
8e2038
|
20 |
|
U |
21 |
import java.util.logging.Logger; |
|
22 |
import java.util.logging.Level; |
|
23 |
import java.util.List; |
|
24 |
import java.util.ArrayList; |
|
25 |
import java.util.Iterator; |
|
26 |
|
|
27 |
public class MeldeThread extends Thread { |
|
28 |
|
|
29 |
private static final Logger logger = Logger.getLogger(MeldeThread.class.getName()); |
|
30 |
|
|
31 |
private Process omxplayer; |
|
32 |
private int exitValue; |
|
33 |
private List<ProzessLauscher> lauscher = new ArrayList<>(); |
|
34 |
private String meldeUrlStr; |
|
35 |
|
|
36 |
public void setProcess(Process p) { |
|
37 |
this.omxplayer = p; |
|
38 |
} |
|
39 |
|
|
40 |
public int getExitValue() { |
|
41 |
return exitValue; |
|
42 |
} |
|
43 |
|
|
44 |
public void setMeldeUrl(String meldeUrlStr) { |
|
45 |
this.meldeUrlStr = meldeUrlStr; |
|
46 |
} |
|
47 |
|
929228
|
48 |
/** |
U |
49 |
* ausfuehren des Threads |
|
50 |
*/ |
|
51 |
@Override |
8e2038
|
52 |
public void run() { |
U |
53 |
try { |
|
54 |
exitValue = omxplayer.waitFor(); |
|
55 |
prozessBeendetMelden(); |
929228
|
56 |
lauscher.clear(); |
U |
57 |
lauscher = null; |
|
58 |
} catch(InterruptedException ex) { |
8e2038
|
59 |
logger.log(Level.FINE, ex.getMessage(), ex); |
U |
60 |
} finally { |
|
61 |
aufraeumen(); |
|
62 |
} |
|
63 |
} |
|
64 |
|
|
65 |
private void aufraeumen() { |
|
66 |
lauscher.clear(); |
|
67 |
lauscher = null; |
|
68 |
} |
|
69 |
|
|
70 |
public void lauscherHinzufuegen(ProzessLauscher l) { |
|
71 |
lauscher.add(l); |
|
72 |
} |
|
73 |
|
|
74 |
public void lauscherEntfernen(ProzessLauscher l) { |
|
75 |
lauscher.remove(l); |
|
76 |
} |
|
77 |
|
|
78 |
private void prozessBeendetMelden() { |
82594d
|
79 |
logger.log(Level.FINER, |
U |
80 |
"Alle Lauscher werden ueber beendeten Abspielprozess verstaendigt.."); |
8e2038
|
81 |
Iterator<ProzessLauscher> i = lauscher.iterator(); |
U |
82 |
while(i.hasNext()) { |
|
83 |
ProzessLauscher l = i.next(); |
|
84 |
l.prozessBeendet(meldeUrlStr); |
|
85 |
} |
|
86 |
} |
|
87 |
|
|
88 |
} |