X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FRemoteLibraryServer.java;h=b95c50f84f490134a12a8d8592b599a429b99d76;hb=e023483b95b36ec0afae4527e6e769ac28bc2fc8;hp=2799a65a1923975f4695dd8d13bb1c33c0a91f1d;hpb=74a40dfb4551443fcb20dddb50af940e14acee25;p=fanfix.git
diff --git a/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java b/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java
index 2799a65..b95c50f 100644
--- a/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java
+++ b/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java
@@ -10,8 +10,9 @@ import be.nikiroo.fanfix.data.Chapter;
import be.nikiroo.fanfix.data.MetaData;
import be.nikiroo.fanfix.data.Paragraph;
import be.nikiroo.fanfix.data.Story;
+import be.nikiroo.utils.Progress;
+import be.nikiroo.utils.Progress.ProgressListener;
import be.nikiroo.utils.Version;
-import be.nikiroo.utils.serial.server.ConnectActionClientObject;
import be.nikiroo.utils.serial.server.ConnectActionServerObject;
import be.nikiroo.utils.serial.server.ServerObject;
@@ -24,6 +25,7 @@ import be.nikiroo.utils.serial.server.ServerObject;
* The key is always a String, the commands are also Strings; the parameters
* vary depending upon the command.
*
+ * - [key] PING: will return PONG if the key is accepted
* - [key] GET_METADATA *: will return the metadata of all the stories in the
* library
* - [key] GET_STORY [luid]: will return the given story if it exists (or NULL
@@ -58,6 +60,8 @@ public class RemoteLibraryServer extends ServerObject {
public RemoteLibraryServer(String key, int port) throws IOException {
super("Fanfix remote library", port, true);
this.key = key;
+
+ setTraceHandler(Instance.getTraceHandler());
}
@Override
@@ -79,31 +83,52 @@ public class RemoteLibraryServer extends ServerObject {
}
}
- System.out.print("[" + command + "] ");
+ String trace = "[" + command + "] ";
for (Object arg : args) {
- System.out.print(arg + " ");
+ trace += arg + " ";
}
- System.out.println("");
+ getTraceHandler().trace(trace);
if (!key.equals(this.key)) {
- System.out.println("Key rejected.");
- throw new SecurityException("Invalid key");
+ getTraceHandler().trace("Key rejected.");
+ return null;
}
- // TODO: progress (+send name + %age info back to client)
-
- if ("GET_METADATA".equals(command)) {
+ if ("PING".equals(command)) {
+ return "PONG";
+ } else if ("GET_METADATA".equals(command)) {
if (args[0].equals("*")) {
- List metas = Instance.getLibrary().getMetas(null);
+ List metas = Instance.getLibrary().getMetas(
+ createPgForwarder(action));
return metas.toArray(new MetaData[] {});
}
throw new InvalidParameterException(
"only * is valid here, but you passed: " + args[0]);
} else if ("GET_STORY".equals(command)) {
+ MetaData meta = Instance.getLibrary().getInfo("" + args[0]);
+ meta = meta.clone();
+ meta.setCover(null);
+
+ action.send(meta);
+ action.rec();
+
Story story = Instance.getLibrary().getStory("" + args[0], null);
- sendStory(story, action);
+ for (Object obj : breakStory(story)) {
+ action.send(obj);
+ action.rec();
+ }
} else if ("SAVE_STORY".equals(command)) {
- Story story = recStory(action);
+ List