From a85e807750081c6e77a7916ca4e79506b5a98537 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Sat, 25 Nov 2017 22:09:04 +0100 Subject: [PATCH] Prepare work on RemoteLibrary --- VERSION | 2 +- .../nikiroo/fanfix/library/RemoteLibrary.java | 24 ++++++---- .../fanfix/library/RemoteLibraryServer.java | 44 ++++++++++++++----- 3 files changed, 49 insertions(+), 21 deletions(-) diff --git a/VERSION b/VERSION index fdd3be6..8d067ce 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.6.2 +1.6.2-dev diff --git a/src/be/nikiroo/fanfix/library/RemoteLibrary.java b/src/be/nikiroo/fanfix/library/RemoteLibrary.java index 8376639..513849e 100644 --- a/src/be/nikiroo/fanfix/library/RemoteLibrary.java +++ b/src/be/nikiroo/fanfix/library/RemoteLibrary.java @@ -16,7 +16,7 @@ import be.nikiroo.utils.serial.ConnectActionClient; /** * This {@link BasicLibrary} will access a remote server to list the available - * stories, and download the one you try to load to the local directory + * stories, and download the ones you try to load to the local directory * specified in the configuration. * * @author niki @@ -137,26 +137,32 @@ public class RemoteLibrary extends BasicLibrary { } @Override - protected int getNextId() { + public synchronized void delete(String luid) throws IOException { throw new java.lang.InternalError( "No write support allowed on remote Libraries"); } @Override - protected void doDelete(String luid) throws IOException { + public void setSourceCover(String source, String luid) { throw new java.lang.InternalError( "No write support allowed on remote Libraries"); } + // All the following methods are only used by Save and Delete in + // BasicLibrary: + @Override - protected Story doSave(Story story, Progress pg) throws IOException { - throw new java.lang.InternalError( - "No write support allowed on remote Libraries"); + protected int getNextId() { + throw new java.lang.InternalError("Should not have been called"); } @Override - public void setSourceCover(String source, String luid) { - throw new java.lang.InternalError( - "No write support allowed on remote Libraries"); + protected void doDelete(String luid) throws IOException { + throw new java.lang.InternalError("Should not have been called"); + } + + @Override + protected Story doSave(Story story, Progress pg) throws IOException { + throw new java.lang.InternalError("Should not have been called"); } } diff --git a/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java b/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java index 566c70f..661bf54 100644 --- a/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java +++ b/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java @@ -9,10 +9,32 @@ import be.nikiroo.utils.Version; import be.nikiroo.utils.serial.ConnectActionServer; import be.nikiroo.utils.serial.Server; +/** + * Create a new remote server that will listen for order on the given port. + *

+ * The available commands are: + *

+ * + * @author niki + */ public class RemoteLibraryServer extends Server { + /** + * Create a new remote server (will not be active until + * {@link RemoteLibraryServer#start()} is called). + * + * @param port + * the port to listen on + * + * @throws IOException + * in case of I/O error + */ public RemoteLibraryServer(int port) throws IOException { - super(Version.getCurrentVersion(), port, true); + super(port, true); } @Override @@ -32,16 +54,16 @@ public class RemoteLibraryServer extends Server { System.out.println(String.format("COMMAND: [%s], ARGS: [%s]", command, args)); - if (command != null) { - if (command.equals("GET_METADATA")) { - if (args != null && args.equals("*")) { - List metas = Instance.getLibrary().getMetas(null); - return metas.toArray(new MetaData[] {}); - } - } else if (command.equals("GET_STORY")) { - if (args != null) { - return Instance.getLibrary().getStory(args, null); - } + // TODO: progress (+send name + %age info back to client) + + if ("GET_METADATA".equals(command)) { + if (args != null && args.equals("*")) { + List metas = Instance.getLibrary().getMetas(null); + return metas.toArray(new MetaData[] {}); + } + } else if ("GET_STORY".equals(command)) { + if (args != null) { + return Instance.getLibrary().getStory(args, null); } } -- 2.27.0