|
21 | 21 | #include <validation.h>
|
22 | 22 |
|
23 | 23 | #include <stdint.h>
|
24 |
| -#include <functional> |
25 | 24 |
|
26 | 25 | #include <QDebug>
|
| 26 | +#include <QMetaObject> |
27 | 27 | #include <QThread>
|
28 | 28 | #include <QTimer>
|
29 | 29 |
|
@@ -148,21 +148,6 @@ uint256 ClientModel::getBestBlockHash()
|
148 | 148 | return m_cached_tip_blocks;
|
149 | 149 | }
|
150 | 150 |
|
151 |
| -void ClientModel::updateNumConnections(int numConnections) |
152 |
| -{ |
153 |
| - Q_EMIT numConnectionsChanged(numConnections); |
154 |
| -} |
155 |
| - |
156 |
| -void ClientModel::updateNetworkActive(bool networkActive) |
157 |
| -{ |
158 |
| - Q_EMIT networkActiveChanged(networkActive); |
159 |
| -} |
160 |
| - |
161 |
| -void ClientModel::updateAlert() |
162 |
| -{ |
163 |
| - Q_EMIT alertsChanged(getStatusBarWarnings()); |
164 |
| -} |
165 |
| - |
166 | 151 | enum BlockSource ClientModel::getBlockSource() const
|
167 | 152 | {
|
168 | 153 | if (m_node.getReindex())
|
@@ -230,94 +215,65 @@ QString ClientModel::blocksDir() const
|
230 | 215 | return GUIUtil::PathToQString(gArgs.GetBlocksDirPath());
|
231 | 216 | }
|
232 | 217 |
|
233 |
| -void ClientModel::updateBanlist() |
234 |
| -{ |
235 |
| - banTableModel->refresh(); |
236 |
| -} |
237 |
| - |
238 |
| -// Handlers for core signals |
239 |
| -static void ShowProgress(ClientModel *clientmodel, const std::string &title, int nProgress) |
240 |
| -{ |
241 |
| - // emits signal "showProgress" |
242 |
| - bool invoked = QMetaObject::invokeMethod(clientmodel, "showProgress", Qt::QueuedConnection, |
243 |
| - Q_ARG(QString, QString::fromStdString(title)), |
244 |
| - Q_ARG(int, nProgress)); |
245 |
| - assert(invoked); |
246 |
| -} |
247 |
| - |
248 |
| -static void NotifyNumConnectionsChanged(ClientModel *clientmodel, int newNumConnections) |
249 |
| -{ |
250 |
| - // Too noisy: qDebug() << "NotifyNumConnectionsChanged: " + QString::number(newNumConnections); |
251 |
| - bool invoked = QMetaObject::invokeMethod(clientmodel, "updateNumConnections", Qt::QueuedConnection, |
252 |
| - Q_ARG(int, newNumConnections)); |
253 |
| - assert(invoked); |
254 |
| -} |
255 |
| - |
256 |
| -static void NotifyNetworkActiveChanged(ClientModel *clientmodel, bool networkActive) |
257 |
| -{ |
258 |
| - bool invoked = QMetaObject::invokeMethod(clientmodel, "updateNetworkActive", Qt::QueuedConnection, |
259 |
| - Q_ARG(bool, networkActive)); |
260 |
| - assert(invoked); |
261 |
| -} |
262 |
| - |
263 |
| -static void NotifyAlertChanged(ClientModel *clientmodel) |
264 |
| -{ |
265 |
| - qDebug() << "NotifyAlertChanged"; |
266 |
| - bool invoked = QMetaObject::invokeMethod(clientmodel, "updateAlert", Qt::QueuedConnection); |
267 |
| - assert(invoked); |
268 |
| -} |
269 |
| - |
270 |
| -static void BannedListChanged(ClientModel *clientmodel) |
271 |
| -{ |
272 |
| - qDebug() << QString("%1: Requesting update for peer banlist").arg(__func__); |
273 |
| - bool invoked = QMetaObject::invokeMethod(clientmodel, "updateBanlist", Qt::QueuedConnection); |
274 |
| - assert(invoked); |
275 |
| -} |
276 |
| - |
277 |
| -static void BlockTipChanged(ClientModel* clientmodel, SynchronizationState sync_state, interfaces::BlockTip tip, double verificationProgress, bool fHeader) |
| 218 | +void ClientModel::TipChanged(SynchronizationState sync_state, interfaces::BlockTip tip, double verification_progress, bool header) |
278 | 219 | {
|
279 |
| - if (fHeader) { |
| 220 | + if (header) { |
280 | 221 | // cache best headers time and height to reduce future cs_main locks
|
281 |
| - clientmodel->cachedBestHeaderHeight = tip.block_height; |
282 |
| - clientmodel->cachedBestHeaderTime = tip.block_time; |
| 222 | + cachedBestHeaderHeight = tip.block_height; |
| 223 | + cachedBestHeaderTime = tip.block_time; |
283 | 224 | } else {
|
284 |
| - clientmodel->m_cached_num_blocks = tip.block_height; |
285 |
| - WITH_LOCK(clientmodel->m_cached_tip_mutex, clientmodel->m_cached_tip_blocks = tip.block_hash;); |
| 225 | + m_cached_num_blocks = tip.block_height; |
| 226 | + WITH_LOCK(m_cached_tip_mutex, m_cached_tip_blocks = tip.block_hash;); |
286 | 227 | }
|
287 | 228 |
|
288 | 229 | // Throttle GUI notifications about (a) blocks during initial sync, and (b) both blocks and headers during reindex.
|
289 |
| - const bool throttle = (sync_state != SynchronizationState::POST_INIT && !fHeader) || sync_state == SynchronizationState::INIT_REINDEX; |
| 230 | + const bool throttle = (sync_state != SynchronizationState::POST_INIT && !header) || sync_state == SynchronizationState::INIT_REINDEX; |
290 | 231 | const int64_t now = throttle ? GetTimeMillis() : 0;
|
291 |
| - int64_t& nLastUpdateNotification = fHeader ? nLastHeaderTipUpdateNotification : nLastBlockTipUpdateNotification; |
| 232 | + int64_t& nLastUpdateNotification = header ? nLastHeaderTipUpdateNotification : nLastBlockTipUpdateNotification; |
292 | 233 | if (throttle && now < nLastUpdateNotification + count_milliseconds(MODEL_UPDATE_DELAY)) {
|
293 | 234 | return;
|
294 | 235 | }
|
295 | 236 |
|
296 |
| - bool invoked = QMetaObject::invokeMethod(clientmodel, "numBlocksChanged", Qt::QueuedConnection, |
297 |
| - Q_ARG(int, tip.block_height), |
298 |
| - Q_ARG(QDateTime, QDateTime::fromSecsSinceEpoch(tip.block_time)), |
299 |
| - Q_ARG(double, verificationProgress), |
300 |
| - Q_ARG(bool, fHeader), |
301 |
| - Q_ARG(SynchronizationState, sync_state)); |
302 |
| - assert(invoked); |
| 237 | + Q_EMIT numBlocksChanged(tip.block_height, QDateTime::fromSecsSinceEpoch(tip.block_time), verification_progress, header, sync_state); |
303 | 238 | nLastUpdateNotification = now;
|
304 | 239 | }
|
305 | 240 |
|
306 | 241 | void ClientModel::subscribeToCoreSignals()
|
307 | 242 | {
|
308 |
| - // Connect signals to client |
309 |
| - m_handler_show_progress = m_node.handleShowProgress(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2)); |
310 |
| - m_handler_notify_num_connections_changed = m_node.handleNotifyNumConnectionsChanged(std::bind(NotifyNumConnectionsChanged, this, std::placeholders::_1)); |
311 |
| - m_handler_notify_network_active_changed = m_node.handleNotifyNetworkActiveChanged(std::bind(NotifyNetworkActiveChanged, this, std::placeholders::_1)); |
312 |
| - m_handler_notify_alert_changed = m_node.handleNotifyAlertChanged(std::bind(NotifyAlertChanged, this)); |
313 |
| - m_handler_banned_list_changed = m_node.handleBannedListChanged(std::bind(BannedListChanged, this)); |
314 |
| - m_handler_notify_block_tip = m_node.handleNotifyBlockTip(std::bind(BlockTipChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, false)); |
315 |
| - m_handler_notify_header_tip = m_node.handleNotifyHeaderTip(std::bind(BlockTipChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, true)); |
| 243 | + m_handler_show_progress = m_node.handleShowProgress( |
| 244 | + [this](const std::string& title, int progress, [[maybe_unused]] bool resume_possible) { |
| 245 | + Q_EMIT showProgress(QString::fromStdString(title), progress); |
| 246 | + }); |
| 247 | + m_handler_notify_num_connections_changed = m_node.handleNotifyNumConnectionsChanged( |
| 248 | + [this](int new_num_connections) { |
| 249 | + Q_EMIT numConnectionsChanged(new_num_connections); |
| 250 | + }); |
| 251 | + m_handler_notify_network_active_changed = m_node.handleNotifyNetworkActiveChanged( |
| 252 | + [this](bool network_active) { |
| 253 | + Q_EMIT networkActiveChanged(network_active); |
| 254 | + }); |
| 255 | + m_handler_notify_alert_changed = m_node.handleNotifyAlertChanged( |
| 256 | + [this]() { |
| 257 | + qDebug() << "ClientModel: NotifyAlertChanged"; |
| 258 | + Q_EMIT alertsChanged(getStatusBarWarnings()); |
| 259 | + }); |
| 260 | + m_handler_banned_list_changed = m_node.handleBannedListChanged( |
| 261 | + [this]() { |
| 262 | + qDebug() << "ClienModel: Requesting update for peer banlist"; |
| 263 | + QMetaObject::invokeMethod(banTableModel, [this] { banTableModel->refresh(); }); |
| 264 | + }); |
| 265 | + m_handler_notify_block_tip = m_node.handleNotifyBlockTip( |
| 266 | + [this](SynchronizationState sync_state, interfaces::BlockTip tip, double verification_progress) { |
| 267 | + TipChanged(sync_state, tip, verification_progress, /*header=*/false); |
| 268 | + }); |
| 269 | + m_handler_notify_header_tip = m_node.handleNotifyHeaderTip( |
| 270 | + [this](SynchronizationState sync_state, interfaces::BlockTip tip, double verification_progress) { |
| 271 | + TipChanged(sync_state, tip, verification_progress, /*header=*/true); |
| 272 | + }); |
316 | 273 | }
|
317 | 274 |
|
318 | 275 | void ClientModel::unsubscribeFromCoreSignals()
|
319 | 276 | {
|
320 |
| - // Disconnect signals from client |
321 | 277 | m_handler_show_progress->disconnect();
|
322 | 278 | m_handler_notify_num_connections_changed->disconnect();
|
323 | 279 | m_handler_notify_network_active_changed->disconnect();
|
|
0 commit comments