-rw-r--r-- | noncore/apps/opie-console/filetransfer.cpp | 142 | ||||
-rw-r--r-- | noncore/apps/opie-console/filetransfer.h | 38 | ||||
-rw-r--r-- | noncore/apps/opie-console/io_layer.cpp | 3 | ||||
-rw-r--r-- | noncore/apps/opie-console/io_layer.h | 7 | ||||
-rw-r--r-- | noncore/apps/opie-console/io_serial.cpp | 7 | ||||
-rw-r--r-- | noncore/apps/opie-console/io_serial.h | 1 | ||||
-rw-r--r-- | noncore/apps/opie-console/sz_transfer.cpp | 121 |
7 files changed, 212 insertions, 107 deletions
diff --git a/noncore/apps/opie-console/filetransfer.cpp b/noncore/apps/opie-console/filetransfer.cpp new file mode 100644 index 0000000..78982bd --- a/dev/null +++ b/noncore/apps/opie-console/filetransfer.cpp | |||
@@ -0,0 +1,142 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <errno.h> | ||
4 | #include <fcntl.h> | ||
5 | #include <unistd.h> | ||
6 | |||
7 | #include <qcstring.h> | ||
8 | #include <qsocketnotifier.h> | ||
9 | |||
10 | #include <opie/oprocess.h> | ||
11 | |||
12 | #include "filetransfer.h" | ||
13 | |||
14 | bool FileTransfer::terminate = false; | ||
15 | pid_t FileTransfer::m_pid; | ||
16 | |||
17 | FileTransfer::FileTransfer( Type t, IOLayer* lay ) | ||
18 | : FileTransferLayer( lay ), m_type( t ) { | ||
19 | signal( SIGCHLD, signal_handler ); | ||
20 | } | ||
21 | FileTransfer::~FileTransfer() { | ||
22 | } | ||
23 | |||
24 | /** | ||
25 | * now we will send the file. | ||
26 | * | ||
27 | * we request an fd. The IOLayer should be closed | ||
28 | * then we will setup a pipe for progress communication | ||
29 | * then we will dup2 the m_fd in the forked process | ||
30 | * to do direct IO from and to the fd | ||
31 | */ | ||
32 | void FileTransfer::sendFile( const QString& file ) { | ||
33 | m_fd = layer()->rawIO(); | ||
34 | // | ||
35 | // m_fd = ::open("/dev/ttyS0", O_RDWR); | ||
36 | |||
37 | |||
38 | if ( pipe( m_comm ) < 0 ) | ||
39 | m_comm[0] = m_comm[1] = 0; | ||
40 | if ( pipe( m_info ) < 0 ) | ||
41 | m_info[0] = m_info[1] = 0; | ||
42 | |||
43 | qWarning("output:"+file ); | ||
44 | m_pid = fork(); | ||
45 | switch( m_pid ) { | ||
46 | case 0:{ | ||
47 | setupChild(); | ||
48 | /* exec */ | ||
49 | char* verbose = "-vv"; | ||
50 | char* binray = "-b"; | ||
51 | |||
52 | |||
53 | /* we should never return from here */ | ||
54 | execlp("sz", "sz", verbose, binray, file.latin1(), NULL ); | ||
55 | |||
56 | /* communication for error!*/ | ||
57 | char resultByte =1; | ||
58 | if (m_info[1] ) | ||
59 | write(m_info[1], &resultByte, 1 ); | ||
60 | _exit( -1 ); | ||
61 | break; | ||
62 | } | ||
63 | default:{ | ||
64 | if ( m_info[1] ) | ||
65 | close( m_info[1] ); | ||
66 | if ( m_info[0] ) for (;;) { | ||
67 | char resultByte; int len; | ||
68 | len = read(m_info[0], &resultByte, 1 ); | ||
69 | /* len == 1 start up failed */ | ||
70 | if ( len == 1 ) | ||
71 | return; | ||
72 | if ( len == -1 ) | ||
73 | if ( (errno == ECHILD ) || (errno == EINTR ) ) | ||
74 | continue; | ||
75 | |||
76 | // len == 0 or something like this | ||
77 | break; | ||
78 | } | ||
79 | if ( m_info[0] ) | ||
80 | close( m_info[0] ); | ||
81 | |||
82 | terminate = false; | ||
83 | fd_set fds; | ||
84 | struct timeval timeout; | ||
85 | int sel; | ||
86 | |||
87 | /* replace by QSocketNotifier!!! */ | ||
88 | while (!terminate) { | ||
89 | FD_ZERO( &fds ); | ||
90 | FD_SET( m_comm[0], &fds ); | ||
91 | sel = select( m_comm[0]+1, &fds, NULL, NULL, &timeout ); | ||
92 | if (sel ) { | ||
93 | if ( FD_ISSET(m_comm[0], &fds ) ) { | ||
94 | printf("out:"); | ||
95 | QByteArray ar(4096); | ||
96 | int len = read(m_comm[0], ar.data(), 4096 ); | ||
97 | for (int i = 0; i < len; i++ ) { | ||
98 | // printf("%c", ar[i] ); | ||
99 | } | ||
100 | printf("\n"); | ||
101 | } | ||
102 | } | ||
103 | } | ||
104 | break; | ||
105 | } | ||
106 | } | ||
107 | } | ||
108 | void FileTransfer::sendFile( const QFile& file ) { | ||
109 | sendFile( file.name() ); | ||
110 | } | ||
111 | void FileTransfer::signal_handler(int ) { | ||
112 | int status; | ||
113 | signal( SIGCHLD, signal_handler ); | ||
114 | waitpid( m_pid, &status, WNOHANG ); | ||
115 | terminate = true; | ||
116 | } | ||
117 | void FileTransfer::setupChild() { | ||
118 | /* | ||
119 | * we do not want to read from our | ||
120 | * information channel | ||
121 | */ | ||
122 | if (m_info[0] ) | ||
123 | close(m_info[0] ); | ||
124 | /* | ||
125 | * FD_CLOEXEC will close the | ||
126 | * fd on successfull exec | ||
127 | */ | ||
128 | if (m_info[1] ) | ||
129 | fcntl(m_info[1], F_SETFD, FD_CLOEXEC ); | ||
130 | |||
131 | if (m_comm[0] ) | ||
132 | close( m_comm[0] ); | ||
133 | /* | ||
134 | * now set the communication | ||
135 | * m_fd STDIN_FILENO | ||
136 | * STDOUT_FILENO | ||
137 | * STDERR_FILENO | ||
138 | */ | ||
139 | dup2( m_fd, STDIN_FILENO ); | ||
140 | dup2( m_fd, STDOUT_FILENO ); | ||
141 | dup2( m_comm[1], STDERR_FILENO ); | ||
142 | } | ||
diff --git a/noncore/apps/opie-console/filetransfer.h b/noncore/apps/opie-console/filetransfer.h new file mode 100644 index 0000000..06c6d12 --- a/dev/null +++ b/noncore/apps/opie-console/filetransfer.h | |||
@@ -0,0 +1,38 @@ | |||
1 | #ifndef OPIE_FILE_TRANSFER_H | ||
2 | #define OPIE_FILE_TRANSFER_H | ||
3 | |||
4 | #include <sys/types.h> | ||
5 | |||
6 | #include <qfile.h> | ||
7 | |||
8 | #include "file_layer.h" | ||
9 | |||
10 | class QSocketNotifier; | ||
11 | class OProcess; | ||
12 | class FileTransfer : public FileTransferLayer{ | ||
13 | Q_OBJECT | ||
14 | public: | ||
15 | enum Type { | ||
16 | SZ = 0, | ||
17 | SX, | ||
18 | SY | ||
19 | }; | ||
20 | FileTransfer( Type t, IOLayer* ); | ||
21 | ~FileTransfer(); | ||
22 | |||
23 | void sendFile( const QString& file ); | ||
24 | void sendFile( const QFile& ); | ||
25 | |||
26 | private slots: | ||
27 | void setupChild(); | ||
28 | private: | ||
29 | static pid_t m_pid; | ||
30 | int m_fd; | ||
31 | int m_info[2]; | ||
32 | int m_comm[2]; | ||
33 | Type m_type; | ||
34 | static void signal_handler(int); | ||
35 | static bool terminate; | ||
36 | }; | ||
37 | |||
38 | #endif | ||
diff --git a/noncore/apps/opie-console/io_layer.cpp b/noncore/apps/opie-console/io_layer.cpp index 563a252..79d47f5 100644 --- a/noncore/apps/opie-console/io_layer.cpp +++ b/noncore/apps/opie-console/io_layer.cpp | |||
@@ -14 +14,4 @@ IOLayer::~IOLayer() { | |||
14 | } | 14 | } |
15 | int IOLayer::rawIO()const{ | ||
16 | return -1; | ||
17 | } | ||
diff --git a/noncore/apps/opie-console/io_layer.h b/noncore/apps/opie-console/io_layer.h index b891b2b..7745021 100644 --- a/noncore/apps/opie-console/io_layer.h +++ b/noncore/apps/opie-console/io_layer.h | |||
@@ -51,2 +51,9 @@ public: | |||
51 | virtual QString name() const = 0; | 51 | virtual QString name() const = 0; |
52 | |||
53 | /** | ||
54 | * a file descriptor which opens | ||
55 | * the device for io but does not | ||
56 | * do any ioctling on it... | ||
57 | */ | ||
58 | virtual int rawIO()const; | ||
52 | signals: | 59 | signals: |
diff --git a/noncore/apps/opie-console/io_serial.cpp b/noncore/apps/opie-console/io_serial.cpp index 929aeff..845f4be 100644 --- a/noncore/apps/opie-console/io_serial.cpp +++ b/noncore/apps/opie-console/io_serial.cpp | |||
@@ -159,3 +159,3 @@ void IOSerial::errorOccured() { | |||
159 | void IOSerial::dataArrived() { | 159 | void IOSerial::dataArrived() { |
160 | QByteArray array(4096); | 160 | QByteArray array(4097); |
161 | 161 | ||
@@ -177 +177,6 @@ QString IOSerial::name() const { | |||
177 | } | 177 | } |
178 | int IOSerial::rawIO()const { | ||
179 | int fd = ::open(m_device, O_RDWR ); | ||
180 | |||
181 | return fd; | ||
182 | }; | ||
diff --git a/noncore/apps/opie-console/io_serial.h b/noncore/apps/opie-console/io_serial.h index 521dac6..00a6d2c 100644 --- a/noncore/apps/opie-console/io_serial.h +++ b/noncore/apps/opie-console/io_serial.h | |||
@@ -37,2 +37,3 @@ public: | |||
37 | QString name() const; | 37 | QString name() const; |
38 | int rawIO()const; | ||
38 | signals: | 39 | signals: |
diff --git a/noncore/apps/opie-console/sz_transfer.cpp b/noncore/apps/opie-console/sz_transfer.cpp index 41917c0..0a315cf 100644 --- a/noncore/apps/opie-console/sz_transfer.cpp +++ b/noncore/apps/opie-console/sz_transfer.cpp | |||
@@ -7,98 +7,2 @@ | |||
7 | 7 | ||
8 | /* following function ripped out of minicom's sysdep2.c */ | ||
9 | |||
10 | |||
11 | /* | ||
12 | * Set cbreak mode. | ||
13 | * Mode 0 = normal. | ||
14 | * Mode 1 = cbreak, no echo | ||
15 | * Mode 2 = raw, no echo. | ||
16 | * Mode 3 = only return erasechar (for wkeys.c) | ||
17 | * | ||
18 | * Returns: the current erase character. | ||
19 | */ | ||
20 | |||
21 | static struct termios savetty; | ||
22 | int setcbreak(int mode) | ||
23 | { | ||
24 | #if 1 | ||
25 | struct termios tty; | ||
26 | static int init = 0; | ||
27 | static int erasechar; | ||
28 | |||
29 | |||
30 | if (init == 0) { | ||
31 | tcgetattr(0, &savetty); | ||
32 | erasechar = savetty.c_cc[VERASE]; | ||
33 | init++; | ||
34 | } | ||
35 | |||
36 | if (mode == 3) return(erasechar); | ||
37 | |||
38 | |||
39 | |||
40 | /* Always return to default settings first */ | ||
41 | tcsetattr(0, TCSADRAIN, &savetty); | ||
42 | |||
43 | if (mode == 0) { | ||
44 | return(erasechar); | ||
45 | } | ||
46 | |||
47 | tcgetattr(0, &tty); | ||
48 | if (mode == 1) { | ||
49 | tty.c_oflag &= ~OPOST; | ||
50 | tty.c_lflag &= ~(XCASE|ECHONL|NOFLSH); | ||
51 | tty.c_lflag &= ~(ICANON | ISIG | ECHO); | ||
52 | tty.c_iflag &= ~(ICRNL|INLCR); | ||
53 | tty.c_cflag |= CREAD; | ||
54 | tty.c_cc[VTIME] = 5; | ||
55 | tty.c_cc[VMIN] = 1; | ||
56 | } | ||
57 | if (mode == 2) { /* raw */ | ||
58 | tty.c_iflag &= ~(IGNBRK | IGNCR | INLCR | ICRNL | IUCLC | | ||
59 | IXANY | IXON | IXOFF | INPCK | ISTRIP); | ||
60 | tty.c_iflag |= (BRKINT | IGNPAR); | ||
61 | tty.c_oflag &= ~OPOST; | ||
62 | tty.c_lflag &= ~(XCASE|ECHONL|NOFLSH); | ||
63 | tty.c_lflag &= ~(ICANON | ISIG | ECHO); | ||
64 | tty.c_cflag |= CREAD; | ||
65 | tty.c_cc[VTIME] = 5; | ||
66 | tty.c_cc[VMIN] = 1; | ||
67 | } | ||
68 | tcsetattr(0, TCSADRAIN, &tty); | ||
69 | return(erasechar); | ||
70 | #else | ||
71 | struct sgttyb args; | ||
72 | static int init = 0; | ||
73 | static int erasechar; | ||
74 | |||
75 | if (init == 0) { | ||
76 | (void) ioctl(0, TIOCGETP, &savetty); | ||
77 | (void) ioctl(0, TIOCGETC, &savetty2); | ||
78 | erasechar = savetty.sg_erase; | ||
79 | init++; | ||
80 | } | ||
81 | |||
82 | if (mode == 3) return(erasechar); | ||
83 | |||
84 | if (mode == 0) { | ||
85 | (void) ioctl(0, TIOCSETP, &savetty); | ||
86 | (void) ioctl(0, TIOCSETC, &savetty2); | ||
87 | return(erasechar); | ||
88 | } | ||
89 | |||
90 | (void) ioctl(0, TIOCGETP, &args); | ||
91 | if (mode == 1) { | ||
92 | args.sg_flags |= CBREAK; | ||
93 | args.sg_flags &= ~(ECHO|RAW); | ||
94 | } | ||
95 | if (mode == 2) { | ||
96 | args.sg_flags |= RAW; | ||
97 | args.sg_flags &= ~(ECHO|CBREAK); | ||
98 | } | ||
99 | (void) ioctl(0, TIOCSETP, &args); | ||
100 | return(erasechar); | ||
101 | #endif | ||
102 | |||
103 | } | ||
104 | 8 | ||
@@ -123,6 +27,6 @@ void SzTransfer::sendFile(const QString& file) { | |||
123 | *proc << "sz"; | 27 | *proc << "sz"; |
124 | *proc << "-v" << "-v" << "-v" << "-b" << file; | 28 | *proc << "-v" << "-v" << "-b" << file; |
125 | connect(proc, SIGNAL(processExited(OProcess *)), | 29 | connect(proc, SIGNAL(processExited(OProcess *)), |
126 | this, SLOT(sent())); | 30 | this, SLOT(sent())); |
127 | connect(proc, SIGNAL(receivedStdout(OProcess *, char *, int)), | 31 | connect(proc, SIGNAL(receivedStdout(OProcess *, char *, int)), |
128 | this, SLOT(SzReceivedStdout(OProcess *, char *, int))); | 32 | this, SLOT(SzReceivedStdout(OProcess *, char *, int))); |
@@ -138,3 +42,3 @@ void SzTransfer::SzReceivedStdout(OProcess *, char *buffer, int buflen) { | |||
138 | 42 | ||
139 | //qWarning("recieved from sz %d bytes", buflen); | 43 | qWarning("recieved from sz on stdout %d bytes", buflen); |
140 | 44 | ||
@@ -142,5 +46,9 @@ void SzTransfer::SzReceivedStdout(OProcess *, char *buffer, int buflen) { | |||
142 | data.fill(*buffer, buflen); | 46 | data.fill(*buffer, buflen); |
47 | for (uint i = 0; i < data.count(); i++ ) { | ||
48 | printf("%c", buffer[i] ); | ||
49 | } | ||
50 | printf("\n"); | ||
143 | 51 | ||
144 | // send out through the io layer | 52 | // send out through the io layer |
145 | (layer())->send(data); | 53 | layer()->send(data); |
146 | } | 54 | } |
@@ -150,5 +58,6 @@ void SzTransfer::SzReceivedStderr(OProcess *, char *buffer, int length) { | |||
150 | // parse and show data in a progress dialog/widget | 58 | // parse and show data in a progress dialog/widget |
151 | printf("\n"); | 59 | printf("stderr:\n"); |
152 | for (int i = 0; i < length; i++) | 60 | //for (int i = 0; i < length; i++) |
153 | printf("%c", buffer[i]); | 61 | // printf("%c", buffer[i]); |
62 | //printf("\n"); | ||
154 | } | 63 | } |
@@ -157,4 +66,4 @@ void SzTransfer::receivedStdin(const QByteArray &data) { | |||
157 | 66 | ||
158 | //qWarning("recieved from io_serial %d bytes", data.size()); | 67 | qWarning("recieved from io_serial %d bytes", data.size()); |
159 | 68 | ||
160 | // recieved data from the io layer goes to sz | 69 | // recieved data from the io layer goes to sz |