summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console/filetransfer.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-console/filetransfer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/filetransfer.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/noncore/apps/opie-console/filetransfer.cpp b/noncore/apps/opie-console/filetransfer.cpp
index 14787f6..8ca0df2 100644
--- a/noncore/apps/opie-console/filetransfer.cpp
+++ b/noncore/apps/opie-console/filetransfer.cpp
@@ -1,74 +1,76 @@
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 <qcstring.h> 7#include <qcstring.h>
8#include <qsocketnotifier.h> 8#include <qsocketnotifier.h>
9 9
10#include <opie/oprocess.h> 10#include <opie/oprocess.h>
11 11
12#include "procctl.h" 12#include "procctl.h"
13#include "filetransfer.h" 13#include "filetransfer.h"
14 14
15 15
16FileTransfer::FileTransfer( Type t, IOLayer* lay ) 16FileTransfer::FileTransfer( Type t, IOLayer* lay )
17 : FileTransferLayer( lay ), m_type( t ), m_pid ( 0 ) { 17 : FileTransferLayer( lay ), m_type( t ), m_pid ( 0 ) {
18 signal(SIGPIPE, SIG_IGN ); 18 signal(SIGPIPE, SIG_IGN );
19 19
20 m_pid = 0;
20 m_not = 0l; 21 m_not = 0l;
21 m_proc = 0l; 22 m_proc = 0l;
22} 23}
23FileTransfer::~FileTransfer() { 24FileTransfer::~FileTransfer() {
24} 25}
25 26
26/** 27/**
27 * now we will send the file. 28 * now we will send the file.
28 * 29 *
29 * we request an fd. The IOLayer should be closed 30 * we request an fd. The IOLayer should be closed
30 * then we will setup a pipe for progress communication 31 * then we will setup a pipe for progress communication
31 * then we will dup2 the m_fd in the forked process 32 * then we will dup2 the m_fd in the forked process
32 * to do direct IO from and to the fd 33 * to do direct IO from and to the fd
33 */ 34 */
34void FileTransfer::sendFile( const QString& file ) { 35void FileTransfer::sendFile( const QString& file ) {
35 m_prog =-1; 36 m_prog =-1;
36 m_fd = layer()->rawIO(); 37 m_fd = layer()->rawIO();
37// 38//
38// m_fd = ::open("/dev/ttyS0", O_RDWR); 39// m_fd = ::open("/dev/ttyS0", O_RDWR);
39 40
40 m_file = file; 41 m_file = file;
41 if ( pipe( m_comm ) < 0 ) 42 if ( pipe( m_comm ) < 0 )
42 m_comm[0] = m_comm[1] = 0; 43 m_comm[0] = m_comm[1] = 0;
43 if ( pipe( m_info ) < 0 ) 44 if ( pipe( m_info ) < 0 )
44 m_info[0] = m_info[1] = 0; 45 m_info[0] = m_info[1] = 0;
45 46
46 47
47 m_pid = fork(); 48 m_pid = fork();
48 switch( m_pid ) { 49 switch( m_pid ) {
49 case -1: 50 case -1:
50 emit error( StartError, tr("Was not able to fork") ); 51 emit error( StartError, tr("Was not able to fork") );
52 slotExec();
51 break; 53 break;
52 case 0:{ 54 case 0:{
53 setupChild(); 55 setupChild();
54 qWarning("output:"+file ); 56 qWarning("output:"+file );
55 /* exec */ 57 /* exec */
56 char* verbose = "-vv"; 58 char* verbose = "-vv";
57 char* binray = "-b"; 59 char* binray = "-b";
58 60
59 61
60 char* typus; 62 char* typus;
61 switch(m_type ) { 63 switch(m_type ) {
62 case SZ: 64 case SZ:
63 typus = ""; 65 typus = "";
64 break; 66 break;
65 case SX: 67 case SX:
66 typus = "-X"; 68 typus = "-X";
67 break; 69 break;
68 case SY: 70 case SY:
69 typus = "--ymodem"; 71 typus = "--ymodem";
70 break; 72 break;
71 } 73 }
72 74
73 /* we should never return from here */ 75 /* we should never return from here */
74 execlp("sz", "sz", verbose, binray, file.latin1(), typus, NULL ); 76 execlp("sz", "sz", verbose, binray, file.latin1(), typus, NULL );
@@ -156,49 +158,48 @@ void FileTransfer::setupChild() {
156 dup2( m_fd, STDOUT_FILENO ); 158 dup2( m_fd, STDOUT_FILENO );
157 dup2( m_comm[1], STDERR_FILENO ); 159 dup2( m_comm[1], STDERR_FILENO );
158} 160}
159 161
160/* 162/*
161 * read from the stderr of the child 163 * read from the stderr of the child
162 * process 164 * process
163 */ 165 */
164void FileTransfer::slotRead() { 166void FileTransfer::slotRead() {
165 QByteArray ar(4096); 167 QByteArray ar(4096);
166 int len = read(m_comm[0], ar.data(), 4096 ); 168 int len = read(m_comm[0], ar.data(), 4096 );
167 qWarning("slot read %d", len); 169 qWarning("slot read %d", len);
168 for (int i = 0; i < len; i++ ) { 170 for (int i = 0; i < len; i++ ) {
169 // printf("%c", ar[i] ); 171 // printf("%c", ar[i] );
170 } 172 }
171 ar.resize( len ); 173 ar.resize( len );
172 QString str( ar ); 174 QString str( ar );
173 qWarning(str.simplifyWhiteSpace() ); 175 qWarning(str.simplifyWhiteSpace() );
174 QStringList lis = QStringList::split(' ', str ); 176 QStringList lis = QStringList::split(' ', str );
175 /* 177 /*
176 * Transfer finished.. either complete or incomplete 178 * Transfer finished.. either complete or incomplete
177 */ 179 */
178 if ( lis[0].simplifyWhiteSpace() == "Transfer" ) { 180 if ( lis[0].simplifyWhiteSpace() == "Transfer" ) {
179 qWarning("sent!!!!"); 181 qWarning("sent!!!!");
180 emit sent();
181 return; 182 return;
182 } 183 }
183 /* 184 /*
184 * do progress reading 185 * do progress reading
185 */ 186 */
186 slotProgress( lis ); 187 slotProgress( lis );
187 188
188 189
189} 190}
190/* 191/*
191 * find the progress 192 * find the progress
192 */ 193 */
193void FileTransfer::slotProgress( const QStringList& list ) { 194void FileTransfer::slotProgress( const QStringList& list ) {
194 if ( m_type != SZ ) 195 if ( m_type != SZ )
195 return; 196 return;
196 bool complete = true; 197 bool complete = true;
197 int min, sec; 198 int min, sec;
198 int bps; 199 int bps;
199 unsigned long sent, total; 200 unsigned long sent, total;
200 201
201 min = sec = bps = -1; 202 min = sec = bps = -1;
202 sent = total = 0; 203 sent = total = 0;
203 204
204 // Data looks like this 205 // Data looks like this
@@ -215,39 +216,41 @@ void FileTransfer::slotProgress( const QStringList& list ) {
215 216
216 qWarning("%s, %d, %d", progi.join("/").latin1(), sent, total ); 217 qWarning("%s, %d, %d", progi.join("/").latin1(), sent, total );
217 218
218 double pro = (double)sent/total; 219 double pro = (double)sent/total;
219 int prog = pro * 100; 220 int prog = pro * 100;
220 221
221 // speed 222 // speed
222 progi = QStringList::split(':', list[3].simplifyWhiteSpace() ); 223 progi = QStringList::split(':', list[3].simplifyWhiteSpace() );
223 bps = progi[1].toInt(); 224 bps = progi[1].toInt();
224 225
225 // time 226 // time
226 progi = QStringList::split(':', list[5].simplifyWhiteSpace() ); 227 progi = QStringList::split(':', list[5].simplifyWhiteSpace() );
227 min = progi[0].toInt(); 228 min = progi[0].toInt();
228 sec = progi[1].toInt(); 229 sec = progi[1].toInt();
229 230
230 231
231 if ( prog > m_prog ) { 232 if ( prog > m_prog ) {
232 m_prog = prog; 233 m_prog = prog;
233 emit progress(m_file, m_prog, bps, -1, min , sec ); 234 emit progress(m_file, m_prog, bps, -1, min , sec );
234 } 235 }
235 236
236} 237}
237void FileTransfer::cancel() { 238void FileTransfer::cancel() {
238 if(m_pid > 0) ::kill(m_pid,9 ); 239 if(m_pid > 0) ::kill(m_pid,9 );
239 delete m_not; 240
240} 241}
241void FileTransfer::slotExec() { 242void FileTransfer::slotExec() {
242 qWarning("exited!"); 243 qWarning("exited!");
243 char buf[2]; 244 char buf[2];
244 ::read(m_term[0], buf, 1 ); 245 ::read(m_term[0], buf, 1 );
245 delete m_proc; 246 delete m_proc;
246 delete m_not; 247 delete m_not;
247 m_proc = m_not = 0l; 248 m_proc = m_not = 0l;
248 close( m_term[0] ); 249 close( m_term[0] );
249 close( m_term[1] ); 250 close( m_term[1] );
250 close( m_comm[0] ); 251 close( m_comm[0] );
251 close( m_comm[1] ); 252 close( m_comm[1] );
253 layer()->closeRawIO( m_fd );
252 emit sent(); 254 emit sent();
255 m_pid = 0;
253} 256}