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

MODULE: Differentiate different types of downloads

parent 44b8ee56
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Ce commit fait partie de la requête de fusion !122. Les commentaires créés ici seront créés dans le contexte de cette requête de fusion.
...@@ -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);
} }
...@@ -615,12 +616,12 @@ mod_update(va_list *va) ...@@ -615,12 +616,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);
...@@ -640,12 +641,12 @@ mod_rescan(va_list *va) ...@@ -640,12 +641,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);
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter