mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-24 10:52:49 +00:00
kio: SlaveInterface::dispatch() optimization
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
5d920b66f2
commit
d3426e8206
2 changed files with 161 additions and 149 deletions
|
@ -141,162 +141,174 @@ template<int T> struct PIDType { typedef pid_t PID_t; } ;
|
||||||
template<> struct PIDType<2> { typedef qint16 PID_t; } ;
|
template<> struct PIDType<2> { typedef qint16 PID_t; } ;
|
||||||
template<> struct PIDType<4> { typedef qint32 PID_t; } ;
|
template<> struct PIDType<4> { typedef qint32 PID_t; } ;
|
||||||
|
|
||||||
bool SlaveInterface::dispatch(int _cmd, const QByteArray &rawdata)
|
bool SlaveInterface::dispatch(int cmd, const QByteArray &rawdata)
|
||||||
{
|
{
|
||||||
Q_D(SlaveInterface);
|
Q_D(SlaveInterface);
|
||||||
//kDebug(7007) << "dispatch " << _cmd;
|
//kDebug(7007) << "dispatch " << cmd;
|
||||||
|
|
||||||
QDataStream stream(rawdata);
|
QDataStream stream(rawdata);
|
||||||
|
|
||||||
QString str1;
|
switch(cmd) {
|
||||||
qint32 i;
|
case MSG_DATA:
|
||||||
qint8 b;
|
emit data(rawdata);
|
||||||
quint32 ul;
|
break;
|
||||||
|
case MSG_DATA_REQ: {
|
||||||
switch(_cmd) {
|
emit dataReq();
|
||||||
case MSG_DATA:
|
break;
|
||||||
emit data(rawdata);
|
}
|
||||||
break;
|
case MSG_OPENED: {
|
||||||
case MSG_DATA_REQ:
|
emit open();
|
||||||
emit dataReq();
|
break;
|
||||||
break;
|
}
|
||||||
case MSG_OPENED:
|
case MSG_FINISHED: {
|
||||||
emit open();
|
//kDebug(7007) << "Finished [this = " << this << "]";
|
||||||
break;
|
d->offset = 0;
|
||||||
case MSG_FINISHED:
|
d->speed_timer.stop();
|
||||||
//kDebug(7007) << "Finished [this = " << this << "]";
|
emit finished();
|
||||||
d->offset = 0;
|
break;
|
||||||
d->speed_timer.stop();
|
}
|
||||||
emit finished();
|
case MSG_STAT_ENTRY: {
|
||||||
break;
|
UDSEntry entry;
|
||||||
case MSG_STAT_ENTRY: {
|
|
||||||
UDSEntry entry;
|
|
||||||
stream >> entry;
|
|
||||||
emit statEntry(entry);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case MSG_LIST_ENTRIES: {
|
|
||||||
quint32 count;
|
|
||||||
stream >> count;
|
|
||||||
|
|
||||||
UDSEntryList list;
|
|
||||||
UDSEntry entry;
|
|
||||||
for (uint i = 0; i < count; i++) {
|
|
||||||
stream >> entry;
|
stream >> entry;
|
||||||
list.append(entry);
|
emit statEntry(entry);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
emit listEntries(list);
|
case MSG_LIST_ENTRIES: {
|
||||||
break;
|
quint32 count;
|
||||||
}
|
stream >> count;
|
||||||
case MSG_RESUME: { // From the put job
|
|
||||||
d->offset = readFilesize_t(stream);
|
UDSEntryList list;
|
||||||
emit canResume(d->offset);
|
UDSEntry entry;
|
||||||
break;
|
for (uint i = 0; i < count; i++) {
|
||||||
}
|
stream >> entry;
|
||||||
case MSG_CANRESUME: // From the get job
|
list.append(entry);
|
||||||
d->filesize = d->offset;
|
}
|
||||||
emit canResume(0); // the arg doesn't matter
|
emit listEntries(list);
|
||||||
break;
|
break;
|
||||||
case MSG_ERROR:
|
}
|
||||||
stream >> i >> str1;
|
case MSG_RESUME: { // From the put job
|
||||||
kDebug(7007) << "error " << i << " " << str1;
|
d->offset = readFilesize_t(stream);
|
||||||
emit error(i, str1);
|
emit canResume(d->offset);
|
||||||
break;
|
break;
|
||||||
case MSG_SLAVE_STATUS: {
|
}
|
||||||
PIDType<sizeof(pid_t)>::PID_t stream_pid;
|
case MSG_CANRESUME: { // From the get job
|
||||||
pid_t pid;
|
d->filesize = d->offset;
|
||||||
QByteArray protocol;
|
emit canResume(0); // the arg doesn't matter
|
||||||
stream >> stream_pid >> protocol >> str1 >> b;
|
break;
|
||||||
pid = stream_pid;
|
}
|
||||||
emit slaveStatus(pid, protocol, str1, (b != 0));
|
case MSG_ERROR: {
|
||||||
break;
|
qint32 i;
|
||||||
}
|
QString str;
|
||||||
case MSG_CONNECTED:
|
stream >> i >> str;
|
||||||
emit connected();
|
kDebug(7007) << "error " << i << " " << str;
|
||||||
break;
|
emit error(i, str);
|
||||||
case MSG_WRITTEN: {
|
break;
|
||||||
KIO::filesize_t size = readFilesize_t(stream);
|
}
|
||||||
emit written(size);
|
case MSG_SLAVE_STATUS: {
|
||||||
break;
|
PIDType<sizeof(pid_t)>::PID_t stream_pid;
|
||||||
}
|
pid_t pid;
|
||||||
case INF_TOTAL_SIZE: {
|
QByteArray protocol;
|
||||||
KIO::filesize_t size = readFilesize_t(stream);
|
QString str;
|
||||||
gettimeofday(&d->start_time, 0);
|
qint8 b;
|
||||||
d->last_time = 0;
|
stream >> stream_pid >> protocol >> str >> b;
|
||||||
d->filesize = d->offset;
|
pid = stream_pid;
|
||||||
d->sizes[0] = d->filesize - d->offset;
|
emit slaveStatus(pid, protocol, str, (b != 0));
|
||||||
d->times[0] = 0;
|
break;
|
||||||
d->nums = 1;
|
}
|
||||||
d->speed_timer.start(1000);
|
case MSG_CONNECTED: {
|
||||||
d->slave_calcs_speed = false;
|
emit connected();
|
||||||
emit totalSize(size);
|
break;
|
||||||
break;
|
}
|
||||||
}
|
case MSG_WRITTEN: {
|
||||||
case INF_PROCESSED_SIZE: {
|
KIO::filesize_t size = readFilesize_t(stream);
|
||||||
KIO::filesize_t size = readFilesize_t(stream);
|
emit written(size);
|
||||||
emit processedSize( size );
|
break;
|
||||||
d->filesize = size;
|
}
|
||||||
break;
|
case INF_TOTAL_SIZE: {
|
||||||
}
|
KIO::filesize_t size = readFilesize_t(stream);
|
||||||
case INF_POSITION: {
|
gettimeofday(&d->start_time, 0);
|
||||||
KIO::filesize_t pos = readFilesize_t(stream);
|
d->last_time = 0;
|
||||||
emit position(pos);
|
d->filesize = d->offset;
|
||||||
break;
|
d->sizes[0] = d->filesize - d->offset;
|
||||||
}
|
d->times[0] = 0;
|
||||||
case INF_SPEED:
|
d->nums = 1;
|
||||||
stream >> ul;
|
d->speed_timer.start(1000);
|
||||||
d->slave_calcs_speed = true;
|
d->slave_calcs_speed = false;
|
||||||
d->speed_timer.stop();
|
emit totalSize(size);
|
||||||
emit speed( ul );
|
break;
|
||||||
break;
|
}
|
||||||
case INF_REDIRECTION: {
|
case INF_PROCESSED_SIZE: {
|
||||||
KUrl url;
|
KIO::filesize_t size = readFilesize_t(stream);
|
||||||
stream >> url;
|
emit processedSize( size );
|
||||||
emit redirection( url );
|
d->filesize = size;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case INF_MIME_TYPE:
|
case INF_POSITION: {
|
||||||
stream >> str1;
|
KIO::filesize_t pos = readFilesize_t(stream);
|
||||||
emit mimeType(str1);
|
emit position(pos);
|
||||||
if (!d->connection->suspended())
|
break;
|
||||||
d->connection->sendnow(CMD_NONE, QByteArray());
|
}
|
||||||
break;
|
case INF_SPEED: {
|
||||||
case INF_WARNING:
|
quint32 ul;
|
||||||
stream >> str1;
|
stream >> ul;
|
||||||
emit warning(str1);
|
d->slave_calcs_speed = true;
|
||||||
break;
|
d->speed_timer.stop();
|
||||||
case INF_MESSAGEBOX: {
|
emit speed(ul);
|
||||||
kDebug(7007) << "needs a msg box";
|
break;
|
||||||
QString text, caption, buttonYes, buttonNo, dontAskAgainName;
|
}
|
||||||
int type;
|
case INF_REDIRECTION: {
|
||||||
stream >> type >> text >> caption >> buttonYes >> buttonNo;
|
KUrl url;
|
||||||
if (stream.atEnd()) {
|
stream >> url;
|
||||||
messageBox(type, text, caption, buttonYes, buttonNo);
|
emit redirection(url);
|
||||||
} else {
|
break;
|
||||||
stream >> dontAskAgainName;
|
}
|
||||||
messageBox(type, text, caption, buttonYes, buttonNo, dontAskAgainName);
|
case INF_MIME_TYPE: {
|
||||||
|
QString str;
|
||||||
|
stream >> str;
|
||||||
|
emit mimeType(str);
|
||||||
|
if (!d->connection->suspended())
|
||||||
|
d->connection->sendnow(CMD_NONE, QByteArray());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case INF_WARNING: {
|
||||||
|
QString str;
|
||||||
|
stream >> str;
|
||||||
|
emit warning(str);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case INF_MESSAGEBOX: {
|
||||||
|
kDebug(7007) << "needs a msg box";
|
||||||
|
QString text, caption, buttonYes, buttonNo, dontAskAgainName;
|
||||||
|
int type;
|
||||||
|
stream >> type >> text >> caption >> buttonYes >> buttonNo;
|
||||||
|
if (stream.atEnd()) {
|
||||||
|
messageBox(type, text, caption, buttonYes, buttonNo);
|
||||||
|
} else {
|
||||||
|
stream >> dontAskAgainName;
|
||||||
|
messageBox(type, text, caption, buttonYes, buttonNo, dontAskAgainName);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case INF_INFOMESSAGE: {
|
||||||
|
QString msg;
|
||||||
|
stream >> msg;
|
||||||
|
emit infoMessage(msg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case INF_META_DATA: {
|
||||||
|
MetaData m;
|
||||||
|
stream >> m;
|
||||||
|
emit metaData(m);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MSG_NEED_SUBURL_DATA: {
|
||||||
|
emit needSubUrlData();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
kWarning(7007) << "Slave sends unknown command (" << cmd << "), dropping slave";
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
case INF_INFOMESSAGE: {
|
|
||||||
QString msg;
|
|
||||||
stream >> msg;
|
|
||||||
emit infoMessage(msg);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case INF_META_DATA: {
|
|
||||||
MetaData m;
|
|
||||||
stream >> m;
|
|
||||||
emit metaData(m);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case MSG_NEED_SUBURL_DATA: {
|
|
||||||
emit needSubUrlData();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
kWarning(7007) << "Slave sends unknown command (" << _cmd << "), dropping slave";
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,7 +171,7 @@ protected:
|
||||||
////////////////
|
////////////////
|
||||||
|
|
||||||
virtual bool dispatch();
|
virtual bool dispatch();
|
||||||
virtual bool dispatch( int _cmd, const QByteArray &data );
|
virtual bool dispatch( int cmd, const QByteArray &data );
|
||||||
|
|
||||||
void messageBox( int type, const QString &text, const QString &caption,
|
void messageBox( int type, const QString &text, const QString &caption,
|
||||||
const QString &buttonYes, const QString &buttonNo );
|
const QString &buttonYes, const QString &buttonNo );
|
||||||
|
|
Loading…
Add table
Reference in a new issue