summaryrefslogtreecommitdiff
authorzecke <zecke>2002-10-13 15:31:12 (UTC)
committer zecke <zecke>2002-10-13 15:31:12 (UTC)
commit6a9726437a59cf3b18bf57d6e20fb2dfaaa2fc34 (patch) (unidiff)
tree14fa6710ef6d80fa213250a97f13253eb88a80cd
parent5db679753dac04095a2fa4b03297785ed4ba4030 (diff)
downloadopie-6a9726437a59cf3b18bf57d6e20fb2dfaaa2fc34.zip
opie-6a9726437a59cf3b18bf57d6e20fb2dfaaa2fc34.tar.gz
opie-6a9726437a59cf3b18bf57d6e20fb2dfaaa2fc34.tar.bz2
Move some stuff in filetransfer around
make pid == 0 after a finished process. Introduce the FileReceive class it does not parse progress though
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/filereceive.cpp159
-rw-r--r--noncore/apps/opie-console/filereceive.h42
-rw-r--r--noncore/apps/opie-console/filetransfer.cpp7
-rw-r--r--noncore/apps/opie-console/opie-console.pro8
-rw-r--r--noncore/apps/opie-console/receive_layer.cpp33
-rw-r--r--noncore/apps/opie-console/receive_layer.h22
-rw-r--r--noncore/apps/opie-console/test/console.pro6
-rw-r--r--noncore/apps/opie-console/test/sender.ui22
-rw-r--r--noncore/apps/opie-console/test/senderui.cpp7
-rw-r--r--noncore/apps/opie-console/test/senderui.h1
10 files changed, 292 insertions, 15 deletions
diff --git a/noncore/apps/opie-console/filereceive.cpp b/noncore/apps/opie-console/filereceive.cpp
new file mode 100644
index 0000000..26b3dec
--- a/dev/null
+++ b/noncore/apps/opie-console/filereceive.cpp
@@ -0,0 +1,159 @@
1#include <unistd.h>
2#include <fcntl.h>
3#include <signal.h>
4#include <errno.h>
5
6#include <qsocketnotifier.h>
7
8#include "io_layer.h"
9#include "procctl.h"
10#include "filereceive.h"
11
12FileReceive::FileReceive( Type t, IOLayer* lay, const QString& dir )
13 : ReceiveLayer(lay, dir ), m_type( t )
14{
15 m_fd = -1;
16 m_not = 0l;
17 m_proc = 0l;
18}
19FileReceive::~FileReceive() {
20}
21void FileReceive::receive() {
22 receive( currentDir() );
23}
24void FileReceive::receive( const QString& dir ) {
25 m_prog = -1;
26 m_fd = layer()->rawIO();
27 m_curDir = dir;
28
29 if (pipe( m_comm ) < 0 )
30 m_comm[0] = m_comm[1] = 0;
31 if (pipe( m_info ) < 0 )
32 m_info[0] = m_info[1] = 0;
33
34 m_pid = fork();
35 switch( m_pid ) {
36 case -1:
37 //emit error
38 slotExec();
39 break;
40 /* child */
41 case 0: {
42 setupChild();
43 char* typus = NULL;
44 switch(m_type ) {
45 case SZ:
46 break;
47 case SX:
48 typus = "-X";
49 break;
50 case SY:
51 typus = "--ymodem";
52 break;
53 }
54
55 /* we should never return from here */
56 execlp("rz", "rz", typus, NULL );
57
58 char resultByte = 1;
59 if (m_info[1] )
60 ::write(m_info[1], &resultByte, 1 );
61
62 _exit( -1 );
63 break;
64 }
65 default: {
66 if ( m_info[1] )
67 close( m_info[1] );
68
69 if ( m_info[0] ) for (;;) {
70 char resultByte; int len;
71 len = read(m_info[0], &resultByte, 1 );
72 /* len == 1 start up failed */
73 if ( len == 1 ) {
74 emit error( StartError, tr("Could not start") );
75 return;
76 }
77 if ( len == -1 )
78 if ( (errno == ECHILD ) || (errno == EINTR ) )
79 continue;
80
81 // len == 0 or something like this
82 break;
83 }
84
85 if ( m_info[0] )
86 close( m_info[0] );
87
88 m_not = new QSocketNotifier(m_comm[0], QSocketNotifier::Read );
89 connect(m_not, SIGNAL(activated(int) ),
90 this, SLOT(slotRead() ) );
91 if ( pipe(m_term) < 0 )
92 m_term[0] = m_term[1] = 0;
93
94 ProcCtl::self()->add(m_pid, m_term[1] );
95 m_proc = new QSocketNotifier(m_term[0], QSocketNotifier::Read );
96 connect(m_proc, SIGNAL(activated(int) ),
97 this, SLOT(slotExec() ) );
98
99 }
100 break;
101
102 }
103
104}
105void FileReceive::cancel() {
106 ::kill(m_pid, 9 );
107}
108void FileReceive::setupChild() {
109 changeDir( currentDir() );
110 /*
111 * we do not want to read from our
112 * information channel
113 */
114 if (m_info[0] )
115 close(m_info[0] );
116 /*
117 * FD_CLOEXEC will close the
118 * fd on successfull exec
119 */
120 if (m_info[1] )
121 fcntl(m_info[1], F_SETFD, FD_CLOEXEC );
122
123 if (m_comm[0] )
124 close( m_comm[0] );
125 /*
126 * now set the communication
127 * m_fd STDIN_FILENO
128 * STDOUT_FILENO
129 * STDERR_FILENO
130 */
131 dup2( m_fd, STDIN_FILENO );
132 dup2( m_fd, STDOUT_FILENO );
133 dup2( m_comm[1], STDERR_FILENO );
134}
135void FileReceive::slotRead() {
136 QByteArray ar(4096);
137 int len = read(m_comm[0], ar.data(), 4096 );
138 qWarning("slot read %d", len);
139 for (int i = 0; i < len; i++ ) {
140 // printf("%c", ar[i] );
141 }
142 ar.resize( len );
143 QString str( ar );
144 qWarning(str.simplifyWhiteSpace() );
145}
146void FileReceive::slotExec() {
147 char buf[2];
148 ::read(m_term[0], buf, 1 );
149 delete m_proc;
150 delete m_not;
151 m_not = m_proc = 0l;
152 close( m_term[0] );
153 close( m_term[1] );
154 close( m_comm[0] );
155 close( m_comm[1] );
156 layer()->closeRawIO(m_fd);
157 emit received(QString::null);
158
159}
diff --git a/noncore/apps/opie-console/filereceive.h b/noncore/apps/opie-console/filereceive.h
new file mode 100644
index 0000000..a525439
--- a/dev/null
+++ b/noncore/apps/opie-console/filereceive.h
@@ -0,0 +1,42 @@
1#ifndef OPIE_FILE_RECEIVE_H
2#define OPIE_FILE_RECEIVE_H
3
4/**
5 * This is the receive Implementation
6 * for X-Modem/Y-Modem/Z-Modem
7 */
8#include <sys/types.h>
9
10#include "receive_layer.h"
11
12class QSocketNotifier;
13class FileReceive : public ReceiveLayer {
14 Q_OBJECT
15public:
16 enum Type {
17 SZ = 0,
18 SX,
19 SY
20 };
21 FileReceive( Type t, IOLayer* lay, const QString& startDir = QString::null );
22 ~FileReceive();
23 void receive();
24 void receive( const QString& dir );
25 void cancel();
26private slots:
27 void setupChild();
28 void slotRead();
29 void slotExec();
30private:
31 pid_t m_pid;
32 int m_fd;
33 int m_prog;
34 int m_info[2];
35 int m_comm[2];
36 int m_term[2];
37 Type m_type;
38 QSocketNotifier* m_not;
39 QSocketNotifier* m_proc;
40};
41
42#endif
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
@@ -17,6 +17,7 @@ FileTransfer::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}
@@ -48,6 +49,7 @@ void FileTransfer::sendFile( const QString& file ) {
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();
@@ -177,7 +179,6 @@ void FileTransfer::slotRead() {
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 /*
@@ -236,7 +237,7 @@ void FileTransfer::slotProgress( const QStringList& list ) {
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!");
@@ -249,5 +250,7 @@ void FileTransfer::slotExec() {
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}
diff --git a/noncore/apps/opie-console/opie-console.pro b/noncore/apps/opie-console/opie-console.pro
index 8e39a48..0b4676b 100644
--- a/noncore/apps/opie-console/opie-console.pro
+++ b/noncore/apps/opie-console/opie-console.pro
@@ -30,7 +30,9 @@ HEADERS = io_layer.h io_serial.h io_irda.h io_bt.h\
30 btconfigwidget.h modemconfigwidget.h \ 30 btconfigwidget.h modemconfigwidget.h \
31 atconfigdialog.h dialdialog.h \ 31 atconfigdialog.h dialdialog.h \
32 emulation_widget.h procctl.h \ 32 emulation_widget.h procctl.h \
33 function_keyboard.h script.h 33 function_keyboard.h \
34 receive_layer.h filereceive.h \
35 script.h
34 36
35SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp io_bt.cpp \ 37SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp io_bt.cpp \
36 file_layer.cpp filetransfer.cpp \ 38 file_layer.cpp filetransfer.cpp \
@@ -58,7 +60,9 @@ SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp io_bt.cpp \
58 btconfigwidget.cpp modemconfigwidget.cpp \ 60 btconfigwidget.cpp modemconfigwidget.cpp \
59 atconfigdialog.cpp dialdialog.cpp \ 61 atconfigdialog.cpp dialdialog.cpp \
60 emulation_widget.cpp default.cpp procctl.cpp \ 62 emulation_widget.cpp default.cpp procctl.cpp \
61 function_keyboard.cpp script.cpp 63 function_keyboard.cpp \
64 receive_layer.cpp filereceive.cpp \
65 script.cpp
62 66
63INTERFACES = configurebase.ui editbase.ui 67INTERFACES = configurebase.ui editbase.ui
64INCLUDEPATH += $(OPIEDIR)/include 68INCLUDEPATH += $(OPIEDIR)/include
diff --git a/noncore/apps/opie-console/receive_layer.cpp b/noncore/apps/opie-console/receive_layer.cpp
new file mode 100644
index 0000000..05e2c67
--- a/dev/null
+++ b/noncore/apps/opie-console/receive_layer.cpp
@@ -0,0 +1,33 @@
1#include <unistd.h>
2
3#include <qstring.h>
4#include <qfile.h>
5
6#include "io_layer.h"
7#include "receive_layer.h"
8
9ReceiveLayer::ReceiveLayer( IOLayer* lay, const QString& startDir )
10 : QObject(), m_curDir( startDir ), m_layer(lay )
11{
12
13}
14ReceiveLayer::~ReceiveLayer() {
15
16}
17IOLayer* ReceiveLayer::layer() {
18 return m_layer;
19}
20QString ReceiveLayer::currentDir()const{
21 if (m_curDir.isEmpty() )
22 return QString::fromLocal8Bit( ::getwd(NULL) );
23 return m_curDir;
24}
25void ReceiveLayer::changeDir( const QString& str) {
26 ::chdir( str.latin1() );
27}
28void ReceiveLayer::receive( const QString& dir, Mode, Features ) {
29 receive( dir );
30}
31void ReceiveLayer::cancel() {
32
33}
diff --git a/noncore/apps/opie-console/receive_layer.h b/noncore/apps/opie-console/receive_layer.h
index 0cfe16d..157c7e5 100644
--- a/noncore/apps/opie-console/receive_layer.h
+++ b/noncore/apps/opie-console/receive_layer.h
@@ -45,12 +45,11 @@ public:
45 }; 45 };
46 46
47 /** 47 /**
48 * which protocol to use? 48 * Error codes
49 */ 49 */
50 enum Type{ 50 enum Error {
51 SZ = 0, 51 Unknown = 0,
52 SX, 52 StartError
53 SY
54 }; 53 };
55 54
56 /** 55 /**
@@ -59,7 +58,7 @@ public:
59 * @param t The Type 58 * @param t The Type
60 * @param startDir In which dir should files be received? 59 * @param startDir In which dir should files be received?
61 */ 60 */
62 ReceiveLayer( IOLayer* lay, Type t, const QString& startDir = QString::null ); 61 ReceiveLayer( IOLayer* lay, const QString& startDir = QString::null );
63 virtual ~ReceiveLayer(); 62 virtual ~ReceiveLayer();
64 63
65public slots: 64public slots:
@@ -78,7 +77,7 @@ public slots:
78 /** 77 /**
79 * advanced method with features and Mode 78 * advanced method with features and Mode
80 */ 79 */
81 virtual void receive( const QString& dir, Mode, Features ) {} 80 virtual void receive( const QString& dir, Mode, Features );
82 81
83 /** 82 /**
84 * cancel receive 83 * cancel receive
@@ -108,6 +107,15 @@ signals:
108 */ 107 */
109 void received( const QString& file ); 108 void received( const QString& file );
110 109
110protected:
111 QString m_curDir;
112 IOLayer* layer();
113 /* from a variable set from the outside */
114 QString currentDir()const;
115 void changeDir( const QString& );
116private:
117 IOLayer* m_layer;
118
111}; 119};
112 120
113#endif 121#endif
diff --git a/noncore/apps/opie-console/test/console.pro b/noncore/apps/opie-console/test/console.pro
index af0e9f7..6de2cd0 100644
--- a/noncore/apps/opie-console/test/console.pro
+++ b/noncore/apps/opie-console/test/console.pro
@@ -3,10 +3,12 @@ TEMPLATE = app
3 CONFIG = qt debug 3 CONFIG = qt debug
4#DESTDIR = $(OPIEDIR)/bin 4#DESTDIR = $(OPIEDIR)/bin
5HEADERS = ../io_layer.h ../io_serial.h ../sz_transfer.h ../file_layer.h\ 5HEADERS = ../io_layer.h ../io_serial.h ../sz_transfer.h ../file_layer.h\
6 senderui.h ../profile.h ../filetransfer.h ../procctl.h 6 senderui.h ../profile.h ../filetransfer.h ../procctl.h \
7 ../filereceive.h ../receive_layer.h
7SOURCES = ../io_layer.cpp ../io_serial.cpp \ 8SOURCES = ../io_layer.cpp ../io_serial.cpp \
8 ../profile.cpp ../sz_transfer.cpp ../file_layer.cpp\ 9 ../profile.cpp ../sz_transfer.cpp ../file_layer.cpp\
9 main.cpp senderui.cpp ../filetransfer.cpp ../procctl.cpp 10 main.cpp senderui.cpp ../filetransfer.cpp ../procctl.cpp \
11 ../filereceive.cpp ../receive_layer.cpp
10INTERFACES = sender.ui 12INTERFACES = sender.ui
11INCLUDEPATH += $(OPIEDIR)/include 13INCLUDEPATH += $(OPIEDIR)/include
12DEPENDPATH += $(OPIEDIR)/include 14DEPENDPATH += $(OPIEDIR)/include
diff --git a/noncore/apps/opie-console/test/sender.ui b/noncore/apps/opie-console/test/sender.ui
index b946b81..74b9790 100644
--- a/noncore/apps/opie-console/test/sender.ui
+++ b/noncore/apps/opie-console/test/sender.ui
@@ -11,7 +11,7 @@
11 <rect> 11 <rect>
12 <x>0</x> 12 <x>0</x>
13 <y>0</y> 13 <y>0</y>
14 <width>596</width> 14 <width>592</width>
15 <height>480</height> 15 <height>480</height>
16 </rect> 16 </rect>
17 </property> 17 </property>
@@ -39,6 +39,17 @@
39 <class>QPushButton</class> 39 <class>QPushButton</class>
40 <property stdset="1"> 40 <property stdset="1">
41 <name>name</name> 41 <name>name</name>
42 <cstring>PushButton3</cstring>
43 </property>
44 <property stdset="1">
45 <name>text</name>
46 <string>Receive File</string>
47 </property>
48 </widget>
49 <widget>
50 <class>QPushButton</class>
51 <property stdset="1">
52 <name>name</name>
42 <cstring>PushButton1</cstring> 53 <cstring>PushButton1</cstring>
43 </property> 54 </property>
44 <property stdset="1"> 55 <property stdset="1">
@@ -66,13 +77,20 @@
66 <receiver>Form1</receiver> 77 <receiver>Form1</receiver>
67 <slot>slotSend()</slot> 78 <slot>slotSend()</slot>
68 </connection> 79 </connection>
69 <slot access="public">slotSend()</slot>
70 <connection> 80 <connection>
71 <sender>PushButton2</sender> 81 <sender>PushButton2</sender>
72 <signal>clicked()</signal> 82 <signal>clicked()</signal>
73 <receiver>Form1</receiver> 83 <receiver>Form1</receiver>
74 <slot>slotSendFile()</slot> 84 <slot>slotSendFile()</slot>
75 </connection> 85 </connection>
86 <connection>
87 <sender>PushButton3</sender>
88 <signal>clicked()</signal>
89 <receiver>Form1</receiver>
90 <slot>slotRev()</slot>
91 </connection>
92 <slot access="public">slotRev()</slot>
93 <slot access="public">slotSend()</slot>
76 <slot access="public">slotSendFile()</slot> 94 <slot access="public">slotSendFile()</slot>
77</connections> 95</connections>
78</UI> 96</UI>
diff --git a/noncore/apps/opie-console/test/senderui.cpp b/noncore/apps/opie-console/test/senderui.cpp
index 8bc1676..2ce3f6d 100644
--- a/noncore/apps/opie-console/test/senderui.cpp
+++ b/noncore/apps/opie-console/test/senderui.cpp
@@ -9,6 +9,7 @@
9#include "../profile.h" 9#include "../profile.h"
10#include "../io_serial.h" 10#include "../io_serial.h"
11#include "../filetransfer.h" 11#include "../filetransfer.h"
12#include "../filereceive.h"
12 13
13#include <opie/oprocess.h> 14#include <opie/oprocess.h>
14 15
@@ -66,3 +67,9 @@ void SenderUI::fileTransComplete() {
66void SenderUI::send() { 67void SenderUI::send() {
67 68
68} 69}
70void SenderUI::slotRev(){
71qWarning("Going to receive!");
72FileReceive *rev = new FileReceive( FileReceive::SZ, ser );
73rev->receive();
74
75} \ No newline at end of file
diff --git a/noncore/apps/opie-console/test/senderui.h b/noncore/apps/opie-console/test/senderui.h
index 5e613cd..c130dcf 100644
--- a/noncore/apps/opie-console/test/senderui.h
+++ b/noncore/apps/opie-console/test/senderui.h
@@ -19,6 +19,7 @@ public slots:
19 void send(); 19 void send();
20 void slotSendFile(); 20 void slotSendFile();
21 void slotSend(); 21 void slotSend();
22 void slotRev();
22 void got(const QByteArray& ); 23 void got(const QByteArray& );
23 void fileTransComplete(); 24 void fileTransComplete();
24private: 25private: