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

MODULE: Differentiate different types of downloads

parent a27962ea
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!122Resolve "Import the "Favoris" from kurisu"
...@@ -20,15 +20,59 @@ ...@@ -20,15 +20,59 @@
#include <time.h> #include <time.h>
#include <stdarg.h> #include <stdarg.h>
/* Different kinds of updates */
#define REPO_UPDATE_KARA (1 << 1) /* Downloading or rescanning the bakabase */
#define REPO_UPDATE_FAV (1 << 2) /* Downloading the favorites */
#define REPO_UPDATE_TYPE_COUNT 2 /* Different kinds of download, for some sizes... */
/*********** /***********
* Globals * * Globals *
***********/ ***********/
static volatile unsigned int __curl_init = false; static volatile unsigned int __curl_init = false;
/****************************************************** /*********************
* Private functions needed for the private structure * * Private structure *
******************************************************/ *********************/
struct module_repo_internal {
/* Just the repo */
char *name;
char *base_url;
char *kara_dir;
char *get_all_json;
char *get_id_json;
char *get_id_file;
const uint64_t version;
/* Worker threads */
struct worker_pool workers;
volatile int updating : REPO_UPDATE_TYPE_COUNT;
/* The database and the queue */
struct queue *queue;
volatile sqlite3 *db;
/* Craft a filename for newly downloaded karas. Arguments:
* - str: the destination string, the prefix, i.e. the kara_dir, is already here
* - len: the length of the string, not its size (which is PATH_MAX)
* - kara: the kara structure, which contains all the data to create the filename */
void (*craft_filename)(char str[PATH_MAX], size_t, struct kara *);
};
struct __memory {
void *mem;
size_t size;
};
struct __file {
const char *path;
int fd;
};
/*********************
* Private functions *
*********************/
/* Recursive mkdir, where the last word of the string is a file, not a folder. */ /* Recursive mkdir, where the last word of the string is a file, not a folder. */
static inline void static inline void
...@@ -74,49 +118,6 @@ __craft_filename_non_obfuscate(char str[PATH_MAX], size_t len, struct kara *kara ...@@ -74,49 +118,6 @@ __craft_filename_non_obfuscate(char str[PATH_MAX], size_t len, struct kara *kara
kara->mdt.song_type, kara->mdt.song_number, kara->mdt.song_name); kara->mdt.song_type, kara->mdt.song_number, kara->mdt.song_name);
} }
/*********************
* Private structure *
*********************/
struct module_repo_internal {
/* Just the repo */
char *name;
char *base_url;
char *kara_dir;
char *get_all_json;
char *get_id_json;
char *get_id_file;
const uint64_t version;
/* Worker threads */
struct worker_pool workers;
volatile int updating;
/* The database and the queue */
struct queue *queue;
volatile sqlite3 *db;
/* Craft a filename for newly downloaded karas. Arguments:
* - str: the destination string, the prefix, i.e. the kara_dir, is already here
* - len: the length of the string, not its size (which is PATH_MAX)
* - kara: the kara structure, which contains all the data to create the filename */
void (*craft_filename)(char str[PATH_MAX], size_t, struct kara *);
};
struct __memory {
void *mem;
size_t size;
};
struct __file {
const char *path;
int fd;
};
/*********************
* Private functions *
*********************/
static inline void static inline void
__clean_file(struct __file *f) __clean_file(struct __file *f)
{ {
...@@ -426,7 +427,7 @@ __worker_update(void *__repo) ...@@ -426,7 +427,7 @@ __worker_update(void *__repo)
{ {
struct module_repo_internal *repo = __repo; struct module_repo_internal *repo = __repo;
lkt_queue_send(repo->queue, lkt_event_db_updating, LKT_DB_UPDATING_PROGRESS); lkt_queue_send(repo->queue, lkt_event_db_updating, LKT_DB_UPDATING_PROGRESS);
repo->updating = 1; repo->updating &= REPO_UPDATE_KARA;
struct json_object *json; struct json_object *json;
LOG_INFO("REPO", "Download kara list from %s (%s), directory is %s", LOG_INFO("REPO", "Download kara list from %s (%s), directory is %s",
...@@ -456,10 +457,10 @@ __worker_rescan(void *__repo) ...@@ -456,10 +457,10 @@ __worker_rescan(void *__repo)
LOG_ERROR("REPO", "Failed to get kara prefix from config"); LOG_ERROR("REPO", "Failed to get kara prefix from config");
pthread_exit(NULL); pthread_exit(NULL);
} }
repo->updating = 1; repo->updating &= REPO_UPDATE_KARA;
database_update(repo->db, kara_prefix, 0); /* Don't check timestamp. database_update(repo->db, kara_prefix, 0); /* Don't check timestamp.
TODO: Sometimes we want to check them */ * TODO: Sometimes we want to check them */
repo->updating = 0; repo->updating &= (~ REPO_UPDATE_KARA);
lkt_queue_send(repo->queue, lkt_event_db_updating, LKT_DB_UPDATING_FINISHED); lkt_queue_send(repo->queue, lkt_event_db_updating, LKT_DB_UPDATING_FINISHED);
pthread_exit(NULL); pthread_exit(NULL);
} }
...@@ -646,12 +647,12 @@ mod_update(va_list *va) ...@@ -646,12 +647,12 @@ mod_update(va_list *va)
va_copy(copy, *va); va_copy(copy, *va);
repo = (struct module_repo_internal **) va_arg(copy, void **); repo = (struct module_repo_internal **) va_arg(copy, void **);
if ((*repo)->updating) { if ((*repo)->updating & REPO_UPDATE_KARA) {
LOG_WARN("REPO", "Already updating"); LOG_WARN("REPO", "Already updating");
va_end(copy); va_end(copy);
return 0; return 0;
} }
(*repo)->updating = 1; (*repo)->updating &= REPO_UPDATE_KARA;
if (worker_pool_push(&(*repo)->workers, __worker_update, (void *) *repo)) { if (worker_pool_push(&(*repo)->workers, __worker_update, (void *) *repo)) {
LOG_ERROR("REPO", "Out of memory"); LOG_ERROR("REPO", "Out of memory");
va_end(copy); va_end(copy);
...@@ -671,12 +672,12 @@ mod_rescan(va_list *va) ...@@ -671,12 +672,12 @@ mod_rescan(va_list *va)
va_copy(copy, *va); va_copy(copy, *va);
repo = (struct module_repo_internal **) va_arg(copy, void **); repo = (struct module_repo_internal **) va_arg(copy, void **);
if ((*repo)->updating) { if ((*repo)->updating & REPO_UPDATE_KARA) {
LOG_WARN("REPO", "Already updating"); LOG_WARN("REPO", "Already updating");
va_end(copy); va_end(copy);
return 0; return 0;
} }
(*repo)->updating = 1; (*repo)->updating &= REPO_UPDATE_KARA;
if (worker_pool_push(&(*repo)->workers, __worker_rescan, (void *) *repo)) { if (worker_pool_push(&(*repo)->workers, __worker_rescan, (void *) *repo)) {
LOG_ERROR("REPO", "Out of memory"); LOG_ERROR("REPO", "Out of memory");
va_end(copy); va_end(copy);
...@@ -699,6 +700,7 @@ mod_is_updating(va_list *va) ...@@ -699,6 +700,7 @@ mod_is_updating(va_list *va)
ret = va_arg(copy, int *); ret = va_arg(copy, int *);
if (ret == NULL) if (ret == NULL)
return 1; return 1;
/* Don't differentiate kinds of downloads here */
*ret = (*repo)->updating; *ret = (*repo)->updating;
va_end(copy); va_end(copy);
return 0; return 0;
......
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