Browse Source

Implement start all (btcli start -a) functionality.

Closes GH-7
master
Marq Schneider 14 years ago
parent
commit
fd18baa9e6
4 changed files with 59 additions and 7 deletions
  1. +26
    -0
      btpd/cli_if.c
  2. +24
    -7
      cli/start.c
  3. +8
    -0
      misc/btpd_if.c
  4. +1
    -0
      misc/btpd_if.h

+ 26
- 0
btpd/cli_if.c View File

@@ -323,6 +323,30 @@ cmd_start(struct cli *cli, int argc, const char *args)
return write_code_buffer(cli, code);
}

static int
cmd_start_all(struct cli *cli, int argc, const char *args)
{
struct htbl_iter it;
struct tlib *tl;
enum ipc_err last_code, ret_code= IPC_OK;

if (btpd_is_stopping())
return write_code_buffer(cli, IPC_ESHUTDOWN);

for (tl = tlib_iter_first(&it); tl != NULL; tl = tlib_iter_next(&it)) {
if (torrent_startable(tl)) {
if ((last_code = torrent_start(tl)) == IPC_OK) {
active_add(tl->hash);
} else {
btpd_err("torrent_start(%d) failed.\n", tl->num);
ret_code = last_code;
}
}
}

return write_code_buffer(cli, ret_code);
}

static int
cmd_stop(struct cli *cli, int argc, const char *args)
{
@@ -355,6 +379,7 @@ cmd_stop_all(struct cli *cli, int argc, const char *args)
{
struct torrent *tp, *next;
int ret = write_code_buffer(cli, IPC_OK);

active_clear();
BTPDQ_FOREACH_MUTABLE(tp, torrent_get_all(), entry, next)
torrent_stop(tp, 0);
@@ -381,6 +406,7 @@ static struct {
{ "del", 3, cmd_del },
{ "die", 3, cmd_die },
{ "start", 5, cmd_start },
{ "start-all", 9, cmd_start_all},
{ "stop", 4, cmd_stop },
{ "stop-all", 8, cmd_stop_all},
{ "tget", 4, cmd_tget }


+ 24
- 7
cli/start.c View File

@@ -12,6 +12,10 @@ usage_start(void)
"torrent ...\n"
"\tThe torrents to activate.\n"
"\n"
"Options:\n"
"-a\n"
"\tActivate all inactive torrents.\n"
"\n"
);
exit(1);
}
@@ -24,19 +28,32 @@ static struct option start_opts [] = {
void
cmd_start(int argc, char **argv)
{
int ch;
int ch, all = 0;
struct ipc_torrent t;

while ((ch = getopt_long(argc, argv, "", start_opts, NULL)) != -1)
usage_start();
while ((ch = getopt_long(argc, argv, "a", start_opts, NULL)) != -1) {
switch (ch) {
case 'a':
all = 1;
break;
default:
usage_start();
}
}
argc -= optind;
argv += optind;

if (argc < 1)
if ((argc == 0 && !all) || (all && argc != 0))
usage_start();

btpd_connect();
for (int i = 0; i < argc; i++)
if (torrent_spec(argv[i], &t))
handle_ipc_res(btpd_start(ipc, &t), "start", argv[i]);
if (all) {
enum ipc_err code = btpd_start_all(ipc);
if (code != IPC_OK)
diemsg("command failed (%s).\n", ipc_strerror(code));
} else {
for (int i = 0; i < argc; i++)
if (torrent_spec(argv[i], &t))
handle_ipc_res(btpd_start(ipc, &t), "start", argv[i]);
}
}

+ 8
- 0
misc/btpd_if.c View File

@@ -302,6 +302,14 @@ btpd_start(struct ipc *ipc, struct ipc_torrent *tp)
return simple_treq(ipc, "start", tp);
}

enum ipc_err
btpd_start_all(struct ipc *ipc)
{
struct iobuf iob = iobuf_init(16);
iobuf_swrite(&iob, "l9:start-alle");
return ipc_buf_req_code(ipc, &iob);
}

enum ipc_err
btpd_stop(struct ipc *ipc, struct ipc_torrent *tp)
{


+ 1
- 0
misc/btpd_if.h View File

@@ -78,6 +78,7 @@ enum ipc_err btpd_add(struct ipc *ipc, const char *mi, size_t mi_size,
const char *content, const char *name);
enum ipc_err btpd_del(struct ipc *ipc, struct ipc_torrent *tp);
enum ipc_err btpd_start(struct ipc *ipc, struct ipc_torrent *tp);
enum ipc_err btpd_start_all(struct ipc *ipc);
enum ipc_err btpd_stop(struct ipc *ipc, struct ipc_torrent *tp);
enum ipc_err btpd_stop_all(struct ipc *ipc);
enum ipc_err btpd_die(struct ipc *ipc);


Loading…
Cancel
Save