Commit | Line | Data |
---|---|---|
e42573a0 | 1 | package be.nikiroo.fanfix.library; |
b0e88ebd | 2 | |
b0e88ebd | 3 | import java.io.IOException; |
68e2c6d2 | 4 | import java.util.List; |
b0e88ebd | 5 | |
e42573a0 | 6 | import be.nikiroo.fanfix.Instance; |
b0e88ebd NR |
7 | import be.nikiroo.fanfix.data.MetaData; |
8 | import be.nikiroo.utils.Version; | |
9 | import be.nikiroo.utils.serial.ConnectActionServer; | |
10 | import be.nikiroo.utils.serial.Server; | |
11 | ||
12 | public class RemoteLibraryServer extends Server { | |
13 | ||
14 | public RemoteLibraryServer(int port) throws IOException { | |
15 | super(Version.getCurrentVersion(), port, true); | |
16 | } | |
17 | ||
18 | @Override | |
19 | protected Object onRequest(ConnectActionServer action, | |
20 | Version clientVersion, Object data) throws Exception { | |
21 | String command = null; | |
22 | String args = null; | |
23 | if (data instanceof String) { | |
24 | command = (String) data; | |
25 | int pos = command.indexOf(" "); | |
26 | if (pos >= 0) { | |
27 | args = command.substring(pos + 1); | |
28 | command = command.substring(0, pos); | |
29 | } | |
30 | } | |
31 | ||
32 | System.out.println(String.format("COMMAND: [%s], ARGS: [%s]", command, | |
33 | args)); | |
34 | ||
35 | if (command != null) { | |
36 | if (command.equals("GET_METADATA")) { | |
37 | if (args != null && args.equals("*")) { | |
68e2c6d2 NR |
38 | List<MetaData> metas = Instance.getLibrary().getMetas(null); |
39 | return metas.toArray(new MetaData[] {}); | |
b0e88ebd NR |
40 | } |
41 | } else if (command.equals("GET_STORY")) { | |
42 | if (args != null) { | |
43 | return Instance.getLibrary().getStory(args, null); | |
44 | } | |
45 | } | |
46 | } | |
47 | ||
48 | return null; | |
49 | } | |
50 | } |