import java.net.MalformedURLException;
import java.net.URL;
-import be.nikiroo.fanfix.bundles.Config;
import be.nikiroo.fanfix.bundles.StringId;
import be.nikiroo.fanfix.data.Chapter;
import be.nikiroo.fanfix.data.Story;
import be.nikiroo.fanfix.supported.BasicSupport.SupportType;
import be.nikiroo.utils.Progress;
import be.nikiroo.utils.Version;
+import be.nikiroo.utils.serial.ConnectActionClient;
import be.nikiroo.utils.serial.Server;
/**
*/
public class Main {
private enum MainAction {
- IMPORT, EXPORT, CONVERT, READ, READ_URL, LIST, HELP, SET_READER, START, VERSION, SERVER, REMOTE,
+ IMPORT, EXPORT, CONVERT, READ, READ_URL, LIST, HELP, SET_READER, START, VERSION, SERVER, STOP_SERVER, REMOTE,
}
/**
* for this command</li>
* <li>--version: get the version of the program</li>
* <li>--server [port]: start a server on this port</li>
+ * <li>--stop-server [port]: stop the running server on this port if any</li>
* <li>--remote [host] [port]: use a the given remote library</li>
* </ul>
*
exitCode = 255; // no arguments for this option
break;
case SERVER:
+ case STOP_SERVER:
if (port == null) {
port = Integer.parseInt(args[i]);
} else {
lib = new CacheLibrary(remoteCacheDir, lib);
BasicReader.setDefaultLibrary(lib);
-
+
action = MainAction.START;
} else {
exitCode = 255;
Instance.syserr(e);
}
return;
+ case STOP_SERVER:
+ if (port == null) {
+ exitCode = 255;
+ break;
+ }
+
+ try {
+ new ConnectActionClient(host, port, true) {
+ @Override
+ public void action(Version serverVersion)
+ throws Exception {
+ try {
+ send(new Object[] { "EXIT" });
+ } catch (Exception e) {
+ Instance.syserr(e);
+ }
+ }
+ }.connect();
+ } catch (IOException e) {
+ Instance.syserr(e);
+ }
+ break;
case REMOTE:
exitCode = 255; // should not be reachable (REMOTE -> START)
break;
* <li>GET_SOURCE_COVER [source]: return the cover for this source</li>
* <li>SET_SOURCE_COVER [source], [luid]: set the default cover for the given
* source to the cover of the story denoted by luid</li>
+ * <li>EXIT: stop the server</li>
* </ul>
*
* @author niki
return Instance.getLibrary().getSourceCover("" + args[1]);
} else if ("SET_SOURCE_COVER".equals(command)) {
Instance.getLibrary().setSourceCover("" + args[1], "" + args[2]);
+ } else if ("EXIT".equals(command)) {
+ stop(0, false);
}
return null;