Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 41515 | Differences between
and this patch

Collapse All | Expand All

(-)kget.old/slave.cpp (-109 / +84 lines)
Lines 36-45 Link Here
36
#include <assert.h>
36
#include <assert.h>
37
37
38
Slave::Slave(Transfer * _parent, const KURL & _src, const KURL & _dest)
38
Slave::Slave(Transfer * _parent, const KURL & _src, const KURL & _dest)
39
    : QObject(),
39
    : QObject()
40
      QThread()
41
{
40
{
42
    mDebug << ">>>>Entering" << endl;
41
    sDebug << ">>>>Entering" << endl;
43
    copyjob = NULL;
42
    copyjob = NULL;
44
    m_src = _src;
43
    m_src = _src;
45
    m_dest = _dest;
44
    m_dest = _dest;
Lines 47-53 Link Here
47
46
48
    nPendingCommand = 0;
47
    nPendingCommand = 0;
49
48
50
    mDebug << ">>>>Leaving" << endl;
49
    sDebug << ">>>>Leaving" << endl;
51
}
50
}
52
51
53
Slave::~Slave()
52
Slave::~Slave()
Lines 55-72 Link Here
55
54
56
void Slave::Op(SlaveCommand _cmd)
55
void Slave::Op(SlaveCommand _cmd)
57
{
56
{
58
    mDebugIn << " _cmd = " << _cmd << endl;
57
    sDebugIn << " _cmd = " << _cmd << endl;
59
58
60
    if ( !running() ) // start on demand
61
        start();
62
63
    mutex.lock();
64
    stack.push(_cmd);
59
    stack.push(_cmd);
65
    nPendingCommand++;
60
    nPendingCommand++;
66
    worker.wakeOne();
61
    run();
67
    mutex.unlock();
62
    sDebugOut << endl;
68
69
    mDebugOut << endl;
70
}
63
}
71
64
72
/** No descriptions */
65
/** No descriptions */
Lines 82-88 Link Here
82
    SlaveEvent *e1 = new SlaveEvent(m_parent, _event, _msg);
75
    SlaveEvent *e1 = new SlaveEvent(m_parent, _event, _msg);
83
76
84
    QApplication::postEvent(kapp->mainWidget(), (QEvent *) e1);
77
    QApplication::postEvent(kapp->mainWidget(), (QEvent *) e1);
85
    mDebug << "Msg:" << "_msg = " << _msg << endl;
78
    sDebug << "Msg:" << "_msg = " << _msg << endl;
86
}
79
}
87
80
88
void Slave::InfoMessage(const QString & _msg)
81
void Slave::InfoMessage(const QString & _msg)
Lines 90-204 Link Here
90
    SlaveEvent *e1 = new SlaveEvent(m_parent, SLV_INFO, _msg);
83
    SlaveEvent *e1 = new SlaveEvent(m_parent, SLV_INFO, _msg);
91
84
92
    QApplication::postEvent(kapp->mainWidget(), (QEvent *) e1);
85
    QApplication::postEvent(kapp->mainWidget(), (QEvent *) e1);
93
    mDebug << "Infor Msg:" << "_msg = " << _msg << endl;
86
    sDebug << "Infor Msg:" << "_msg = " << _msg << endl;
94
}
87
}
95
88
96
89
97
90
98
void Slave::run()
91
void Slave::run()
99
{
92
{
100
    mDebugIn << endl;
93
    sDebugIn << endl;
101
94
102
    SlaveCommand cmd;
95
    SlaveCommand cmd;
103
    bool running = true;
104
96
105
    while (running) 
97
    switch (cmd = fetch_cmd()) 
106
    {
98
    {
107
        if (!nPendingCommand)
99
        case RESTART:
108
            worker.wait();
100
            copyjob->kill(true);
109
        switch (cmd = fetch_cmd()) 
101
            // fall through
110
        {
102
        case RETR:
111
            case RESTART:
103
            sDebug << " FETCHED COMMAND       RETR" << endl;
112
                copyjob->kill(true);
104
            KIO::Scheduler::checkSlaveOnHold( true );
113
                // fall through
105
            copyjob = new KIO::GetFileJob(m_src, m_dest);
114
            case RETR:
106
            copyjob->setAutoErrorHandlingEnabled(true);
115
                mDebug << " FETCHED COMMAND       RETR" << endl;
107
            Connect();
116
                KIO::Scheduler::checkSlaveOnHold( true );
108
            PostMessage(SLV_RESUMED);
117
                copyjob = new KIO::GetFileJob(m_src, m_dest);
109
            break;
118
                copyjob->setAutoErrorHandlingEnabled(true);
110
119
                Connect();
111
        case PAUSE:
120
                PostMessage(SLV_RESUMED);
112
            sDebug << " FETCHED COMMAND       PAUSE" << endl;
121
                break;
113
            copyjob->kill(true);
122
114
            copyjob = 0L;
123
            case PAUSE:
115
            PostMessage(SLV_PAUSED);
124
                mDebug << " FETCHED COMMAND       PAUSE" << endl;
116
            break;
125
                copyjob->kill(true);
117
126
                copyjob = 0L;
118
        case KILL:
127
                PostMessage(SLV_PAUSED);
119
            sDebug << " FETCHED COMMAND      KILL" << endl;
128
                break;
120
            if (copyjob)
129
121
              copyjob->kill(true);
130
            case KILL:
122
            copyjob = 0L;
131
                mDebug << " FETCHED COMMAND      KILL" << endl;
123
            // no message posted
132
                running = false;
124
            break;
133
                if (copyjob)
134
                {
135
                copyjob->kill(true);
136
                copyjob = 0L;
137
                 }
138
                // no message posted
139
                break;
140
            
125
            
141
            case REMOVE:
126
        case REMOVE:
142
                mDebug << " FETCHED COMMAND       REMOVE" << endl;
127
            sDebug << " FETCHED COMMAND       REMOVE" << endl;
143
                running = false;
128
            copyjob->kill(true);
144
                copyjob->kill(true);
129
            copyjob = 0L;
145
                copyjob = 0L;
130
            PostMessage(SLV_REMOVED);
146
                PostMessage(SLV_REMOVED);
131
            break;
147
                break;
132
148
133
        case SCHEDULE:
149
            case SCHEDULE:
134
            sDebug << " FETCHED COMMAND       SCHEDULE" << endl;
150
                mDebug << " FETCHED COMMAND       SCHEDULE" << endl;
135
            copyjob->kill(true);
151
                copyjob->kill(true);
136
            copyjob = 0L;
152
                copyjob = 0L;
137
            PostMessage(SLV_SCHEDULED);
153
                PostMessage(SLV_SCHEDULED);
138
            break;
154
                break;
139
155
140
        case DELAY:
156
            case DELAY:
141
            sDebug << " FETCHED COMMAND       DELAY" << endl;
157
                mDebug << " FETCHED COMMAND       DELAY" << endl;
142
            copyjob->kill(true);
158
                copyjob->kill(true);
143
            copyjob = 0L;
159
                copyjob = 0L;
144
            PostMessage(SLV_DELAYED);
160
                PostMessage(SLV_DELAYED);
145
            break;
161
                break;
146
162
147
        case NOOP:
163
            case NOOP:
148
            sDebug << "FETCHED COMMAND        NOOP, i.e. empty stack" << endl;
164
                mDebug << "FETCHED COMMAND        NOOP, i.e. empty stack" << endl;
149
            if ( copyjob )
165
                if ( copyjob )
150
            {
166
                {
167
                    copyjob->kill(true);
151
                    copyjob->kill(true);
168
                    copyjob = 0L;
152
                    copyjob = 0L;
169
                }
170
                running = false;
171
                break;
172
173
            default: {
174
                mDebug << " UNKNOWN COMMAND DIE...." << endl;
175
                assert(0);
176
            }
153
            }
154
            break;
155
156
        default: {
157
            sDebug << " UNKNOWN COMMAND DIE...." << endl;
158
            assert(0);
177
        }
159
        }
178
    }
160
    }
179
161
    sDebugOut << endl;
180
    copyjob = NULL;
181
    mDebugOut << endl;
182
}
162
}
183
163
184
164
185
Slave::SlaveCommand Slave::fetch_cmd()
165
Slave::SlaveCommand Slave::fetch_cmd()
186
{
166
{
187
    mutex.lock();
188
    SlaveCommand cmd = NOOP;
167
    SlaveCommand cmd = NOOP;
189
    if ( !stack.isEmpty() )
168
    if ( !stack.isEmpty() )
190
    {
169
    {
191
        nPendingCommand--;
170
        nPendingCommand--;
192
        cmd = stack.pop();
171
        cmd = stack.pop();
193
    }
172
    }
194
    mutex.unlock();
195
    return cmd;
173
    return cmd;
196
}
174
}
197
175
198
176
199
void Slave::Connect()
177
void Slave::Connect()
200
{
178
{
201
    mDebugIn << endl;
179
    sDebugIn << endl;
202
180
203
181
204
    connect(copyjob, SIGNAL(canceled(KIO::Job *)), SLOT(slotCanceled(KIO::Job *)));
182
    connect(copyjob, SIGNAL(canceled(KIO::Job *)), SLOT(slotCanceled(KIO::Job *)));
Lines 213-287 Link Here
213
191
214
    connect(copyjob, SIGNAL(infoMessage(KIO::Job *, const QString &)), SLOT(slotInfoMessage(KIO::Job *, const QString &)));
192
    connect(copyjob, SIGNAL(infoMessage(KIO::Job *, const QString &)), SLOT(slotInfoMessage(KIO::Job *, const QString &)));
215
193
216
    mDebugOut << endl;
194
    sDebugOut << endl;
217
}
195
}
218
196
219
197
220
void Slave::slotCanceled(KIO::Job *)
198
void Slave::slotCanceled(KIO::Job *)
221
{
199
{
222
    mDebugIn << endl;
200
    sDebugIn << endl;
223
201
224
202
225
    mDebugOut << endl;
203
    sDebugOut << endl;
226
}
204
}
227
205
228
void Slave::slotConnected(KIO::Job *)
206
void Slave::slotConnected(KIO::Job *)
229
{
207
{
230
    mDebugIn << endl;
208
    sDebugIn << endl;
231
209
232
210
233
    mDebugOut << endl;
211
    sDebugOut << endl;
234
}
212
}
235
213
236
void Slave::slotResult(KIO::Job * job)
214
void Slave::slotResult(KIO::Job * job)
237
{
215
{
238
    mDebugIn << endl;
216
    sDebugIn << endl;
239
    if (job->error()) {
217
    if (job->error()) {
240
        InfoMessage(job->errorString());
218
        InfoMessage(job->errorString());
241
        terminate(); // AEEIIII!
242
        wait();
243
        PostMessage(SLV_DELAYED);
219
        PostMessage(SLV_DELAYED);
244
    } else
220
    } else
245
    {
221
    {
246
        terminate(); // AEEIIII!
247
        wait();
248
        PostMessage(SLV_FINISHED);
222
        PostMessage(SLV_FINISHED);
249
    }
223
    }
250
    mDebugOut << endl;
224
    copyjob=0L;
225
    sDebugOut << endl;
251
}
226
}
252
227
253
228
254
void Slave::slotSpeed(KIO::Job *, unsigned long lSpeed)
229
void Slave::slotSpeed(KIO::Job *, unsigned long lSpeed)
255
{
230
{
256
    // mDebugIn<<endl;
231
    // sDebugIn<<endl;
257
    PostMessage(SLV_PROGRESS_SPEED, lSpeed);
232
    PostMessage(SLV_PROGRESS_SPEED, lSpeed);
258
    // mDebugOut<<endl;
233
    // sDebugOut<<endl;
259
234
260
}
235
}
261
236
262
void Slave::slotTotalSize(KIO::Job *, KIO::filesize_t _total_size)
237
void Slave::slotTotalSize(KIO::Job *, KIO::filesize_t _total_size)
263
{
238
{
264
    mDebugIn << "= " << (unsigned long) _total_size << endl;
239
    sDebugIn << "= " << (unsigned long) _total_size << endl;
265
    PostMessage(SLV_TOTAL_SIZE, _total_size);
240
    PostMessage(SLV_TOTAL_SIZE, _total_size);
266
241
267
    PostMessage(SLV_CAN_RESUME, copyjob->getCanResume());
242
    PostMessage(SLV_CAN_RESUME, copyjob->getCanResume());
268
    PostMessage(SLV_CONNECTED);
243
    PostMessage(SLV_CONNECTED);
269
    mDebugOut << endl;
244
    sDebugOut << endl;
270
}
245
}
271
246
272
void Slave::slotProcessedSize(KIO::Job *, KIO::filesize_t _processed_size)
247
void Slave::slotProcessedSize(KIO::Job *, KIO::filesize_t _processed_size)
273
{
248
{
274
    // mDebugIn<<endl;
249
    // sDebugIn<<endl;
275
    PostMessage(SLV_PROGRESS_SIZE, _processed_size);
250
    PostMessage(SLV_PROGRESS_SIZE, _processed_size);
276
251
277
    // mDebugOut<<endl;
252
    // sDebugOut<<endl;
278
}
253
}
279
254
280
void Slave::slotInfoMessage(KIO::Job *, const QString & _msg)
255
void Slave::slotInfoMessage(KIO::Job *, const QString & _msg)
281
{
256
{
282
    mDebugIn << "MSG=" << _msg << endl;
257
    sDebugIn << "MSG=" << _msg << endl;
283
    InfoMessage(_msg);
258
    InfoMessage(_msg);
284
    mDebugOut << endl;
259
    sDebugOut << endl;
285
}
260
}
286
261
287
#include "slave.moc"
262
#include "slave.moc"
(-)kget.old/slave.h (-3 / +1 lines)
Lines 43-49 Link Here
43
43
44
class Transfer;
44
class Transfer;
45
45
46
class Slave:public QObject, public QThread
46
class Slave:public QObject
47
{
47
{
48
    Q_OBJECT 
48
    Q_OBJECT 
49
49
Lines 95-102 Link Here
95
    int nPendingCommand;
95
    int nPendingCommand;
96
96
97
    QValueStack < SlaveCommand > stack;
97
    QValueStack < SlaveCommand > stack;
98
    QWaitCondition worker;
99
    QMutex mutex;
100
    KIO::GetFileJob * copyjob;
98
    KIO::GetFileJob * copyjob;
101
99
102
};
100
};
(-)kget.old/transfer.cpp (-9 / +1 lines)
Lines 162-175 Link Here
162
{
162
{
163
    if ( m_pSlave )
163
    if ( m_pSlave )
164
    {
164
    {
165
        if ( m_pSlave->running() )
165
        m_pSlave->Op(Slave::KILL);
166
        {
167
            m_pSlave->Op(Slave::KILL);
168
            m_pSlave->wait();
169
        }
170
171
        if ( m_pSlave->running() )
172
            m_pSlave->terminate();
173
166
174
        delete m_pSlave;
167
        delete m_pSlave;
175
        m_pSlave = 0L;
168
        m_pSlave = 0L;
Lines 789-795 Link Here
789
{
782
{
790
    sDebugIn << endl;
783
    sDebugIn << endl;
791
784
792
    m_pSlave->wait();
793
    emit statusChanged(this, OP_REMOVED);
785
    emit statusChanged(this, OP_REMOVED);
794
    sDebugOut << endl;
786
    sDebugOut << endl;
795
}
787
}

Return to bug 41515