-rw-r--r-- | noncore/apps/opie-console/filetransfer.cpp | 55 | ||||
-rw-r--r-- | noncore/apps/opie-console/test/console.pro | 4 |
2 files changed, 27 insertions, 32 deletions
diff --git a/noncore/apps/opie-console/filetransfer.cpp b/noncore/apps/opie-console/filetransfer.cpp index 7fd9f37..97552fe 100644 --- a/noncore/apps/opie-console/filetransfer.cpp +++ b/noncore/apps/opie-console/filetransfer.cpp | |||
@@ -4,38 +4,26 @@ | |||
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 "filetransfer.h" | 13 | #include "filetransfer.h" |
13 | 14 | ||
14 | /** | ||
15 | * | ||
16 | * | ||
17 | class FileTransferControl { | ||
18 | public: | ||
19 | FileTransferControl(); | ||
20 | ~FileTransferControl(); | ||
21 | |||
22 | |||
23 | }; | ||
24 | */ | ||
25 | |||
26 | bool FileTransfer::terminate = false; | ||
27 | pid_t FileTransfer::m_pid; | ||
28 | 15 | ||
29 | FileTransfer::FileTransfer( Type t, IOLayer* lay ) | 16 | FileTransfer::FileTransfer( Type t, IOLayer* lay ) |
30 | : FileTransferLayer( lay ), m_type( t ) { | 17 | : FileTransferLayer( lay ), m_type( t ) { |
31 | signal(SIGPIPE, SIG_IGN ); | 18 | signal(SIGPIPE, SIG_IGN ); |
32 | signal( SIGCHLD, signal_handler ); | 19 | |
33 | m_not = 0l; | 20 | m_not = 0l; |
21 | m_proc = 0l; | ||
34 | } | 22 | } |
35 | FileTransfer::~FileTransfer() { | 23 | FileTransfer::~FileTransfer() { |
36 | } | 24 | } |
37 | 25 | ||
38 | /** | 26 | /** |
39 | * now we will send the file. | 27 | * now we will send the file. |
40 | * | 28 | * |
41 | * we request an fd. The IOLayer should be closed | 29 | * we request an fd. The IOLayer should be closed |
@@ -95,46 +83,40 @@ void FileTransfer::sendFile( const QString& file ) { | |||
95 | continue; | 83 | continue; |
96 | 84 | ||
97 | // len == 0 or something like this | 85 | // len == 0 or something like this |
98 | break; | 86 | break; |
99 | } | 87 | } |
100 | if ( m_info[0] ) | 88 | if ( m_info[0] ) |
101 | close( m_info[0] ); | 89 | close( m_info[0] ); |
102 | 90 | ||
103 | terminate = false; | 91 | |
104 | fd_set fds; | ||
105 | struct timeval timeout; | ||
106 | int sel; | ||
107 | 92 | ||
108 | /* replace by QSocketNotifier!!! */ | 93 | /* replace by QSocketNotifier!!! */ |
109 | m_not = new QSocketNotifier(m_comm[0], QSocketNotifier::Read ); | 94 | m_not = new QSocketNotifier(m_comm[0], QSocketNotifier::Read ); |
110 | connect(m_not, SIGNAL(activated(int) ), | 95 | connect(m_not, SIGNAL(activated(int) ), |
111 | this, SLOT(slotRead() ) ); | 96 | this, SLOT(slotRead() ) ); |
97 | if ( pipe(m_term) < 0 ) | ||
98 | m_term[0] = m_term[1] = 0; | ||
99 | |||
100 | ProcCtl::self()->add(m_pid, m_term[1] ); | ||
101 | m_proc = new QSocketNotifier(m_term[0], QSocketNotifier::Read ); | ||
102 | connect(m_proc, SIGNAL(activated(int) ), | ||
103 | this, SLOT(slotExec() ) ); | ||
104 | |||
112 | } | 105 | } |
113 | break; | 106 | break; |
114 | } | 107 | } |
115 | } | 108 | } |
116 | /* | 109 | /* |
117 | * let's call the one with the filename | 110 | * let's call the one with the filename |
118 | */ | 111 | */ |
119 | void FileTransfer::sendFile( const QFile& file ) { | 112 | void FileTransfer::sendFile( const QFile& file ) { |
120 | sendFile( file.name() ); | 113 | sendFile( file.name() ); |
121 | } | 114 | } |
122 | /* | ||
123 | * our signal handler to be replaced by | ||
124 | * a procctl thingie | ||
125 | */ | ||
126 | void FileTransfer::signal_handler(int ) { | ||
127 | qWarning("Terminated"); | ||
128 | int status; | ||
129 | signal( SIGCHLD, signal_handler ); | ||
130 | waitpid( m_pid, &status, WNOHANG ); | ||
131 | terminate = true; | ||
132 | } | ||
133 | 115 | ||
134 | /* | 116 | /* |
135 | * setting up communication | 117 | * setting up communication |
136 | * between parent child and ioLayer | 118 | * between parent child and ioLayer |
137 | */ | 119 | */ |
138 | void FileTransfer::setupChild() { | 120 | void FileTransfer::setupChild() { |
139 | /* | 121 | /* |
140 | * we do not want to read from our | 122 | * we do not want to read from our |
@@ -170,16 +152,17 @@ void FileTransfer::slotRead() { | |||
170 | QByteArray ar(4096); | 152 | QByteArray ar(4096); |
171 | int len = read(m_comm[0], ar.data(), 4096 ); | 153 | int len = read(m_comm[0], ar.data(), 4096 ); |
172 | qWarning("slot read %d", len); | 154 | qWarning("slot read %d", len); |
173 | for (int i = 0; i < len; i++ ) { | 155 | for (int i = 0; i < len; i++ ) { |
174 | // printf("%c", ar[i] ); | 156 | // printf("%c", ar[i] ); |
175 | } | 157 | } |
176 | ar.resize( len ); | 158 | ar.resize( len ); |
177 | QString str( ar ); | 159 | QString str( ar ); |
160 | qWarning(str.simplifyWhiteSpace() ); | ||
178 | QStringList lis = QStringList::split(' ', str ); | 161 | QStringList lis = QStringList::split(' ', str ); |
179 | /* | 162 | /* |
180 | * Transfer finished.. either complete or incomplete | 163 | * Transfer finished.. either complete or incomplete |
181 | */ | 164 | */ |
182 | if ( lis[0].simplifyWhiteSpace() == "Transfer" ) { | 165 | if ( lis[0].simplifyWhiteSpace() == "Transfer" ) { |
183 | qWarning("sent!!!!"); | 166 | qWarning("sent!!!!"); |
184 | emit sent(); | 167 | emit sent(); |
185 | return; | 168 | return; |
@@ -235,8 +218,20 @@ void FileTransfer::slotProgress( const QStringList& list ) { | |||
235 | emit progress(m_file, m_prog, bps, -1, min , sec ); | 218 | emit progress(m_file, m_prog, bps, -1, min , sec ); |
236 | } | 219 | } |
237 | 220 | ||
238 | } | 221 | } |
239 | void FileTransfer::cancel() { | 222 | void FileTransfer::cancel() { |
240 | ::kill(m_pid,9 ); | 223 | ::kill(m_pid,9 ); |
241 | delete m_not; | 224 | delete m_not; |
242 | } | 225 | } |
226 | void FileTransfer::slotExec() { | ||
227 | qWarning("exited!"); | ||
228 | char buf[2]; | ||
229 | ::read(m_term[0], buf, 1 ); | ||
230 | delete m_proc; | ||
231 | delete m_not; | ||
232 | close( m_term[0] ); | ||
233 | close( m_term[1] ); | ||
234 | close( m_comm[0] ); | ||
235 | close( m_comm[1] ); | ||
236 | emit sent(); | ||
237 | } | ||
diff --git a/noncore/apps/opie-console/test/console.pro b/noncore/apps/opie-console/test/console.pro index 9fe8e13..af0e9f7 100644 --- a/noncore/apps/opie-console/test/console.pro +++ b/noncore/apps/opie-console/test/console.pro | |||
@@ -1,15 +1,15 @@ | |||
1 | TEMPLATE = app | 1 | TEMPLATE = app |
2 | #CONFIG = qt warn_on release | 2 | #CONFIG = qt warn_on release |
3 | CONFIG = qt debug | 3 | CONFIG = qt debug |
4 | #DESTDIR = $(OPIEDIR)/bin | 4 | #DESTDIR = $(OPIEDIR)/bin |
5 | HEADERS = ../io_layer.h ../io_serial.h ../sz_transfer.h ../file_layer.h\ | 5 | HEADERS = ../io_layer.h ../io_serial.h ../sz_transfer.h ../file_layer.h\ |
6 | senderui.h ../profile.h ../filetransfer.h | 6 | senderui.h ../profile.h ../filetransfer.h ../procctl.h |
7 | SOURCES = ../io_layer.cpp ../io_serial.cpp \ | 7 | SOURCES = ../io_layer.cpp ../io_serial.cpp \ |
8 | ../profile.cpp ../sz_transfer.cpp ../file_layer.cpp\ | 8 | ../profile.cpp ../sz_transfer.cpp ../file_layer.cpp\ |
9 | main.cpp senderui.cpp ../filetransfer.cpp | 9 | main.cpp senderui.cpp ../filetransfer.cpp ../procctl.cpp |
10 | INTERFACES = sender.ui | 10 | INTERFACES = sender.ui |
11 | INCLUDEPATH += $(OPIEDIR)/include | 11 | INCLUDEPATH += $(OPIEDIR)/include |
12 | DEPENDPATH += $(OPIEDIR)/include | 12 | DEPENDPATH += $(OPIEDIR)/include |
13 | LIBS += -lqpe -lopie | 13 | LIBS += -lqpe -lopie |
14 | TARGET = test | 14 | TARGET = test |
15 | 15 | ||