Changeset View
Changeset View
Standalone View
Standalone View
src/core/slavebase.cpp
Show All 29 Lines | |||||
30 | 30 | | |||
31 | #include <stdlib.h> | 31 | #include <stdlib.h> | ||
32 | #include <qplatformdefs.h> | 32 | #include <qplatformdefs.h> | ||
33 | #include <signal.h> | 33 | #include <signal.h> | ||
34 | #ifdef Q_OS_WIN | 34 | #ifdef Q_OS_WIN | ||
35 | #include <process.h> | 35 | #include <process.h> | ||
36 | #endif | 36 | #endif | ||
37 | 37 | | |||
38 | #include <QtGlobal> | ||||
dfaure: what is this used for? | |||||
38 | #include <QFile> | 39 | #include <QFile> | ||
39 | #include <QList> | 40 | #include <QList> | ||
40 | #include <QDateTime> | 41 | #include <QDateTime> | ||
41 | #include <QElapsedTimer> | 42 | #include <QElapsedTimer> | ||
42 | #include <QCoreApplication> | 43 | #include <QCoreApplication> | ||
43 | #include <QDataStream> | 44 | #include <QDataStream> | ||
45 | #include <QMap> | ||||
44 | 46 | | |||
45 | #include <kconfig.h> | 47 | #include <kconfig.h> | ||
46 | #include <kconfiggroup.h> | 48 | #include <kconfiggroup.h> | ||
47 | #include <kcrash.h> | 49 | #include <kcrash.h> | ||
48 | #include <klocalizedstring.h> | 50 | #include <klocalizedstring.h> | ||
49 | 51 | | |||
50 | #include "kremoteencoding.h" | 52 | #include "kremoteencoding.h" | ||
51 | 53 | | |||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | 90 | public: | |||
116 | bool needSendCanResume: 1; | 118 | bool needSendCanResume: 1; | ||
117 | bool onHold: 1; | 119 | bool onHold: 1; | ||
118 | bool wasKilled: 1; | 120 | bool wasKilled: 1; | ||
119 | bool inOpenLoop: 1; | 121 | bool inOpenLoop: 1; | ||
120 | bool exit_loop: 1; | 122 | bool exit_loop: 1; | ||
121 | MetaData configData; | 123 | MetaData configData; | ||
122 | KConfig *config; | 124 | KConfig *config; | ||
123 | KConfigGroup *configGroup; | 125 | KConfigGroup *configGroup; | ||
126 | QMap<QString, QVariant> mapConfig; | ||||
124 | QUrl onHoldUrl; | 127 | QUrl onHoldUrl; | ||
125 | 128 | | |||
126 | QElapsedTimer lastTimeout; | 129 | QElapsedTimer lastTimeout; | ||
127 | QElapsedTimer nextTimeout; | 130 | QElapsedTimer nextTimeout; | ||
128 | qint64 nextTimeoutMsecs; | 131 | qint64 nextTimeoutMsecs; | ||
129 | KIO::filesize_t totalSize; | 132 | KIO::filesize_t totalSize; | ||
130 | KRemoteEncoding *remotefile; | 133 | KRemoteEncoding *remotefile; | ||
131 | enum { Idle, InsideMethod, FinishedCalled, ErrorCalled } m_state; | 134 | enum { Idle, InsideMethod, FinishedCalled, ErrorCalled } m_state; | ||
Show All 40 Lines | 172 | #endif | |||
172 | bool hasTempAuth() const | 175 | bool hasTempAuth() const | ||
173 | { | 176 | { | ||
174 | return !m_tempAuths.isEmpty(); | 177 | return !m_tempAuths.isEmpty(); | ||
175 | } | 178 | } | ||
176 | 179 | | |||
177 | // Reconstructs configGroup from configData and mIncomingMetaData | 180 | // Reconstructs configGroup from configData and mIncomingMetaData | ||
178 | void rebuildConfig() | 181 | void rebuildConfig() | ||
179 | { | 182 | { | ||
180 | configGroup->deleteGroup(KConfigGroup::WriteConfigFlags()); | 183 | mapConfig.clear(); | ||
181 | 184 | | |||
182 | // mIncomingMetaData cascades over config, so we write config first, | 185 | // mIncomingMetaData cascades over config, so we write config first, | ||
183 | // to let it be overwritten | 186 | // to let it be overwritten | ||
184 | MetaData::ConstIterator end = configData.constEnd(); | 187 | MetaData::ConstIterator end = configData.constEnd(); | ||
185 | for (MetaData::ConstIterator it = configData.constBegin(); it != end; ++it) { | 188 | for (MetaData::ConstIterator it = configData.constBegin(); it != end; ++it) { | ||
186 | configGroup->writeEntry(it.key(), it->toUtf8(), KConfigGroup::WriteConfigFlags()); | 189 | mapConfig.insert(it.key(), it->toUtf8()); | ||
187 | } | 190 | } | ||
188 | 191 | | |||
189 | end = q->mIncomingMetaData.constEnd(); | 192 | end = q->mIncomingMetaData.constEnd(); | ||
190 | for (MetaData::ConstIterator it = q->mIncomingMetaData.constBegin(); it != end; ++it) { | 193 | for (MetaData::ConstIterator it = q->mIncomingMetaData.constBegin(); it != end; ++it) { | ||
191 | configGroup->writeEntry(it.key(), it->toUtf8(), KConfigGroup::WriteConfigFlags()); | 194 | mapConfig.insert(it.key(), it->toUtf8()); | ||
192 | } | 195 | } | ||
196 | | ||||
broulik: `delete nullptr` is fine, no need to check first | |||||
197 | delete configGroup; | ||||
198 | configGroup = nullptr; | ||||
missing config = nullptr so the delete config in the destructor doesn't crash. Same with configGroup. dfaure: missing `config = nullptr` so the `delete config` in the destructor doesn't crash.
Same with… | |||||
199 | delete config; | ||||
200 | config = nullptr; | ||||
193 | } | 201 | } | ||
194 | 202 | | |||
195 | bool finalState() const | 203 | bool finalState() const | ||
196 | { | 204 | { | ||
197 | return ((m_state == FinishedCalled) || (m_state == ErrorCalled)); | 205 | return ((m_state == FinishedCalled) || (m_state == ErrorCalled)); | ||
198 | } | 206 | } | ||
199 | 207 | | |||
200 | void verifyState(const char *cmdName) | 208 | void verifyState(const char *cmdName) | ||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Line(s) | 295 | #endif | |||
289 | globalSlave = this; | 297 | globalSlave = this; | ||
290 | 298 | | |||
291 | d->isConnectedToApp = true; | 299 | d->isConnectedToApp = true; | ||
292 | 300 | | |||
293 | // by kahl for netmgr (need a way to identify slaves) | 301 | // by kahl for netmgr (need a way to identify slaves) | ||
294 | d->slaveid = QString::fromUtf8(protocol) + QString::number(getpid()); | 302 | d->slaveid = QString::fromUtf8(protocol) + QString::number(getpid()); | ||
295 | d->resume = false; | 303 | d->resume = false; | ||
296 | d->needSendCanResume = false; | 304 | d->needSendCanResume = false; | ||
297 | d->config = new KConfig(QString(), KConfig::SimpleConfig); | 305 | d->mapConfig = QMap<QString, QVariant>(); | ||
broulik: This is initialized automatically like this | |||||
That's on purpose, the first use of mapConfig is in rebuildConfig and is a clear() call. meven: That's on purpose, the first use of mapConfig is in rebuildConfig and is a clear() call. | |||||
So? This line is not needed, an empty map is an empty map, no need to assign an empty map to it. dfaure: So? This line is not needed, an empty map is an empty map, no need to assign an empty map to it. | |||||
298 | // The KConfigGroup needs the KConfig to exist during its whole lifetime. | | |||
299 | d->configGroup = new KConfigGroup(d->config, QString()); | | |||
300 | d->onHold = false; | 306 | d->onHold = false; | ||
301 | d->wasKilled = false; | 307 | d->wasKilled = false; | ||
302 | // d->processed_size = 0; | 308 | // d->processed_size = 0; | ||
303 | d->totalSize = 0; | 309 | d->totalSize = 0; | ||
304 | connectSlave(QFile::decodeName(app_socket)); | 310 | connectSlave(QFile::decodeName(app_socket)); | ||
305 | 311 | | |||
306 | d->remotefile = nullptr; | 312 | d->remotefile = nullptr; | ||
307 | d->inOpenLoop = false; | 313 | d->inOpenLoop = false; | ||
308 | d->exit_loop = false; | 314 | d->exit_loop = false; | ||
309 | } | 315 | } | ||
310 | 316 | | |||
311 | SlaveBase::~SlaveBase() | 317 | SlaveBase::~SlaveBase() | ||
312 | { | 318 | { | ||
313 | delete d->configGroup; | 319 | delete d->configGroup; | ||
broulik: Don't you still want this? | |||||
314 | delete d->config; | 320 | delete d->config; | ||
315 | delete d->remotefile; | 321 | delete d->remotefile; | ||
316 | delete d; | 322 | delete d; | ||
317 | s_protocol = ""; | 323 | s_protocol = ""; | ||
318 | } | 324 | } | ||
319 | 325 | | |||
320 | void SlaveBase::dispatchLoop() | 326 | void SlaveBase::dispatchLoop() | ||
321 | { | 327 | { | ||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Line(s) | 427 | if (mIncomingMetaData.contains(key)) { | |||
422 | return true; | 428 | return true; | ||
423 | } | 429 | } | ||
424 | if (d->configData.contains(key)) { | 430 | if (d->configData.contains(key)) { | ||
425 | return true; | 431 | return true; | ||
426 | } | 432 | } | ||
427 | return false; | 433 | return false; | ||
428 | } | 434 | } | ||
429 | 435 | | |||
436 | QMap<QString, QVariant> SlaveBase::mapConfig() const | ||||
That is a weird abuse of const. If the member wasn't in a d pointer, this wouldn't compile. If the slave is supposed to only read from the map, then it should be a value or const ref. dfaure: That is a weird abuse of const. If the member wasn't in a d pointer, this wouldn't compile.
If… | |||||
437 | { | ||||
438 | return d->mapConfig; | ||||
439 | } | ||||
440 | | ||||
430 | KConfigGroup *SlaveBase::config() | 441 | KConfigGroup *SlaveBase::config() | ||
431 | { | 442 | { | ||
443 | if (!d->config) { | ||||
broulik: Just check `if (!d->config)` | |||||
444 | d->config = new KConfig(QString(), KConfig::SimpleConfig); | ||||
445 | | ||||
446 | d->configGroup = new KConfigGroup(d->config, QString()); | ||||
447 | | ||||
448 | auto end = d->mapConfig.cend(); | ||||
449 | for (auto it = d->mapConfig.cbegin(); it != end; ++it) | ||||
450 | { | ||||
451 | d->configGroup->writeEntry(it.key(), it->toString().toUtf8(), KConfigGroup::WriteConfigFlags()); | ||||
452 | } | ||||
453 | } | ||||
454 | | ||||
432 | return d->configGroup; | 455 | return d->configGroup; | ||
433 | } | 456 | } | ||
434 | 457 | | |||
435 | void SlaveBase::sendMetaData() | 458 | void SlaveBase::sendMetaData() | ||
436 | { | 459 | { | ||
437 | sendAndKeepMetaData(); | 460 | sendAndKeepMetaData(); | ||
438 | mOutgoingMetaData.clear(); | 461 | mOutgoingMetaData.clear(); | ||
439 | } | 462 | } | ||
▲ Show 20 Lines • Show All 1091 Lines • Show Last 20 Lines |
what is this used for?