added irreco_webdb_cache_get_themes function
[irreco.git] / irreco / trunk / src / webdb / irreco_webdb_cache.c
blob5b47a2125fa255035863aecacd5bcdbf1cbbd1af
1 /*
2 * irreco - Ir Remote Control
3 * Copyright (C) 2007,2008 Arto Karppinen (arto.karppinen@iki.fi),
4 * Joni Kokko (t5kojo01@students.oamk.fi),
5 * Sami Mäki (t5masa02@students.oamk.fi),
6 * Harri Vattulainen (t5vaha01@students.oamk.fi)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "irreco_webdb_cache.h"
24 #include "irreco_webdb_client.h"
29 * PURPOCE OF FILE. TODO TODO TODO
30 * Caches XML-RPC calls, enables error handling and retries failed calls.
33 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
34 /* Prototypes */
35 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
37 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
38 /* Construction & Destruction */
39 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
41 /**
42 * Create new IrrecoWebdb Object
44 IrrecoWebdbCache *irreco_webdb_cache_new()
46 IrrecoWebdbCache *self;
47 IRRECO_ENTER
49 self = g_slice_new0(IrrecoWebdbCache);
50 self->private = irreco_webdb_client_new();
51 self->error_msg = g_string_new("");
52 self->loop = irreco_retry_loop_new(IRRECO_SECONDS_TO_USEC(0.3),
53 IRRECO_SECONDS_TO_USEC(3));
54 self->conf_hash = g_hash_table_new_full(g_int_hash, g_int_equal, NULL,
55 (GDestroyNotify) irreco_webdb_conf_free);
57 self->themes = irreco_string_table_new (
58 (GDestroyNotify) irreco_webdb_theme_free, NULL);
60 IRRECO_RETURN_PTR(self);
63 /**
64 * Free resources of IrrecoWebdbCache Object.
66 void irreco_webdb_cache_free(IrrecoWebdbCache *self)
68 IRRECO_ENTER
69 g_string_free(self->error_msg, TRUE);
70 self->error_msg = NULL;
71 irreco_retry_loop_free(self->loop);
72 self->loop = NULL;
73 irreco_webdb_client_free(self->private);
74 self->private = NULL;
75 g_slice_free(IrrecoWebdbCache, self);
76 g_hash_table_destroy(self->conf_hash);
77 self->conf_hash = NULL;
78 irreco_string_table_free (self->themes);
79 IRRECO_RETURN
84 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
85 /* Private Functions */
86 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
88 /**
89 * A simple test on Irreco WebDB to test if WebDB returns correct and
90 * meaningfull results.
92 * This function generates two numbers and asks WebDB to sum them. If the sum
93 * if correct, then our connection to the WebDB seems to be working.
95 * @return TRUE on success, FALSE otherwise.
97 static gboolean irreco_webdb_cache_test(IrrecoWebdbCache *self)
99 IrrecoWebdbClient *client;
100 GRand *rand;
101 gint32 num_a;
102 gint32 num_b;
103 gint sum;
104 IRRECO_ENTER
106 if (self->test_ok) IRRECO_RETURN_BOOL(self->test_ok);
108 rand = g_rand_new();
109 client = (IrrecoWebdbClient *) self->private;
111 IRRECO_RETRY_LOOP_START(self->loop)
112 num_a = g_rand_int_range(rand, 1, 1000);
113 num_b = g_rand_int_range(rand, 1, 1000);
114 self->test_ok = irreco_webdb_client_sum(
115 client, num_a, num_b, &sum);
117 if (self->test_ok) {
118 if (sum == num_a + num_b) {
119 break;
120 } else {
121 g_string_printf(self->error_msg,
122 "Got invalid result from "
123 "sum method. %i + %i = %i. "
124 "Expected %i.",
125 num_a, num_b, sum,
126 num_a + num_b);
127 IRRECO_PRINTF("%s\n", self->error_msg->str);
128 self->test_ok = FALSE;
130 } else {
131 irreco_webdb_client_get_error_msg(
132 client, self->error_msg);
134 IRRECO_RETRY_LOOP_END(self->loop)
136 g_rand_free(rand);
137 IRRECO_RETURN_BOOL(self->test_ok);
141 * Shows error message in case categories list is empty.
143 * @return TRUE if categories is not empty, FALSE otherwise.
145 static gboolean irreco_webdb_cache_verify_category(IrrecoWebdbCache *self)
147 IRRECO_ENTER
148 if (self->categories == NULL) {
149 g_string_printf(self->error_msg, "list of categories is NULL");
150 IRRECO_PRINTF("%s\n", self->error_msg->str);
151 IRRECO_RETURN_BOOL(FALSE)
153 IRRECO_RETURN_BOOL(TRUE)
157 * Shows error message in case manufacturers list is empty.
159 * @return TRUE if manufacturers list contains data, FALSE otherwise.
161 static gboolean
162 irreco_webdb_cache_verify_manufacturer(IrrecoWebdbCache *self,
163 const gchar *category,
164 IrrecoStringTable **manufactures)
166 IRRECO_ENTER
167 if (!irreco_string_table_get(self->categories, category,
168 (gpointer*) manufactures)) {
169 g_string_printf(self->error_msg,
170 "list of manufacturers is NULL");
171 IRRECO_PRINTF("%s\n", self->error_msg->str);
172 IRRECO_RETURN_BOOL(FALSE)
174 IRRECO_RETURN_BOOL(TRUE)
179 * Shows error message in case models list is empty.
181 * @return TRUE if models list contains data, FALSE otherwise.
183 static gboolean irreco_webdb_cache_verify_model(IrrecoWebdbCache *self,
184 IrrecoStringTable *manuf_list,
185 const gchar *manufacturer,
186 IrrecoStringTable **models)
188 IRRECO_ENTER
189 if (!irreco_string_table_get(manuf_list, manufacturer,
190 (gpointer*) models)) {
191 g_string_printf(self->error_msg, "list of models is NULL");
192 IRRECO_PRINTF("%s\n", self->error_msg->str);
193 IRRECO_RETURN_BOOL(FALSE)
195 IRRECO_RETURN_BOOL(TRUE)
199 * Shows error message in case configurations list is empty.
201 * @return TRUE if configurations list contains data, FALSE otherwise.
203 static gboolean irreco_webdb_cache_verify_config(IrrecoWebdbCache *self,
204 IrrecoStringTable *models,
205 const gchar *model,
206 IrrecoStringTable **configs)
208 IRRECO_ENTER
209 if (!irreco_string_table_get(models, model, (gpointer*) configs)) {
210 g_string_printf(self->error_msg,
211 "list of configurations is NULL");
212 IRRECO_PRINTF("%s\n", self->error_msg->str);
213 IRRECO_RETURN_BOOL(FALSE)
215 IRRECO_RETURN_BOOL(TRUE)
218 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
219 /* Functions */
220 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
222 * Adds new user (name, email, password) to database.
224 * @return TRUE if user is added succesfully, FALSE otherwise.
226 gboolean irreco_webdb_cache_add_user(IrrecoWebdbCache *self,
227 const gchar *name,
228 const gchar *email,
229 const gchar *passwd)
231 IrrecoWebdbClient *client;
233 IRRECO_ENTER
235 client = (IrrecoWebdbClient *) self->private;
237 IRRECO_RETRY_LOOP_START(self->loop)
238 /* test connection to webdb */
239 if (irreco_webdb_cache_test(self) == FALSE){
240 g_string_printf(self->error_msg,
241 "Failed cache self test.");
242 IRRECO_PRINTF("%s\n", self->error_msg->str);
243 IRRECO_RETURN_BOOL(FALSE);
246 if(irreco_webdb_client_add_user(client, name, email, passwd)) {
247 IRRECO_RETURN_BOOL(TRUE);
248 } else {
249 /* irreco_webdb_client_add_user failed, get err msg */
250 irreco_webdb_client_get_error_msg(client,
251 self->error_msg);
252 IRRECO_RETURN_BOOL(FALSE);
254 IRRECO_RETRY_LOOP_END(self->loop)
256 IRRECO_RETURN_BOOL(FALSE);
260 * Adds new configuration to database.
262 * @return TRUE if configuration is uploaded succesfully, FALSE otherwise.
264 gboolean irreco_webdb_cache_upload_configuration(IrrecoWebdbCache *self,
265 const gchar *backend,
266 const gchar *category,
267 const gchar *file_hash,
268 const gchar *file_name,
269 const gchar *manufacturer,
270 const gchar *model,
271 const gchar *password,
272 const gchar *user,
273 const gchar *data)
275 IrrecoWebdbClient *client;
277 IRRECO_ENTER
279 client = (IrrecoWebdbClient *) self->private;
281 IRRECO_RETRY_LOOP_START(self->loop)
282 /* test connection to webdb */
283 if (irreco_webdb_cache_test(self) == FALSE){
284 g_string_printf(self->error_msg,
285 "Failed cache self test.");
286 IRRECO_PRINTF("%s\n", self->error_msg->str);
287 IRRECO_RETURN_BOOL(FALSE);
290 if(irreco_webdb_client_upload_configuration(client, backend,
291 category, file_hash, file_name,
292 manufacturer, model, password, user,
293 data)) {
295 IRRECO_RETURN_BOOL(TRUE);
296 } else {
297 /* irreco_webdb_client_upload_configuration failed,
298 get err msg */
299 irreco_webdb_client_get_error_msg(client,
300 self->error_msg);
301 IRRECO_RETURN_BOOL(FALSE);
303 IRRECO_RETRY_LOOP_END(self->loop)
305 IRRECO_RETURN_BOOL(FALSE);
309 * Extracts error message from IrrecoWebdbCache object.
311 * @return error message as string.
313 const gchar *irreco_webdb_cache_get_error(IrrecoWebdbCache *self)
315 IRRECO_ENTER
316 IRRECO_RETURN_STR(self->error_msg->str);
320 * Fetches categories from DB
322 * @return TRUE if categories are fetched succesfully, FALSE otherwise.
324 gboolean irreco_webdb_cache_get_categories(IrrecoWebdbCache *self,
325 IrrecoStringTable **categories)
327 IRRECO_ENTER
329 if (self->categories == NULL) {
330 gboolean success = FALSE;
331 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
333 IRRECO_RETRY_LOOP_START(self->loop)
334 if (irreco_webdb_cache_test(self) == FALSE) break;
335 success = irreco_webdb_client_get_categories(
336 client, &self->categories);
337 if (success) {
338 break;
340 irreco_webdb_client_get_error_msg(
341 client, self->error_msg);
342 IRRECO_RETRY_LOOP_END(self->loop)
344 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
346 irreco_string_table_sort_abc (self->categories);
349 *categories = self->categories;
350 IRRECO_RETURN_BOOL(TRUE)
354 * Fetches all categories from DB.
356 * @param all_categories must be freed if return value is TRUE.
357 * @return TRUE if categories are fetched succesfully, FALSE otherwise.
359 gboolean irreco_webdb_cache_get_all_categories(IrrecoWebdbCache *self,
360 IrrecoStringTable **all_categories)
362 gboolean success = FALSE;
363 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
364 IRRECO_ENTER
367 IRRECO_RETRY_LOOP_START(self->loop)
368 if (irreco_webdb_cache_test(self) == FALSE) break;
369 success = irreco_webdb_client_get_all_categories(
370 client, all_categories);
371 if (success) {
372 break;
374 irreco_webdb_client_get_error_msg(
375 client, self->error_msg);
376 IRRECO_RETRY_LOOP_END(self->loop)
378 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
380 irreco_string_table_sort_abc(*all_categories);
382 IRRECO_RETURN_BOOL(TRUE)
386 * Fetches manufacturers from DB.
388 * @param category contains category in which type manufacturers are returned.
389 * @return TRUE if manufacturers are fetched succesfully, FALSE otherwise.
391 gboolean irreco_webdb_cache_get_manufacturers(IrrecoWebdbCache *self,
392 const gchar *category,
393 IrrecoStringTable **manufacturers)
395 IrrecoStringTable *manufacturer_list;
396 IRRECO_ENTER
398 if (!irreco_webdb_cache_verify_category(self) ||
399 !irreco_webdb_cache_verify_manufacturer(self, category,
400 &manufacturer_list)) {
401 IRRECO_RETURN_BOOL(FALSE)
404 if(manufacturer_list == NULL) {
405 gboolean success = FALSE;
406 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
408 IRRECO_RETRY_LOOP_START(self->loop)
409 if (irreco_webdb_cache_test(self) == FALSE) break;
410 success = irreco_webdb_client_get_manufacturers(
411 client, category, &manufacturer_list);
413 if (success) break;
414 irreco_webdb_client_get_error_msg(
415 client, self->error_msg);
416 IRRECO_RETRY_LOOP_END(self->loop)
418 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
420 irreco_string_table_sort_abc (manufacturer_list);
421 irreco_string_table_change_data(self->categories, category,
422 manufacturer_list);
425 irreco_string_table_get(self->categories, category,
426 (gpointer *) manufacturers);
427 IRRECO_RETURN_BOOL(TRUE)
431 * Fetches all manufacturers from DB.
433 * @param all_manufacturers must be released if function returns TRUE.
434 * @return TRUE if manufacturers are fetched succesfully, FALSE otherwise.
436 gboolean irreco_webdb_cache_get_all_manufacturers(IrrecoWebdbCache *self,
437 IrrecoStringTable **all_manufacturers)
439 gboolean success = FALSE;
440 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
441 IRRECO_ENTER
444 IRRECO_RETRY_LOOP_START(self->loop)
445 if (irreco_webdb_cache_test(self) == FALSE) break;
446 success = irreco_webdb_client_get_all_manufacturers(
447 client, all_manufacturers);
448 if (success) {
449 break;
451 irreco_webdb_client_get_error_msg(
452 client, self->error_msg);
453 IRRECO_RETRY_LOOP_END(self->loop)
455 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
457 irreco_string_table_sort_abc(*all_manufacturers);
459 IRRECO_RETURN_BOOL(TRUE)
463 * Fetches models belonging given category and manufacturer.
465 * @param models must be freed if function returns TRUE.
466 * @return TRUE if models are fetched succesfully, FALSE otherwise.
468 gboolean irreco_webdb_cache_get_models(IrrecoWebdbCache *self,
469 const gchar *category,
470 const gchar *manufacturer,
471 IrrecoStringTable **models)
473 IrrecoStringTable *model_list;
474 IrrecoStringTable *manufacturer_list;
475 IRRECO_ENTER
477 if (!irreco_webdb_cache_verify_category(self) ||
478 !irreco_webdb_cache_verify_manufacturer(self, category,
479 &manufacturer_list) ||
480 !irreco_webdb_cache_verify_model(self, manufacturer_list,
481 manufacturer, &model_list)) {
482 IRRECO_RETURN_BOOL(FALSE)
485 if(model_list == NULL) {
486 gboolean success = FALSE;
487 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
489 IRRECO_RETRY_LOOP_START(self->loop)
490 if (irreco_webdb_cache_test(self) == FALSE) break;
491 success = irreco_webdb_client_get_models(
492 client, category, manufacturer, &model_list);
494 if (success) break;
495 irreco_webdb_client_get_error_msg(
496 client, self->error_msg);
497 IRRECO_RETRY_LOOP_END(self->loop)
499 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
501 irreco_string_table_sort_abc (model_list);
502 irreco_string_table_change_data(manufacturer_list, manufacturer,
503 model_list);
506 irreco_string_table_get(manufacturer_list, manufacturer,
507 (gpointer *) models);
508 IRRECO_RETURN_BOOL(TRUE)
512 * Fetches configs belonging given category, manufacturer and model.
514 * @return TRUE if configs are fetched succesfully, FALSE otherwise.
516 gboolean irreco_webdb_cache_get_configs(IrrecoWebdbCache *self,
517 const gchar *category,
518 const gchar *manufacturer,
519 const gchar *model,
520 IrrecoStringTable **configs)
522 IrrecoStringTable * config_list;
523 IrrecoStringTable * model_list;
524 IrrecoStringTable * manufacturer_list;
525 IRRECO_ENTER
527 if (!irreco_webdb_cache_verify_category(self) ||
528 !irreco_webdb_cache_verify_manufacturer(self, category,
529 &manufacturer_list) ||
530 !irreco_webdb_cache_verify_model(self, manufacturer_list,
531 manufacturer, &model_list) ||
532 !irreco_webdb_cache_verify_config(self, model_list, model,
533 &config_list)) {
534 IRRECO_RETURN_BOOL(FALSE)
537 if(config_list == NULL) {
538 gboolean success = FALSE;
539 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
541 IRRECO_RETRY_LOOP_START(self->loop)
542 if (irreco_webdb_cache_test(self) == FALSE) break;
543 success = irreco_webdb_client_get_configs(client,
544 category, manufacturer, model, &config_list);
546 if (success) break;
547 irreco_webdb_client_get_error_msg(
548 client, self->error_msg);
549 IRRECO_RETRY_LOOP_END(self->loop)
551 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
553 irreco_string_table_change_data(model_list, model, config_list);
556 irreco_string_table_get(model_list, model, (gpointer *) configs);
557 IRRECO_RETURN_BOOL(TRUE)
561 * Fetches configuration by given ID.
563 * @return TRUE if configuration is fetched succesfully, FALSE otherwise.
565 gboolean irreco_webdb_cache_get_configuration(IrrecoWebdbCache *self,
566 gint id,
567 IrrecoWebdbConf **config)
569 IrrecoWebdbConf * configuration;
570 IRRECO_ENTER
572 if (g_hash_table_lookup(self->conf_hash, (gconstpointer) &id) == NULL) {
573 gboolean success = FALSE;
574 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
576 IRRECO_RETRY_LOOP_START(self->loop)
577 if (irreco_webdb_cache_test(self) == FALSE) break;
578 success = irreco_webdb_client_get_configuration(
579 client, id, &configuration);
581 if (success) break;
582 irreco_webdb_client_get_error_msg(client,
583 self->error_msg);
584 IRRECO_RETRY_LOOP_END(self->loop)
586 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
588 g_hash_table_insert(self->conf_hash,
589 (gpointer) &configuration->id,
590 (gpointer) configuration);
593 *config = g_hash_table_lookup(self->conf_hash, (gconstpointer) &id);
595 IRRECO_RETURN_BOOL(TRUE)
599 * Fetches file by given hash and name.
601 * @return TRUE if configuration is fetched succesfully, FALSE otherwise.
603 gboolean irreco_webdb_cache_get_file(IrrecoWebdbCache *self,
604 const gchar *file_hash,
605 const gchar *file_name,
606 GString **file_data)
608 GString *file;
609 gboolean success = FALSE;
610 IrrecoWebdbClient *client;
611 IRRECO_ENTER
613 client = (IrrecoWebdbClient *) self->private;
615 IRRECO_RETRY_LOOP_START(self->loop)
616 if (irreco_webdb_cache_test(self) == FALSE) break;
617 success = irreco_webdb_client_get_file(
618 client, file_hash, file_name, &file);
620 if (success) break;
621 irreco_webdb_client_get_error_msg(client, self->error_msg);
622 IRRECO_RETRY_LOOP_END(self->loop)
624 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
626 *file_data = file;
628 IRRECO_RETURN_BOOL(TRUE)
632 * Check if user with given name is already at DB.
634 *.@param user_exists will contain info wether user name was at DB.
635 * @return TRUE if test is done succesfully, FALSE otherwise.
637 gboolean irreco_webdb_cache_get_user_exists(IrrecoWebdbCache *self,
638 const gchar *name,
639 gboolean *user_exists)
641 IrrecoWebdbClient *client;
642 gboolean success = FALSE;
644 IRRECO_ENTER
645 client = (IrrecoWebdbClient *) self->private;
646 IRRECO_RETRY_LOOP_START(self->loop)
647 /* test connection to webdb */
648 if (irreco_webdb_cache_test(self) == FALSE) break;
650 success = irreco_webdb_client_get_user_exists(client,
651 name,
652 user_exists);
654 if (success) break;
656 /* irreco_webdb_client_get_user_exists failed, get err msg */
657 irreco_webdb_client_get_error_msg(client, self->error_msg);
658 IRRECO_RETRY_LOOP_END(self->loop)
660 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
662 IRRECO_RETURN_BOOL(TRUE)
666 * Login to database.
668 * @return TRUE if login is succesful, FALSE otherwise.
670 gboolean irreco_webdb_cache_login(IrrecoWebdbCache *self,
671 const gchar *user,
672 const gchar *password)
674 IrrecoWebdbClient *client;
676 IRRECO_ENTER
678 client = (IrrecoWebdbClient *) self->private;
680 IRRECO_RETRY_LOOP_START(self->loop)
681 /* test connection to webdb */
682 if (irreco_webdb_cache_test(self) == FALSE){
683 g_string_printf(self->error_msg,
684 "Failed cache self test.");
685 IRRECO_PRINTF("%s\n", self->error_msg->str);
686 IRRECO_RETURN_BOOL(FALSE);
689 if(irreco_webdb_client_login(client, user, password)) {
691 IRRECO_RETURN_BOOL(TRUE);
692 } else {
693 /* irreco_webdb_client_login failed,
694 get err msg */
695 irreco_webdb_client_get_error_msg(client,
696 self->error_msg);
697 IRRECO_RETURN_BOOL(FALSE);
699 IRRECO_RETRY_LOOP_END(self->loop)
701 IRRECO_RETURN_BOOL(FALSE);
704 gboolean irreco_webdb_cache_get_themes(IrrecoWebdbCache *self,
705 IrrecoStringTable **theme)
707 gboolean success = FALSE;
708 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
709 IRRECO_ENTER
711 IRRECO_RETRY_LOOP_START(self->loop)
712 if (irreco_webdb_cache_test(self) == FALSE) break;
713 success = irreco_webdb_client_get_themes(client, theme);
715 if (success) break;
716 irreco_webdb_client_get_error_msg(client, self->error_msg);
717 IRRECO_RETRY_LOOP_END(self->loop)
719 IRRECO_RETURN_BOOL(success)
722 gboolean irreco_webdb_cache_get_theme_by_id(IrrecoWebdbCache *self,
723 gint theme_id,
724 IrrecoWebdbTheme **theme)
726 IrrecoWebdbTheme *get_theme;
727 IRRECO_ENTER
729 if (g_hash_table_lookup(self->conf_hash, (gconstpointer) &theme_id) == NULL) {
730 gboolean success = FALSE;
731 IrrecoWebdbClient *client = (IrrecoWebdbClient *) self->private;
733 IRRECO_RETRY_LOOP_START(self->loop)
734 if (irreco_webdb_cache_test(self) == FALSE) break;
735 success = irreco_webdb_client_get_theme_by_id(
736 client, theme_id, &get_theme);
738 if (success) break;
739 irreco_webdb_client_get_error_msg(client,
740 self->error_msg);
741 IRRECO_RETRY_LOOP_END(self->loop)
743 if (success == FALSE) IRRECO_RETURN_BOOL(FALSE);
745 g_hash_table_insert(self->conf_hash,
746 (gpointer) &get_theme->id,
747 (gpointer) get_theme);
750 *theme = g_hash_table_lookup(self->conf_hash, (gconstpointer) &theme_id);
752 IRRECO_RETURN_BOOL(TRUE)
756 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
757 /* Events and Callbacks */
758 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/