Freeciv21
Develop your civilization from humble roots to a global empire
update_queue.h
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 #pragma once
14 
15 #include <QHash>
16 #include <QPair>
17 #include <QQueue>
18 
19 typedef void (*uq_callback_t)(void *data);
20 typedef void (*uq_free_fn_t)(void *data);
21 
22 // Data type in 'update_queue'.
24  void *data;
26 };
27 
28 // Type of data listed in 'wq_processing_started' and
29 // 'wq_processing_finished.'
33 };
34 
35 typedef QList<struct waiting_queue_data *> waitq_list;
36 typedef QPair<uq_callback_t, struct update_queue_data *> updatePair;
37 typedef QHash<int, waitq_list *> waitingQueue;
38 
39 class update_queue {
41  QQueue<updatePair> queue;
43  bool has_idle_cb = {false};
44 
45 public:
46  static update_queue *uq();
47  static void drop();
48  ~update_queue();
49  void init();
50  void add(uq_callback_t callback, void *data);
51  void processing_finished(int request_id);
52  bool has_callback(uq_callback_t callback);
53  bool has_callback_full(uq_callback_t cb, const void **data,
54  uq_free_fn_t *free_fn);
55  void connect_processing_finished(int request_id, uq_callback_t cb,
56  void *data);
57  void connect_processing_finished_unique(int request_id, uq_callback_t cb,
58  void *data);
59  void connect_processing_finished_full(int request_id, uq_callback_t cb,
60  void *data, uq_free_fn_t free_func);
61 
62 private:
63  update_queue() = default;
64  struct update_queue_data *data_new(void *data, uq_free_fn_t free_fn);
65  void data_destroy(struct update_queue_data *dt);
66  void update_unqueue();
67  void push(uq_callback_t cb, struct update_queue_data *dt);
68  struct update_queue_data *
69  wq_data_extract(struct waiting_queue_data *wq_data);
70  void wq_run_requests(waitingQueue &hash, int request_id);
71  void wq_data_destroy(struct waiting_queue_data *wq_data);
73  uq_free_fn_t free_fn);
74  void wq_add_request(waitingQueue &hash, int request_id, uq_callback_t cb,
75  void *data, uq_free_fn_t free_fn);
76 };
77 
bool has_callback_full(uq_callback_t cb, const void **data, uq_free_fn_t *free_fn)
waitingQueue wq_processing_finished
Definition: update_queue.h:42
static update_queue * uq()
void connect_processing_finished_unique(int request_id, uq_callback_t cb, void *data)
Connects the callback to the end of the processing (in server side) of the request.
void wq_data_destroy(struct waiting_queue_data *wq_data)
void wq_run_requests(waitingQueue &hash, int request_id)
void update_unqueue()
bool has_idle_cb
Definition: update_queue.h:43
static void drop()
static update_queue * m_instance
Definition: update_queue.h:40
struct waiting_queue_data * wq_data_new(uq_callback_t callback, void *data, uq_free_fn_t free_fn)
struct update_queue_data * wq_data_extract(struct waiting_queue_data *wq_data)
bool has_callback(uq_callback_t callback)
void connect_processing_finished_full(int request_id, uq_callback_t cb, void *data, uq_free_fn_t free_func)
void data_destroy(struct update_queue_data *dt)
void connect_processing_finished(int request_id, uq_callback_t cb, void *data)
update_queue()=default
void push(uq_callback_t cb, struct update_queue_data *dt)
void wq_add_request(waitingQueue &hash, int request_id, uq_callback_t cb, void *data, uq_free_fn_t free_fn)
QQueue< updatePair > queue
Definition: update_queue.h:41
struct update_queue_data * data_new(void *data, uq_free_fn_t free_fn)
void add(uq_callback_t callback, void *data)
void processing_finished(int request_id)
uq_free_fn_t free_data_func
Definition: update_queue.h:25
uq_callback_t callback
Definition: update_queue.h:31
struct update_queue_data * uq_data
Definition: update_queue.h:32
bool update_queue_is_switching_page(void)
void(* uq_free_fn_t)(void *data)
Definition: update_queue.h:20
void(* uq_callback_t)(void *data)
Definition: update_queue.h:19
void players_dialog_update()
QList< struct waiting_queue_data * > waitq_list
Definition: update_queue.h:35
QPair< uq_callback_t, struct update_queue_data * > updatePair
Definition: update_queue.h:36
QHash< int, waitq_list * > waitingQueue
Definition: update_queue.h:37