From 517cef54dbe8fc243e7cc6a285e67f62b025f8c7 Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Mon, 4 May 2020 16:26:19 +0200 Subject: [PATCH] Give up on search add and search insert, just do queue add/insert --- inc/lektor/commands.h | 13 ++---------- inc/lektor/database.h | 1 - src/commands.c | 48 ++++++++----------------------------------- src/net/listen.c | 14 ++++++------- 4 files changed, 16 insertions(+), 60 deletions(-) diff --git a/inc/lektor/commands.h b/inc/lektor/commands.h index 9c413663..ba3cb7af 100644 --- a/inc/lektor/commands.h +++ b/inc/lektor/commands.h @@ -28,7 +28,7 @@ bool command_stop (volatile sqlite3 *db, struct lkt_win *win, bool command_set_pos(volatile sqlite3 *db, struct lkt_win *win, mpd_idle_flag *watch_mask_ptr, int index); /* The queue */ -bool command_add (volatile sqlite3 *db, struct lkt_win *win, char *args[LKT_MESSAGE_ARGS_MAX], mpd_idle_flag *watch_mask_ptr); +bool command_add (volatile sqlite3 *db, struct lkt_win *win, char *args[LKT_MESSAGE_ARGS_MAX], mpd_idle_flag *watch_mask_ptr, int priority); bool command_addid (volatile sqlite3 *db, struct lkt_win *win, char *args[LKT_MESSAGE_ARGS_MAX], mpd_idle_flag *watch_mask_ptr); bool command_del (volatile sqlite3 *db, struct lkt_win *win, char *pos_range, mpd_idle_flag *watch_mask_ptr); bool command_delid (volatile sqlite3 *db, struct lkt_win *win, char *id, mpd_idle_flag *watch_mask_ptr); @@ -58,18 +58,9 @@ bool command_idle(struct lkt_state *srv, size_t c, struct lkt_command *cmd); /* Cancel the call to the `idle` command. */ bool command_noidle(struct lkt_state *srv, size_t c); -/* Find commands */ -enum lkt_find_action { - LKT_FND_ACT_NONE = 0, - LKT_FND_ACT_RESPOND = (1 << 1), - LKT_FND_ACT_PRINT = (1 << 2), - LKT_FND_ACT_ENQUEUE = (1 << 3), - LKT_FND_ACT_ADD = (1 << 4), -}; - /* Find and send karas in the db that match the search expression */ bool command_find(struct lkt_state *srv, size_t c, char *cmd_args[LKT_MESSAGE_ARGS_MAX], long continuation, - enum lkt_find_action action, bool (*init)(volatile sqlite3 *, char *, char *, struct lkt_search *)); + bool (*init)(volatile sqlite3 *, char *, char *, struct lkt_search *)); /* Set options for the lektor such as `random`, `single`, `repeat`, etc */ enum lkt_playback_option { diff --git a/inc/lektor/database.h b/inc/lektor/database.h index fbfbba6f..63f6ccf4 100644 --- a/inc/lektor/database.h +++ b/inc/lektor/database.h @@ -86,7 +86,6 @@ struct lkt_search { lkt_search_sticker, } type; - void (*init)(void); /* Called at the end of the init phase */ void (*call)(void); /* Called during the iter phase, casted */ struct lkt_state *srv; diff --git a/src/commands.c b/src/commands.c index d282b858..3f0ea07f 100644 --- a/src/commands.c +++ b/src/commands.c @@ -223,14 +223,14 @@ command_stop(volatile sqlite3 *db, struct lkt_win *win, mpd_idle_flag *watch_mas } bool -command_add(volatile sqlite3 *db, struct lkt_win *win, char *args[LKT_MESSAGE_ARGS_MAX], mpd_idle_flag *watch_mask_ptr) +command_add(volatile sqlite3 *db, struct lkt_win *win, char *args[LKT_MESSAGE_ARGS_MAX], mpd_idle_flag *watch_mask_ptr, int priority) { RETURN_UNLESS(args, "Invalid argument", false); *watch_mask_ptr |= MPD_IDLE_PLAYLIST; struct lkt_uri uri; char *query = args[0]; - int ret, priority = 1; /* To be modified according to the command (insert or add) later (TODO) */ - UNUSED(win); /* No callbacks to the window for the moment */ + int ret; /* To be modified according to the command (insert or add) later (TODO) */ + UNUSED(win); /* No callbacks to the window for the moment */ RETURN_UNLESS(lkt_uri_from(&uri, query), "Failed to parse query", false); ret = database_queue_add_uri(db, &uri, priority); lkt_uri_free(&uri); @@ -394,42 +394,22 @@ lkt_callback_send_row_v2(struct lkt_state *srv, size_t c, int id, int id_len, co bool command_find(struct lkt_state *srv, size_t c, char *cmd_args[LKT_MESSAGE_ARGS_MAX], long continuation, - enum lkt_find_action action, bool(*init)(volatile sqlite3 *, char *, char *, struct lkt_search *)) + bool(*init)(volatile sqlite3 *, char *, char *, struct lkt_search *)) { char rgx[PATH_MAX], *col_name, *mpd_tag; - int count, must_init = (continuation == 0), priority; + int count; struct lkt_uri uri; - struct lkt_queue_state queue; struct lkt_search search = { .srv = srv, .c = c, .continuation = continuation, .msg_count = lkt_remaining_msg(srv, c) - 3, /* Reserve slots for OK/ACK and continue: */ - .init = NULL, + .call = (void(*)(void)) lkt_callback_send_row_v2, }; - search.msg_count = MIN(search.msg_count, 10); /* Check args */ RETURN_UNLESS(cmd_args && cmd_args[0], "Invalid argument", false); - /* Select callback */ - switch (action) { - case LKT_FND_ACT_RESPOND: - search.call = (void(*)(void)) lkt_callback_send_row_v2; - break; - case LKT_FND_ACT_PRINT: - search.call = NULL; - break; - case LKT_FND_ACT_ENQUEUE: - priority = 5; - break; - case LKT_FND_ACT_ADD: - priority = 1; - break; - default: - return false; - } - /* Select the right column */ mpd_tag = cmd_args[0]; if (!strcasecmp("any", mpd_tag) || !strcasecmp("all", mpd_tag) || !strcasecmp("query", mpd_tag) || @@ -465,20 +445,6 @@ command_find(struct lkt_state *srv, size_t c, char *cmd_args[LKT_MESSAGE_ARGS_MA } uri.value = rgx; - /* Begin, when we will prints the queue after a modification */ - if (action & (LKT_FND_ACT_ADD | LKT_FND_ACT_ENQUEUE) && ! continuation) { - search.call = (void(*)(void)) lkt_callback_send_row_v2; - search.init = (void(*)(void)) database_queue_add_uri; - search.continuation = queue.length; - RETURN_UNLESS(database_queue_state(srv->db, &queue), "Failed to get the status of the queue", false); - srv->mpd_idle_events |= MPD_IDLE_PLAYLIST; - - if (must_init && ! database_queue_add_uri(srv->db, &uri, priority)) { - LOG_ERROR_SCT("DB", "%s", "Failed to init search + (add | insert) command"); - return false; - } - } - /* Make the search langand do the right action */ RETURN_UNLESS(init(srv->db, col_name, rgx, &search), "Failed to init search", false); @@ -487,6 +453,8 @@ command_find(struct lkt_state *srv, size_t c, char *cmd_args[LKT_MESSAGE_ARGS_MA if (count) lkt_set_continuation(srv, c, continuation + count); + else + LOG_WARN_SCT("COMMAND", "%s", "Nothing found"); return true; } diff --git a/src/net/listen.c b/src/net/listen.c index f12e12f4..d04ba7d0 100644 --- a/src/net/listen.c +++ b/src/net/listen.c @@ -197,7 +197,7 @@ handle_simple_command(struct lkt_state *srv, size_t c, struct lkt_command cmd) else if (!strcmp(cmd.name, "playlist") || !strcmp(cmd.name, "playlistinfo")) err = !command_queue_list(srv, c, cmd.args); else if (!strcmp(cmd.name, "playlistfind") || !strcmp(cmd.name, "playlistsearch")) - err = ! command_find(srv, c, cmd.args, cmd.cont, LKT_FND_ACT_RESPOND, database_search_queue_init); + err = ! command_find(srv, c, cmd.args, cmd.cont, database_search_queue_init); else if (!strcmp(cmd.name, "sticker") && cmd.args[0]) { if (!strcmp(cmd.args[0], "get")) @@ -213,8 +213,10 @@ handle_simple_command(struct lkt_state *srv, size_t c, struct lkt_command cmd) else if (!strcmp(cmd.name, "help")) err = !command_help(srv, c); - else if (!strcmp(cmd.name, "add")) - err = !command_add((sqlite3 *) srv->db, &srv->win, cmd.args, &srv->mpd_idle_events); + else if (!strcmp(cmd.name, "__insert")) + err = !command_add((sqlite3 *) srv->db, &srv->win, cmd.args, &srv->mpd_idle_events, 5); + else if (!strcmp(cmd.name, "searchadd") || !strcmp(cmd.name, "findadd") || !strcmp(cmd.name, "add")) + err = !command_add((sqlite3 *) srv->db, &srv->win, cmd.args, &srv->mpd_idle_events, 1); else if (!strcmp(cmd.name, "addid")) err = !command_addid((sqlite3 *) srv->db, &srv->win, cmd.args, &srv->mpd_idle_events); else if (!strcmp(cmd.name, "deleteid")) @@ -254,11 +256,7 @@ handle_simple_command(struct lkt_state *srv, size_t c, struct lkt_command cmd) err = !command_idle(srv, c, &cmd); goto end_no_send_status; } else if (!strcmp(cmd.name, "search") || !strcmp(cmd.name, "find")) - err = ! command_find(srv, c, cmd.args, cmd.cont, LKT_FND_ACT_RESPOND, database_search_database_init); - else if (!strcmp(cmd.name, "searchadd") || !strcmp(cmd.name, "findadd")) - err = ! command_find(srv, c, cmd.args, cmd.cont, LKT_FND_ACT_ADD, database_search_queue_init); - else if (!strcmp(cmd.name, "__insert")) - err = ! command_find(srv, c, cmd.args, cmd.cont, LKT_FND_ACT_ENQUEUE, database_search_queue_init); + err = ! command_find(srv, c, cmd.args, cmd.cont, database_search_database_init); else err = 2; -- GitLab