From adc7e859a1fb66b93793861d2e7fb79108d2de49 Mon Sep 17 00:00:00 2001 From: Joni Kokko Date: Wed, 17 Dec 2008 15:35:59 +0200 Subject: [PATCH] IrrecoWebdbCache manages remotes. --- irreco/src/webdb/irreco_webdb_cache.c | 102 ++++++++++++++++++++++++++++++++++ irreco/src/webdb/irreco_webdb_cache.h | 11 ++++ 2 files changed, 113 insertions(+) diff --git a/irreco/src/webdb/irreco_webdb_cache.c b/irreco/src/webdb/irreco_webdb_cache.c index d08ddea9..2c076aa7 100644 --- a/irreco/src/webdb/irreco_webdb_cache.c +++ b/irreco/src/webdb/irreco_webdb_cache.c @@ -73,6 +73,9 @@ IrrecoWebdbCache *irreco_webdb_cache_new() self->theme_id_hash = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, (GDestroyNotify) irreco_webdb_theme_free); + self->remote_id_hash = g_hash_table_new_full(g_int_hash, g_int_equal, + NULL, (GDestroyNotify) irreco_webdb_remote_free); + IRRECO_RETURN_PTR(self); } @@ -97,6 +100,8 @@ void irreco_webdb_cache_free(IrrecoWebdbCache *self) self->conf_hash = NULL; g_hash_table_destroy(self->theme_id_hash); self->theme_id_hash = NULL; + g_hash_table_destroy(self->remote_id_hash); + self->remote_id_hash = NULL; IRRECO_RETURN } @@ -1108,6 +1113,103 @@ gboolean irreco_webdb_cache_get_remote_creators(IrrecoWebdbCache *self, IRRECO_RETURN_BOOL(TRUE) } +/** + * Fetches creators belonging given category, manufacturer and model. + * + * @param creators points to internally allocated storage in the cache + * and must not be freed + * @return TRUE if configs are fetched succesfully, FALSE otherwise. + */ +gboolean irreco_webdb_cache_get_remotes(IrrecoWebdbCache *self, + const gchar *category, + const gchar *manufacturer, + const gchar *model, + const gchar *creator, + GList **remote_list) +{ + IrrecoStringTable * creator_list; + IRRECO_ENTER + + if (!irreco_webdb_cache_get_remote_creators(self, category, + manufacturer, model, + &creator_list)) { + IRRECO_RETURN_BOOL(FALSE) + } + + if (!irreco_string_table_exists(creator_list, creator)) { + g_string_printf(self->error_msg, "%s", + "Can't find creator"); + IRRECO_RETURN_BOOL(FALSE) + } + + irreco_string_table_get(creator_list, creator, + (gpointer *) remote_list); + + if(*remote_list == NULL) { + gboolean success = FALSE; + + IRRECO_RETRY_LOOP_START(self->loop) + if (irreco_webdb_cache_test(self) == FALSE) break; + success = irreco_webdb_client_get_remotes(self->private, + category, manufacturer, model, + creator, remote_list); + + if (success) break; + irreco_webdb_client_get_error_msg(self->private, + self->error_msg); + IRRECO_RETRY_LOOP_END(self->loop) + + if (success == FALSE) IRRECO_RETURN_BOOL(FALSE); + + irreco_string_table_change_data(creator_list, creator, + *remote_list); + } + + irreco_string_table_get(creator_list, creator, + (gpointer *) remote_list); + IRRECO_RETURN_BOOL(TRUE) +} + +/** + * Fetches remote by given ID. + * + * @param remote points to internally allocated storage in the cache + * and must not be freed + * @return TRUE if remote is fetched succesfully, FALSE otherwise. + */ +gboolean irreco_webdb_cache_get_remote_by_id(IrrecoWebdbCache *self, + gint id, + IrrecoWebdbRemote **remote) +{ + IRRECO_ENTER + + if (g_hash_table_lookup(self->remote_id_hash, + (gconstpointer) &id) == NULL) { + gboolean success = FALSE; + + IRRECO_RETRY_LOOP_START(self->loop) + if (irreco_webdb_cache_test(self) == FALSE) break; + success = irreco_webdb_client_get_remote_by_id( + self->private, id, remote); + + if (success) break; + irreco_webdb_client_get_error_msg(self->private, + self->error_msg); + IRRECO_RETRY_LOOP_END(self->loop) + + if (success == FALSE) IRRECO_RETURN_BOOL(FALSE); + + g_hash_table_insert(self->remote_id_hash, + (gpointer) &((*remote)->id), + (gpointer) *remote); + } + + *remote = g_hash_table_lookup(self->remote_id_hash, + (gconstpointer) &id); + + IRRECO_RETURN_BOOL(TRUE) +} + /** @} */ /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ diff --git a/irreco/src/webdb/irreco_webdb_cache.h b/irreco/src/webdb/irreco_webdb_cache.h index 7af368e7..ce65d5d9 100644 --- a/irreco/src/webdb/irreco_webdb_cache.h +++ b/irreco/src/webdb/irreco_webdb_cache.h @@ -54,6 +54,7 @@ typedef struct _IrrecoWebdbCache IrrecoWebdbCache; #include #include "irreco_webdb_conf.h" #include "irreco_webdb_theme.h" +#include "irreco_webdb_remote.h" /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ /* Datatypes */ @@ -69,6 +70,7 @@ struct _IrrecoWebdbCache GString *error_msg; GHashTable *conf_hash; GHashTable *theme_id_hash; + GHashTable *remote_id_hash; }; @@ -174,6 +176,15 @@ gboolean irreco_webdb_cache_get_remote_creators(IrrecoWebdbCache *self, const gchar *manufacturer, const gchar *model, IrrecoStringTable **creators); +gboolean irreco_webdb_cache_get_remotes(IrrecoWebdbCache *self, + const gchar *category, + const gchar *manufacturer, + const gchar *model, + const gchar *creator, + GList **remote_list); +gboolean irreco_webdb_cache_get_remote_by_id(IrrecoWebdbCache *self, + gint id, + IrrecoWebdbRemote **remote); #endif /* __IRRECO_WEBDB_CACHE_H__ */ -- 2.11.4.GIT