commit | author | age
|
60719c
|
1 |
/* |
U |
2 |
AV-Direktor - Control OMXPlayer on Raspberry Pi via HTTP |
|
3 |
Copyright (C) 2021 Ulrich Hilger |
|
4 |
|
|
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 |
*/ |
|
18 |
|
229976
|
19 |
package de.uhilger.calypso; |
8e2038
|
20 |
|
U |
21 |
import com.sun.net.httpserver.HttpServer; |
229976
|
22 |
import de.uhilger.calypso.handler.CmdHandler; |
U |
23 |
import de.uhilger.calypso.handler.FileHandler; |
|
24 |
import de.uhilger.calypso.handler.LogHandler; |
|
25 |
import de.uhilger.calypso.handler.OMXPlayer; |
|
26 |
import de.uhilger.calypso.handler.PingHandler; |
|
27 |
import de.uhilger.calypso.handler.PlayHandler; |
|
28 |
import de.uhilger.calypso.handler.PlayOnHandler; |
|
29 |
import de.uhilger.calypso.handler.SeekHandler; |
|
30 |
import de.uhilger.calypso.handler.StopServerHandler; |
8e2038
|
31 |
import java.io.IOException; |
U |
32 |
import java.util.logging.Logger; |
|
33 |
import java.net.InetSocketAddress; |
cd1557
|
34 |
import java.util.concurrent.Executors; |
8e2038
|
35 |
|
U |
36 |
/** |
|
37 |
* |
|
38 |
* @author ulrich |
|
39 |
*/ |
|
40 |
public class Server { |
|
41 |
|
|
42 |
private static final Logger logger = Logger.getLogger(Server.class.getName()); |
|
43 |
|
|
44 |
private int port; |
|
45 |
|
c2c1fd
|
46 |
private String contextName; |
U |
47 |
|
8e2038
|
48 |
public Server(int port) { |
U |
49 |
this.port = port; |
|
50 |
} |
|
51 |
|
|
52 |
public void setPort(int port) { |
|
53 |
this.port = port; |
|
54 |
} |
|
55 |
|
c2c1fd
|
56 |
/** |
U |
57 |
* |
|
58 |
* @param contextName e.g. '/calypso' or '/cal' |
|
59 |
*/ |
|
60 |
public void setContextName(String contextName) { |
|
61 |
this.contextName = contextName; |
|
62 |
} |
|
63 |
|
8e2038
|
64 |
public void start() throws IOException { |
U |
65 |
logger.info("Server starting on port " + port); |
0c8d27
|
66 |
|
8e2038
|
67 |
HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); |
c2c1fd
|
68 |
server.createContext(contextName + "/play", new PlayHandler(OMXPlayer.F_PLAY)); |
U |
69 |
server.createContext(contextName + "/seek", new SeekHandler(OMXPlayer.F_SEEK)); |
|
70 |
server.createContext(contextName + "/stop", new CmdHandler(OMXPlayer.CMD_STOP)); |
|
71 |
server.createContext(contextName + "/pause", new CmdHandler(OMXPlayer.CMD_PAUSE_RESUME)); |
|
72 |
server.createContext(contextName + "/ping", new PingHandler(OMXPlayer.F_PING)); |
|
73 |
server.createContext(contextName + "/server/stop", new StopServerHandler()); |
|
74 |
server.createContext(contextName + "/log", new LogHandler()); |
|
75 |
server.createContext(contextName + "/playon", new PlayOnHandler(OMXPlayer.F_PLAY_ON)); |
|
76 |
server.createContext(contextName + "/ui", new FileHandler(App.getInitParameter(App.IP_WWW_DATA))); |
cd1557
|
77 |
//server.setExecutor(null); // creates a default executor |
U |
78 |
server.setExecutor(Executors.newFixedThreadPool(20)); |
8e2038
|
79 |
server.start(); |
cfe367
|
80 |
} |
8e2038
|
81 |
|
U |
82 |
} |