Freeciv-3.3
Loading...
Searching...
No Matches
update_queue.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* utility */
19#include "log.h"
20#include "support.h" /* bool */
21
22/* common */
23#include "city.h"
24#include "connection.h"
25#include "player.h"
26
27/* client/include */
28#include "canvas_g.h"
29#include "citydlg_g.h"
30#include "cityrep_g.h"
31#include "dialogs_g.h"
32#include "gui_main_g.h"
33#include "menu_g.h"
34#include "pages_g.h"
35#include "plrdlg_g.h"
36#include "ratesdlg_g.h"
37#include "repodlgs_g.h"
38
39/* client */
40#include "client_main.h"
41#include "connectdlg_common.h"
42#include "options.h"
43#include "tilespec.h"
44#include "zoom.h"
45
46#include "update_queue.h"
47
48
49/* Data type in 'update_queue'. */
54
56
57/* 'struct update_queue_hash' and related functions. */
58#define SPECHASH_TAG update_queue
59#define SPECHASH_IKEY_TYPE uq_callback_t
60#define SPECHASH_IDATA_TYPE struct update_queue_data *
61#define SPECHASH_IDATA_FREE update_queue_data_destroy
62#include "spechash.h"
63#define update_queue_hash_iterate(hash, callback, uq_data) \
64 TYPED_HASH_ITERATE(uq_callback_t, const struct update_queue_data *, \
65 hash, callback, uq_data)
66#define update_queue_hash_iterate_end HASH_ITERATE_END
67
68/* Type of data listed in 'processing_started_waiting_queue' and
69 * 'processing_finished_waiting_queue'. Real type is
70 * 'struct waiting_queue_list'. */
75
76/* 'struct waiting_queue_list' and related functions. */
77#define SPECLIST_TAG waiting_queue
78#define SPECLIST_TYPE struct waiting_queue_data
79#include "speclist.h"
80#define waiting_queue_list_iterate(list, data) \
81 TYPED_LIST_ITERATE(struct waiting_queue_data, list, data)
82#define waiting_queue_list_iterate_end LIST_ITERATE_END
83
84/* 'struct waiting_queue_hash' and related functions. */
85#define SPECHASH_TAG waiting_queue
86#define SPECHASH_INT_KEY_TYPE
87#define SPECHASH_IDATA_TYPE struct waiting_queue_list *
88#define SPECHASH_IDATA_FREE waiting_queue_list_destroy
89#include "spechash.h"
90
96
97static void update_unqueue(void *data);
99 struct update_queue_data *uq_data);
100
101/************************************************************************/
104static inline struct update_queue_data *
106{
107 struct update_queue_data *uq_data = fc_malloc(sizeof(*uq_data));
108
109 uq_data->data = data;
111 return uq_data;
112}
113
114/************************************************************************/
118{
119 fc_assert_ret(NULL != uq_data);
120 if (NULL != uq_data->free_data_func) {
121 uq_data->free_data_func(uq_data->data);
122 }
123 free(uq_data);
124}
125
126/************************************************************************/
129static inline struct waiting_queue_data *
131 uq_free_fn_t free_data_func)
132{
133 struct waiting_queue_data *wq_data = fc_malloc(sizeof(*wq_data));
134
135 wq_data->callback = callback;
136 wq_data->uq_data = update_queue_data_new(data, free_data_func);
137 return wq_data;
138}
139
140/************************************************************************/
144{
146 if (NULL != wq_data->uq_data) {
147 /* May be NULL, see waiting_queue_data_extract(). */
149 }
150 free(wq_data);
151}
152
153/************************************************************************/
156static inline struct update_queue_data *
158{
159 struct update_queue_data *uq_data = wq_data->uq_data;
160
161 wq_data->uq_data = NULL;
162 return uq_data;
163}
164
165
166/************************************************************************/
186
187/************************************************************************/
212
213/************************************************************************/
220
221/************************************************************************/
225{
229 && NULL != update_queue
233 } else if (0 > update_queue_frozen_level) {
234 log_error("update_queue_frozen_level < 0, repairing...");
236 }
237}
238
239/************************************************************************/
243{
244 while (update_queue_is_frozen()) {
246 }
247}
248
249/************************************************************************/
253{
254 return (0 < update_queue_frozen_level);
255}
256
257/************************************************************************/
260static inline void
275
276/************************************************************************/
284
285/************************************************************************/
293
294/************************************************************************/
297static void update_unqueue(void *data)
298{
299 struct update_queue_hash *hash;
300
301 if (NULL == update_queue) {
303 return;
304 }
305
307 /* Cannot update now, let's add it again. */
309 return;
310 }
311
312 /* Replace the old list, don't do recursive stuff, and don't write in the
313 * hash table when we are reading it. */
317
318 /* Invoke callbacks. */
320 callback(uq_data->data);
323}
324
325/************************************************************************/
340
341/************************************************************************/
351
352/************************************************************************/
357 uq_free_fn_t free_data_func)
358{
359 if (NULL != update_queue) {
360 update_queue_push(callback, update_queue_data_new(data, free_data_func));
361 }
362}
363
364/************************************************************************/
372
373/************************************************************************/
379 const void **data,
380 uq_free_fn_t *free_data_func)
381{
382 if (NULL != update_queue) {
383 struct update_queue_data *uq_data;
384
386 if (NULL != data) {
387 *data = uq_data->data;
388 }
389 if (NULL != free_data_func) {
390 *free_data_func = uq_data->free_data_func;
391 }
392 return TRUE;
393 }
394 }
395 return FALSE;
396}
397
398/************************************************************************/
401static inline void
405{
406 if (NULL != hash) {
407 struct waiting_queue_list *list;
408
410 /* The list doesn't exist yet for that request, create it. */
413 }
415 free_data_func));
416 }
417}
418
419/************************************************************************/
430
431/************************************************************************/
445
446/************************************************************************/
457
458/************************************************************************/
472
473/************************************************************************/
476static void set_client_page_callback(void *data)
477{
478 enum client_pages page = FC_PTR_TO_INT(data);
479
481
482 if (page == PAGE_GAME) {
483 if (has_zoom_support()) {
484 if (gui_options.zoom_set) {
486 } else {
487 zoom_1_0();
488 }
489 }
490 }
491}
492
493/************************************************************************/
497{
498 log_debug("Requested page: %s.", client_pages_name(page));
499
501}
502
503/************************************************************************/
516
517/************************************************************************/
521{
522 const void *data;
523
525 &data, NULL)) {
526 return FC_PTR_TO_INT(data);
527 } else {
529 }
530}
531
532/************************************************************************/
539
540/************************************************************************/
543static void menus_update_callback(void *data)
544{
545 if (FC_PTR_TO_INT(data)) {
547 }
549}
550
551/************************************************************************/
558
559/************************************************************************/
568
569/************************************************************************/
576
577/************************************************************************/
580static void cities_update_callback(void *data)
581{
582#ifdef FREECIV_DEBUG
583#define NEED_UPDATE(city_update, action) \
584 if (city_update & need_update) { \
585 action; \
586 need_update &= ~city_update; \
587 }
588#else /* FREECIV_DEBUG */
589#define NEED_UPDATE(city_update, action) \
590 if (city_update & need_update) { \
591 action; \
592 }
593#endif /* FREECIV_DEBUG */
594
596 enum city_updates need_update = pcity->client.need_updates;
597
598 if (CU_NO_UPDATE == need_update) {
599 continue;
600 }
601
602 /* Clear all updates. */
603 pcity->client.need_updates = CU_NO_UPDATE;
604
608
609#ifdef FREECIV_DEBUG
610 if (CU_NO_UPDATE != need_update) {
611 log_error("Some city updates not handled "
612 "for city %s (id %d): %d left.",
614 }
615#endif /* FREECIV_DEBUG */
617#undef NEED_UPDATE
618}
619
620/************************************************************************/
628
629/************************************************************************/
637
638/************************************************************************/
646
647/************************************************************************/
654
655/************************************************************************/
662
663/************************************************************************/
670
671/************************************************************************/
678
679/************************************************************************/
686
687/************************************************************************/
694
695/************************************************************************/
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
#define cities_iterate_end
Definition city.h:514
#define cities_iterate(pcity)
Definition city.h:509
city_updates
Definition city.h:295
@ CU_POPUP_DIALOG
Definition city.h:299
@ CU_UPDATE_REPORT
Definition city.h:297
@ CU_UPDATE_DIALOG
Definition city.h:298
@ CU_NO_UPDATE
Definition city.h:296
struct civclient client
static struct fc_sockaddr_list * list
Definition clinet.c:102
char * incite_cost
Definition comments.c:76
bool client_start_server(void)
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
bool has_zoom_support(void)
Definition canvas.c:61
void real_city_dialog_popup(struct city *pcity)
Definition citydlg.c:566
void real_city_dialog_refresh(struct city *pcity)
Definition citydlg.c:487
void real_city_report_dialog_update(void *unused)
Definition cityrep.c:1458
void real_city_report_update_city(struct city *pcity)
Definition cityrep.c:1493
void unit_select_dialog_update_real(void *unused)
Definition dialogs.c:386
void real_multipliers_dialog_update(void *unused)
Definition gamedlgs.c:293
void add_idle_callback(void(callback)(void *), void *data)
Definition gui_main.c:2406
void real_menus_init(void)
Definition menu.c:2915
void real_menus_update(void)
Definition menu.c:2353
enum client_pages get_current_client_page(void)
Definition pages.c:3345
void real_set_client_page(enum client_pages new_page)
Definition pages.c:3353
void real_conn_list_dialog_update(void *unused)
Definition pages.c:2344
void real_players_dialog_update(void *unused)
Definition plrdlg.c:730
void real_units_report_dialog_update(void *unused)
Definition repodlgs.c:1794
void real_economy_report_dialog_update(void *unused)
Definition repodlgs.c:1268
void real_science_report_dialog_update(void *unused)
Definition repodlgs.c:751
static GHashTable * hash
Definition wldlg.c:322
#define fc_assert_ret(condition)
Definition log.h:192
#define fc_assert(condition)
Definition log.h:177
#define log_debug(message,...)
Definition log.h:116
#define log_error(message,...)
Definition log.h:104
#define fc_malloc(sz)
Definition mem.h:34
struct client_options gui_options
Definition options.c:71
#define FC_PTR_TO_INT(p)
Definition shared.h:95
#define FC_INT_TO_PTR(i)
Definition shared.h:94
Definition city.h:317
struct connection conn
Definition client_main.h:96
float zoom_default_level
Definition options.h:232
int last_request_id_used
Definition connection.h:187
struct connection::@61::@66 client
int id
Definition unit.h:147
struct unit::@84::@86 client
uq_free_fn_t free_data_func
uq_callback_t callback
struct update_queue_data * uq_data
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
bool tileset_is_fully_loaded(void)
Definition tilespec.c:7743
#define waiting_queue_list_iterate(list, data)
static void waiting_queue_add_pending_request(struct waiting_queue_hash *hash, int request_id, uq_callback_t callback, void *data, uq_free_fn_t free_data_func)
bool update_queue_is_switching_page(void)
void update_queue_free(void)
void client_start_server_and_set_page(enum client_pages page)
static struct update_queue_data * waiting_queue_data_extract(struct waiting_queue_data *wq_data)
void conn_list_dialog_update(void)
bool update_queue_is_frozen(void)
void economy_report_dialog_update(void)
void set_client_page(enum client_pages page)
void multipliers_dialog_update(void)
static void update_queue_push(uq_callback_t callback, struct update_queue_data *uq_data)
#define update_queue_hash_iterate(hash, callback, uq_data)
void update_queue_connect_processing_finished_full(int request_id, uq_callback_t callback, void *data, uq_free_fn_t free_data_func)
void update_queue_add_full(uq_callback_t callback, void *data, uq_free_fn_t free_data_func)
void city_report_dialog_update_city(struct city *pcity)
void update_queue_connect_processing_started(int request_id, uq_callback_t callback, void *data)
static struct update_queue_hash * update_queue
static struct waiting_queue_hash * processing_finished_waiting_queue
void science_report_dialog_update(void)
void update_queue_thaw(void)
static void waiting_queue_data_destroy(struct waiting_queue_data *wq_data)
void update_queue_init(void)
static struct update_queue_data * update_queue_data_new(void *data, uq_free_fn_t free_data_func)
void popup_city_dialog(struct city *pcity)
bool update_queue_has_callback_full(uq_callback_t callback, const void **data, uq_free_fn_t *free_data_func)
static void update_unqueue(void *data)
static void set_client_page_callback(void *data)
static void cities_update_callback(void *data)
void refresh_city_dialog(struct city *pcity)
void update_queue_freeze(void)
void update_queue_force_thaw(void)
void update_queue_connect_processing_started_full(int request_id, uq_callback_t callback, void *data, uq_free_fn_t free_data_func)
void update_queue_processing_finished(int request_id)
static struct waiting_queue_hash * processing_started_waiting_queue
static void update_queue_data_destroy(struct update_queue_data *pdata)
static bool update_queue_has_idle_callback
void units_report_dialog_update(void)
void update_queue_connect_processing_finished(int request_id, uq_callback_t callback, void *data)
void update_queue_add(uq_callback_t callback, void *data)
void players_dialog_update(void)
static struct waiting_queue_data * waiting_queue_data_new(uq_callback_t callback, void *data, uq_free_fn_t free_data_func)
#define NEED_UPDATE(city_update, action)
void menus_update(void)
void update_queue_processing_started(int request_id)
static void menus_update_callback(void *data)
void city_report_dialog_update(void)
static int update_queue_frozen_level
void menus_init(void)
bool update_queue_has_callback(uq_callback_t callback)
#define waiting_queue_list_iterate_end
static void waiting_queue_execute_pending_requests(struct waiting_queue_hash *hash, int request_id)
enum client_pages get_client_page(void)
void unit_select_dialog_update(void)
#define update_queue_hash_iterate_end
void(* uq_free_fn_t)(void *data)
void(* uq_callback_t)(void *data)
void zoom_1_0(void)
Definition zoom.c:66
void zoom_set(float new_zoom)
Definition zoom.c:49