summaryrefslogtreecommitdiff
authorzecke <zecke>2002-10-12 01:04:40 (UTC)
committer zecke <zecke>2002-10-12 01:04:40 (UTC)
commit78eddaa8057462b0b8e94f10f8673bb9f555061b (patch) (side-by-side diff)
treeec73d894164866c349fd0bc28e441f6006269069
parent39b88e5809e50a4951869434b8015c55265fc495 (diff)
downloadopie-78eddaa8057462b0b8e94f10f8673bb9f555061b.zip
opie-78eddaa8057462b0b8e94f10f8673bb9f555061b.tar.gz
opie-78eddaa8057462b0b8e94f10f8673bb9f555061b.tar.bz2
SWITCH to the ProcCtl interface
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/filetransfer.cpp55
-rw-r--r--noncore/apps/opie-console/test/console.pro4
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
@@ -1,57 +1,45 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <qcstring.h>
#include <qsocketnotifier.h>
#include <opie/oprocess.h>
+#include "procctl.h"
#include "filetransfer.h"
-/**
- *
- *
-class FileTransferControl {
-public:
- FileTransferControl();
- ~FileTransferControl();
-
-
-};
-*/
-
-bool FileTransfer::terminate = false;
-pid_t FileTransfer::m_pid;
FileTransfer::FileTransfer( Type t, IOLayer* lay )
: FileTransferLayer( lay ), m_type( t ) {
signal(SIGPIPE, SIG_IGN );
- signal( SIGCHLD, signal_handler );
+
m_not = 0l;
+ m_proc = 0l;
}
FileTransfer::~FileTransfer() {
}
/**
* now we will send the file.
*
* we request an fd. The IOLayer should be closed
* then we will setup a pipe for progress communication
* then we will dup2 the m_fd in the forked process
* to do direct IO from and to the fd
*/
void FileTransfer::sendFile( const QString& file ) {
m_prog =-1;
m_fd = layer()->rawIO();
//
// m_fd = ::open("/dev/ttyS0", O_RDWR);
m_file = file;
if ( pipe( m_comm ) < 0 )
m_comm[0] = m_comm[1] = 0;
if ( pipe( m_info ) < 0 )
m_info[0] = m_info[1] = 0;
@@ -79,123 +67,118 @@ void FileTransfer::sendFile( const QString& file ) {
_exit( -1 );
break;
}
default:{
if ( m_info[1] )
close( m_info[1] );
if ( m_info[0] ) for (;;) {
char resultByte; int len;
len = read(m_info[0], &resultByte, 1 );
/* len == 1 start up failed */
if ( len == 1 ) {
emit error( StartError, tr("Could not start") );
return;
}
if ( len == -1 )
if ( (errno == ECHILD ) || (errno == EINTR ) )
continue;
// len == 0 or something like this
break;
}
if ( m_info[0] )
close( m_info[0] );
- terminate = false;
- fd_set fds;
- struct timeval timeout;
- int sel;
+
/* replace by QSocketNotifier!!! */
m_not = new QSocketNotifier(m_comm[0], QSocketNotifier::Read );
connect(m_not, SIGNAL(activated(int) ),
this, SLOT(slotRead() ) );
+ if ( pipe(m_term) < 0 )
+ m_term[0] = m_term[1] = 0;
+
+ ProcCtl::self()->add(m_pid, m_term[1] );
+ m_proc = new QSocketNotifier(m_term[0], QSocketNotifier::Read );
+ connect(m_proc, SIGNAL(activated(int) ),
+ this, SLOT(slotExec() ) );
+
}
break;
}
}
/*
* let's call the one with the filename
*/
void FileTransfer::sendFile( const QFile& file ) {
sendFile( file.name() );
}
-/*
- * our signal handler to be replaced by
- * a procctl thingie
- */
-void FileTransfer::signal_handler(int ) {
- qWarning("Terminated");
- int status;
- signal( SIGCHLD, signal_handler );
- waitpid( m_pid, &status, WNOHANG );
- terminate = true;
-}
/*
* setting up communication
* between parent child and ioLayer
*/
void FileTransfer::setupChild() {
/*
* we do not want to read from our
* information channel
*/
if (m_info[0] )
close(m_info[0] );
/*
* FD_CLOEXEC will close the
* fd on successfull exec
*/
if (m_info[1] )
fcntl(m_info[1], F_SETFD, FD_CLOEXEC );
if (m_comm[0] )
close( m_comm[0] );
/*
* now set the communication
* m_fd STDIN_FILENO
* STDOUT_FILENO
* STDERR_FILENO
*/
dup2( m_fd, STDIN_FILENO );
dup2( m_fd, STDOUT_FILENO );
dup2( m_comm[1], STDERR_FILENO );
}
/*
* read from the stderr of the child
* process
*/
void FileTransfer::slotRead() {
QByteArray ar(4096);
int len = read(m_comm[0], ar.data(), 4096 );
qWarning("slot read %d", len);
for (int i = 0; i < len; i++ ) {
// printf("%c", ar[i] );
}
ar.resize( len );
QString str( ar );
+ qWarning(str.simplifyWhiteSpace() );
QStringList lis = QStringList::split(' ', str );
/*
* Transfer finished.. either complete or incomplete
*/
if ( lis[0].simplifyWhiteSpace() == "Transfer" ) {
qWarning("sent!!!!");
emit sent();
return;
}
/*
* do progress reading
*/
slotProgress( lis );
}
/*
* find the progress
*/
void FileTransfer::slotProgress( const QStringList& list ) {
bool complete = true;
int min, sec;
int bps;
unsigned long sent, total;
@@ -219,24 +202,36 @@ void FileTransfer::slotProgress( const QStringList& list ) {
double pro = (double)sent/total;
int prog = pro * 100;
// speed
progi = QStringList::split(':', list[3].simplifyWhiteSpace() );
bps = progi[1].toInt();
// time
progi = QStringList::split(':', list[5].simplifyWhiteSpace() );
min = progi[0].toInt();
sec = progi[1].toInt();
if ( prog > m_prog ) {
m_prog = prog;
emit progress(m_file, m_prog, bps, -1, min , sec );
}
}
void FileTransfer::cancel() {
::kill(m_pid,9 );
delete m_not;
}
+void FileTransfer::slotExec() {
+ qWarning("exited!");
+ char buf[2];
+ ::read(m_term[0], buf, 1 );
+ delete m_proc;
+ delete m_not;
+ close( m_term[0] );
+ close( m_term[1] );
+ close( m_comm[0] );
+ close( m_comm[1] );
+ emit sent();
+}
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 @@
TEMPLATE = app
#CONFIG = qt warn_on release
CONFIG = qt debug
#DESTDIR = $(OPIEDIR)/bin
HEADERS = ../io_layer.h ../io_serial.h ../sz_transfer.h ../file_layer.h\
- senderui.h ../profile.h ../filetransfer.h
+ senderui.h ../profile.h ../filetransfer.h ../procctl.h
SOURCES = ../io_layer.cpp ../io_serial.cpp \
../profile.cpp ../sz_transfer.cpp ../file_layer.cpp\
- main.cpp senderui.cpp ../filetransfer.cpp
+ main.cpp senderui.cpp ../filetransfer.cpp ../procctl.cpp
INTERFACES = sender.ui
INCLUDEPATH += $(OPIEDIR)/include
DEPENDPATH += $(OPIEDIR)/include
LIBS += -lqpe -lopie
TARGET = test