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
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);
+ }
+ } else if ("GET_COVER".equals(command)) {
+ if (args != null) {
+ return Instance.getLibrary().getCover(args);
}
}