1 package be
.nikiroo
.fanfix
.library
;
3 import java
.io
.IOException
;
6 import be
.nikiroo
.fanfix
.Instance
;
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
;
13 * Create a new remote server that will listen for order on the given port.
15 * The available commands are:
17 * <li>GET_METADATA *: will get the metadata of all the stories in the library</li>
18 * <li>GET_STORY [luid]: will return the given story if it exists (or NULL if
24 public class RemoteLibraryServer
extends Server
{
27 * Create a new remote server (will not be active until
28 * {@link RemoteLibraryServer#start()} is called).
31 * the port to listen on
34 * in case of I/O error
36 public RemoteLibraryServer(int port
) throws IOException
{
41 protected Object
onRequest(ConnectActionServer action
,
42 Version clientVersion
, Object data
) throws Exception
{
43 String command
= null;
45 if (data
instanceof String
) {
46 command
= (String
) data
;
47 int pos
= command
.indexOf(" ");
49 args
= command
.substring(pos
+ 1);
50 command
= command
.substring(0, pos
);
54 System
.out
.println(String
.format("COMMAND: [%s], ARGS: [%s]", command
,
57 // TODO: progress (+send name + %age info back to client)
59 if ("GET_METADATA".equals(command
)) {
60 if (args
!= null && args
.equals("*")) {
61 List
<MetaData
> metas
= Instance
.getLibrary().getMetas(null);
62 return metas
.toArray(new MetaData
[] {});
64 } else if ("GET_STORY".equals(command
)) {
66 return Instance
.getLibrary().getStory(args
, null);
68 } else if ("GET_COVER".equals(command
)) {
70 return Instance
.getLibrary().getCover(args
);