Skip to content
Extraits de code Groupes Projets
Vérifiée Valider af489e7b rédigé par Kubat's avatar Kubat
Parcourir les fichiers

Modify searchs to add an init function

parent 80e64c25
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!71Resolve "Performance of search commands"
...@@ -90,13 +90,15 @@ struct lkt_search { ...@@ -90,13 +90,15 @@ struct lkt_search {
lkt_search_database, lkt_search_database,
lkt_search_playlist, lkt_search_playlist,
lkt_search_queue, lkt_search_queue,
lkt_add_queue,
} type; } type;
bool (*init)(volatile sqlite3 *); /* Called at the end of the init phase */ bool (*init)(volatile sqlite3 *); /* Called at the end of the init phase */
void (*call)(void); /* Called during the iter phase, casted */ void (*call)(void); /* Called during the iter phase, casted */
struct lkt_state *srv; struct lkt_state *srv;
size_t c; size_t c;
long continuation; /* The continuation state of the client */ long continuation; /* The continuation state of the client */
int msg_count; /* How much messages we can send */ int msg_count; /* How much messages we can send */
int priority; /* Can be used... where the priority is needed! */
}; };
typedef bool (*lkt_search_database_func)(struct lkt_state *srv, size_t c, int id, int id_len, typedef bool (*lkt_search_database_func)(struct lkt_state *srv, size_t c, int id, int id_len,
......
...@@ -420,14 +420,6 @@ command_noidle(struct lkt_state *srv, size_t c) ...@@ -420,14 +420,6 @@ command_noidle(struct lkt_state *srv, size_t c)
} }
/* Functions for the searchadd and the search mpd commands */ /* Functions for the searchadd and the search mpd commands */
static bool
lkt_callback_print_row_v1(struct lkt_state *srv, size_t c, int id, int id_len, const char *sql_row)
{
UNUSED(srv);
printf(" . from client %ld:\t%*d:%s\n", c, id_len, id, sql_row);
return true;
}
static bool static bool
lkt_callback_send_row_v1(void *_args, int id, int id_len, const char *sql_row) lkt_callback_send_row_v1(void *_args, int id, int id_len, const char *sql_row)
{ {
...@@ -448,22 +440,6 @@ lkt_callback_send_row_v2(struct lkt_state *srv, size_t c, int id, int id_len, co ...@@ -448,22 +440,6 @@ lkt_callback_send_row_v2(struct lkt_state *srv, size_t c, int id, int id_len, co
return true; return true;
} }
static bool
lkt_callback_insert_v1(struct lkt_state *srv, size_t c, int id, int id_len, const char *sql_row)
{
UNUSED(sql_row, id_len, c);
return database_queue_add_id(srv->db, id, 5) &&
lkt_callback_send_row_v2(srv, c, id, id_len, sql_row);
}
static bool
lkt_callback_add_v2(struct lkt_state *srv, size_t c, int id, int id_len, const char *sql_row)
{
UNUSED(sql_row, id_len, c);
return database_queue_add_id(srv->db, id, 1) &&
lkt_callback_send_row_v2(srv, c, id, id_len, sql_row);
}
static bool static bool
__find(struct lkt_state *srv, size_t c, char *cmd_args[LKT_MESSAGE_ARGS_MAX], long continuation, __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 *)) enum lkt_find_action action, bool(*init)(volatile sqlite3 *, char *, char *, struct lkt_search *))
...@@ -488,14 +464,14 @@ __find(struct lkt_state *srv, size_t c, char *cmd_args[LKT_MESSAGE_ARGS_MAX], lo ...@@ -488,14 +464,14 @@ __find(struct lkt_state *srv, size_t c, char *cmd_args[LKT_MESSAGE_ARGS_MAX], lo
search.call = (void(*)(void)) lkt_callback_send_row_v2; search.call = (void(*)(void)) lkt_callback_send_row_v2;
break; break;
case LKT_FND_ACT_PRINT: case LKT_FND_ACT_PRINT:
search.call = (void(*)(void)) lkt_callback_print_row_v1; search.call = NULL;
break; break;
case LKT_FND_ACT_ENQUEUE: case LKT_FND_ACT_ENQUEUE:
search.call = (void(*)(void)) lkt_callback_insert_v1; search.call = (void(*)(void)) lkt_callback_send_row_v2;
srv->mpd_idle_events |= MPD_IDLE_PLAYLIST; srv->mpd_idle_events |= MPD_IDLE_PLAYLIST;
break; break;
case LKT_FND_ACT_ADD: case LKT_FND_ACT_ADD:
search.call = (void(*)(void)) lkt_callback_add_v2; search.call = (void(*)(void)) lkt_callback_send_row_v2;
srv->mpd_idle_events |= MPD_IDLE_PLAYLIST; srv->mpd_idle_events |= MPD_IDLE_PLAYLIST;
break; break;
default: default:
...@@ -506,9 +482,7 @@ __find(struct lkt_state *srv, size_t c, char *cmd_args[LKT_MESSAGE_ARGS_MAX], lo ...@@ -506,9 +482,7 @@ __find(struct lkt_state *srv, size_t c, char *cmd_args[LKT_MESSAGE_ARGS_MAX], lo
mpd_tag = cmd_args[0]; mpd_tag = cmd_args[0];
if (!strcasecmp("any", mpd_tag) || if (!strcasecmp("any", mpd_tag) || !strcasecmp("all", mpd_tag) || !strcasecmp("a", mpd_tag))
!strcasecmp("all", mpd_tag) ||
!strcasecmp("a", mpd_tag))
col_name = LKT_DATABASE_KARA_COLUMNT_ANY; col_name = LKT_DATABASE_KARA_COLUMNT_ANY;
else if (!strcasecmp("author", mpd_tag)) else if (!strcasecmp("author", mpd_tag))
col_name = LKT_DATABASE_NAME_KAUTHOR; col_name = LKT_DATABASE_NAME_KAUTHOR;
......
...@@ -7,6 +7,21 @@ ...@@ -7,6 +7,21 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
static inline bool
__init_search(volatile sqlite3 *db, struct lkt_search *ret)
{
UNUSED(db);
switch (ret->type) {
case lkt_add_queue:
/* Use the add uri */
return false;
default:
LOG_WARN_SCT("DB", "Init for type %d is not implemented", ret->type);
return false;
}
return false;
}
bool bool
database_search_database_init(volatile sqlite3 *db, char *col_name, char *rgx, struct lkt_search *ret) database_search_database_init(volatile sqlite3 *db, char *col_name, char *rgx, struct lkt_search *ret)
{ {
...@@ -20,7 +35,7 @@ database_search_database_init(volatile sqlite3 *db, char *col_name, char *rgx, s ...@@ -20,7 +35,7 @@ database_search_database_init(volatile sqlite3 *db, char *col_name, char *rgx, s
char SQL_STMT[LKT_MAX_SQLITE_STATEMENT]; char SQL_STMT[LKT_MAX_SQLITE_STATEMENT];
/* Init */ /* Init */
if (ret->init && ! ret->init(db)) { if (! ret->continuation && ret->init && ! __init_search(db, ret)) {
LOG_ERROR_SCT("DB", "%s", "Failed to init search query, called to init func failed"); LOG_ERROR_SCT("DB", "%s", "Failed to init search query, called to init func failed");
return false; return false;
} }
...@@ -54,7 +69,7 @@ database_search_queue_init(volatile sqlite3 *db, char *col_name, char *rgx, stru ...@@ -54,7 +69,7 @@ database_search_queue_init(volatile sqlite3 *db, char *col_name, char *rgx, stru
char SQL_STMT[LKT_MAX_SQLITE_STATEMENT]; char SQL_STMT[LKT_MAX_SQLITE_STATEMENT];
/* Init */ /* Init */
if (ret->init && ! ret->init(db)) { if (! ret->continuation && ret->init && ! __init_search(db, ret)) {
LOG_ERROR_SCT("DB", "%s", "Failed to init search query, called to init func failed"); LOG_ERROR_SCT("DB", "%s", "Failed to init search query, called to init func failed");
return false; return false;
} }
...@@ -77,16 +92,17 @@ database_search_iter(struct lkt_search *item) ...@@ -77,16 +92,17 @@ database_search_iter(struct lkt_search *item)
{ {
const char *sql_row; const char *sql_row;
int id, code, id_len; int id, code, id_len;
code = sqlite3_step(item->stmt);
RETURN_UNLESS(item, "Exit because item is NULL, end iterations", false); RETURN_UNLESS(item, "Exit because item is NULL, end iterations", false);
GOTO_UNLESS(item->call, "Call function is NULL, terminate the search", end);
code = sqlite3_step(item->stmt);
if (code == SQLITE_DONE) if (code == SQLITE_DONE)
goto error_or_done; goto end;
if (code != SQLITE_ROW) if (code != SQLITE_ROW) {
goto error; LOG_ERROR_SCT("DB", "Step failed, expected a ROW or a DONE: %s", sqlite3_errmsg((sqlite3 *) item->db));
goto end;
}
switch (item->type) { switch (item->type) {
case lkt_search_database: case lkt_search_database:
...@@ -97,12 +113,11 @@ database_search_iter(struct lkt_search *item) ...@@ -97,12 +113,11 @@ database_search_iter(struct lkt_search *item)
case lkt_search_queue: case lkt_search_queue:
case lkt_search_playlist: case lkt_search_playlist:
default: default:
goto error; LOG_WARN_SCT("DB", "Search operation %d is not implemented", item->type);
goto end;
} }
error: end:
LOG_ERROR_SCT("DB", "sqlite3_step failed: %s", sqlite3_errmsg((sqlite3 *) item->db));
error_or_done:
sqlite3_finalize(item->stmt); sqlite3_finalize(item->stmt);
return false; return false;
} }
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter