Diffstat (limited to 'noncore/apps/opie-console/filetransfer.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-console/filetransfer.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/noncore/apps/opie-console/filetransfer.cpp b/noncore/apps/opie-console/filetransfer.cpp index 7eebc65..6e2d2d5 100644 --- a/noncore/apps/opie-console/filetransfer.cpp +++ b/noncore/apps/opie-console/filetransfer.cpp | |||
@@ -1,54 +1,55 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <errno.h> | 3 | #include <errno.h> |
4 | #include <fcntl.h> | 4 | #include <fcntl.h> |
5 | #include <unistd.h> | 5 | #include <unistd.h> |
6 | 6 | ||
7 | #include <opie2/odebug.h> | ||
7 | #include <qsocketnotifier.h> | 8 | #include <qsocketnotifier.h> |
8 | 9 | ||
9 | #include "procctl.h" | 10 | #include "procctl.h" |
10 | #include "filetransfer.h" | 11 | #include "filetransfer.h" |
11 | 12 | ||
12 | 13 | ||
13 | FileTransfer::FileTransfer( Type t, IOLayer* lay ) | 14 | FileTransfer::FileTransfer( Type t, IOLayer* lay ) |
14 | : FileTransferLayer( lay ), m_type( t ), m_pid ( 0 ) { | 15 | : FileTransferLayer( lay ), m_type( t ), m_pid ( 0 ) { |
15 | signal(SIGPIPE, SIG_IGN ); | 16 | signal(SIGPIPE, SIG_IGN ); |
16 | 17 | ||
17 | m_pid = 0; | 18 | m_pid = 0; |
18 | m_not = 0l; | 19 | m_not = 0l; |
19 | m_proc = 0l; | 20 | m_proc = 0l; |
20 | } | 21 | } |
21 | FileTransfer::~FileTransfer() { | 22 | FileTransfer::~FileTransfer() { |
22 | } | 23 | } |
23 | 24 | ||
24 | /** | 25 | /** |
25 | * now we will send the file. | 26 | * now we will send the file. |
26 | * | 27 | * |
27 | * we request an fd. The IOLayer should be closed | 28 | * we request an fd. The IOLayer should be closed |
28 | * then we will setup a pipe for progress communication | 29 | * then we will setup a pipe for progress communication |
29 | * then we will dup2 the m_fd in the forked process | 30 | * then we will dup2 the m_fd in the forked process |
30 | * to do direct IO from and to the fd | 31 | * to do direct IO from and to the fd |
31 | */ | 32 | */ |
32 | void FileTransfer::sendFile( const QString& file ) { | 33 | void FileTransfer::sendFile( const QString& file ) { |
33 | m_prog =-1; | 34 | m_prog =-1; |
34 | m_fd = layer()->rawIO(); | 35 | m_fd = layer()->rawIO(); |
35 | // | 36 | // |
36 | // m_fd = ::open("/dev/ttyS0", O_RDWR); | 37 | // m_fd = ::open("/dev/ttyS0", O_RDWR); |
37 | 38 | ||
38 | m_file = file; | 39 | m_file = file; |
39 | if ( pipe( m_comm ) < 0 ) | 40 | if ( pipe( m_comm ) < 0 ) |
40 | m_comm[0] = m_comm[1] = 0; | 41 | m_comm[0] = m_comm[1] = 0; |
41 | if ( pipe( m_info ) < 0 ) | 42 | if ( pipe( m_info ) < 0 ) |
42 | m_info[0] = m_info[1] = 0; | 43 | m_info[0] = m_info[1] = 0; |
43 | 44 | ||
44 | 45 | ||
45 | m_pid = fork(); | 46 | m_pid = fork(); |
46 | switch( m_pid ) { | 47 | switch( m_pid ) { |
47 | case -1: | 48 | case -1: |
48 | emit error( StartError, tr("Was not able to fork") ); | 49 | emit error( StartError, tr("Was not able to fork") ); |
49 | slotExec(); | 50 | slotExec(); |
50 | break; | 51 | break; |
51 | case 0:{ | 52 | case 0:{ |
52 | setupChild(); | 53 | setupChild(); |
53 | /* exec */ | 54 | /* exec */ |
54 | char* verbose = "-vv"; | 55 | char* verbose = "-vv"; |
@@ -189,60 +190,61 @@ void FileTransfer::slotProgress( const QStringList& list ) { | |||
189 | if ( m_type != SZ ) | 190 | if ( m_type != SZ ) |
190 | return; | 191 | return; |
191 | bool complete = true; | 192 | bool complete = true; |
192 | int min, sec; | 193 | int min, sec; |
193 | int bps; | 194 | int bps; |
194 | unsigned long sent, total; | 195 | unsigned long sent, total; |
195 | 196 | ||
196 | min = sec = bps = -1; | 197 | min = sec = bps = -1; |
197 | sent = total = 0; | 198 | sent = total = 0; |
198 | 199 | ||
199 | // Data looks like this | 200 | // Data looks like this |
200 | // 0 1 2 3 4 5 | 201 | // 0 1 2 3 4 5 |
201 | // Bytes Sent 65536/11534336 BPS:7784 ETA 24:33 | 202 | // Bytes Sent 65536/11534336 BPS:7784 ETA 24:33 |
202 | QStringList progi = QStringList::split('/', list[2].simplifyWhiteSpace() ); | 203 | QStringList progi = QStringList::split('/', list[2].simplifyWhiteSpace() ); |
203 | sent = progi[0].toULong(&complete ); | 204 | sent = progi[0].toULong(&complete ); |
204 | if (!complete ) return; | 205 | if (!complete ) return; |
205 | 206 | ||
206 | total = progi[1].toULong(&complete ); | 207 | total = progi[1].toULong(&complete ); |
207 | if (!complete || total == 0) { | 208 | if (!complete || total == 0) { |
208 | return; | 209 | return; |
209 | } | 210 | } |
210 | 211 | ||
211 | 212 | ||
212 | double pro = (double)sent/total; | 213 | double pro = (double)sent/total; |
213 | int prog = pro * 100; | 214 | int prog = pro * 100; |
214 | 215 | ||
215 | // speed | 216 | // speed |
216 | progi = QStringList::split(':', list[3].simplifyWhiteSpace() ); | 217 | progi = QStringList::split(':', list[3].simplifyWhiteSpace() ); |
217 | bps = progi[1].toInt(); | 218 | bps = progi[1].toInt(); |
218 | 219 | ||
219 | // time | 220 | // time |
220 | progi = QStringList::split(':', list[5].simplifyWhiteSpace() ); | 221 | progi = QStringList::split(':', list[5].simplifyWhiteSpace() ); |
221 | min = progi[0].toInt(); | 222 | min = progi[0].toInt(); |
222 | sec = progi[1].toInt(); | 223 | sec = progi[1].toInt(); |
223 | 224 | ||
224 | 225 | ||
225 | if ( prog > m_prog ) { | 226 | if ( prog > m_prog ) { |
226 | m_prog = prog; | 227 | m_prog = prog; |
227 | emit progress(m_file, m_prog, bps, -1, min , sec ); | 228 | emit progress(m_file, m_prog, bps, -1, min , sec ); |
228 | } | 229 | } |
229 | 230 | ||
230 | } | 231 | } |
231 | void FileTransfer::cancel() { | 232 | void FileTransfer::cancel() { |
232 | if(m_pid > 0) ::kill(m_pid,9 ); | 233 | if(m_pid > 0) ::kill(m_pid,9 ); |
233 | 234 | ||
234 | } | 235 | } |
235 | void FileTransfer::slotExec() { | 236 | void FileTransfer::slotExec() { |
236 | char buf[2]; | 237 | char buf[2]; |
237 | ::read(m_term[0], buf, 1 ); | 238 | if (::read(m_term[0], buf, 1 ) == -1) |
239 | owarn << "read of m_term[0] failed" << oendl; | ||
238 | delete m_proc; | 240 | delete m_proc; |
239 | delete m_not; | 241 | delete m_not; |
240 | m_proc = m_not = 0l; | 242 | m_proc = m_not = 0l; |
241 | close( m_term[0] ); | 243 | close( m_term[0] ); |
242 | close( m_term[1] ); | 244 | close( m_term[1] ); |
243 | close( m_comm[0] ); | 245 | close( m_comm[0] ); |
244 | close( m_comm[1] ); | 246 | close( m_comm[1] ); |
245 | layer()->closeRawIO( m_fd ); | 247 | layer()->closeRawIO( m_fd ); |
246 | emit sent(); | 248 | emit sent(); |
247 | m_pid = 0; | 249 | m_pid = 0; |
248 | } | 250 | } |