Prepare work on RemoteLibrary
[fanfix.git] / src / be / nikiroo / fanfix / library / RemoteLibraryServer.java
index 566c70fa69a572043ea6749ae5361b05b6ac4b73..661bf54d61b8100d0b00a964b9016f77945666c8 100644 (file)
@@ -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.
+ * <p>
+ * The available commands are:
+ * <ul>
+ * <li>GET_METADATA *: will get the metadata of all the stories in the library</li>
+ * <li>GET_STORY [luid]: will return the given story if it exists (or NULL if
+ * not)</li>
+ * </ul>
+ * 
+ * @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<MetaData> 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<MetaData> 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);
                        }
                }