summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/filetransfer.cpp3
-rw-r--r--noncore/apps/opie-console/opie-console.pro4
-rw-r--r--noncore/apps/opie-console/procctl.cpp90
-rw-r--r--noncore/apps/opie-console/procctl.h33
4 files changed, 125 insertions, 5 deletions
diff --git a/noncore/apps/opie-console/filetransfer.cpp b/noncore/apps/opie-console/filetransfer.cpp
index 7b75d35..7fd9f37 100644
--- a/noncore/apps/opie-console/filetransfer.cpp
+++ b/noncore/apps/opie-console/filetransfer.cpp
@@ -209,13 +209,12 @@ void FileTransfer::slotProgress( const QStringList& list ) {
QStringList progi = QStringList::split('/', list[2].simplifyWhiteSpace() );
sent = progi[0].toULong(&complete );
if (!complete ) return;
total = progi[1].toULong(&complete );
if (!complete || total == 0) {
- qWarning("returning!!");
return;
}
qWarning("%s, %d, %d", progi.join("/").latin1(), sent, total );
double pro = (double)sent/total;
@@ -228,17 +227,15 @@ void FileTransfer::slotProgress( const QStringList& list ) {
// time
progi = QStringList::split(':', list[5].simplifyWhiteSpace() );
min = progi[0].toInt();
sec = progi[1].toInt();
- qWarning("Prog!:%d", prog );
if ( prog > m_prog ) {
m_prog = prog;
emit progress(m_file, m_prog, bps, -1, min , sec );
- qWarning("Progress: %s, %d\%, %d, %d:%d", m_file.latin1(), m_prog, bps, min, sec );
}
}
void FileTransfer::cancel() {
::kill(m_pid,9 );
delete m_not;
diff --git a/noncore/apps/opie-console/opie-console.pro b/noncore/apps/opie-console/opie-console.pro
index 37cef92..9208042 100644
--- a/noncore/apps/opie-console/opie-console.pro
+++ b/noncore/apps/opie-console/opie-console.pro
@@ -24,13 +24,13 @@ HEADERS = io_layer.h io_serial.h io_irda.h \
profiledialogwidget.h \
profileeditordialog.h \
default.h \
terminalwidget.h \
iolayerbase.h \
serialconfigwidget.h irdaconfigwidget.h btconfigwidget.h \
- emulation_widget.h
+ emulation_widget.h procctl.h
SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp \
file_layer.cpp filetransfer.cpp \
main.cpp \
metafactory.cpp \
@@ -51,13 +51,13 @@ SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp \
profiledialogwidget.cpp \
profileeditordialog.cpp \
default.cpp \
terminalwidget.cpp \
iolayerbase.cpp \
serialconfigwidget.cpp irdaconfigwidget.cpp btconfigwidget.cpp \
- emulation_widget.cpp
+ emulation_widget.cpp procctl.cpp
INTERFACES = configurebase.ui editbase.ui
INCLUDEPATH += $(OPIEDIR)/include
DEPENDPATH += $(OPIEDIR)/include
LIBS += -lqpe -lopie
TARGET = opie-console
diff --git a/noncore/apps/opie-console/procctl.cpp b/noncore/apps/opie-console/procctl.cpp
new file mode 100644
index 0000000..6839a84
--- a/dev/null
+++ b/noncore/apps/opie-console/procctl.cpp
@@ -0,0 +1,90 @@
+#include <sys/wait.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "procctl.h"
+
+ProcContainer *ProcCtl::m_last = 0;
+
+ProcCtl::ProcCtl() {
+ signal( SIGCHLD, signal_handler );
+}
+ProcCtl::~ProcCtl() {
+}
+void ProcCtl::add(pid_t pi, int fd ) {
+ ProcContainer * con = new ProcContainer;
+ //memset(con, 0, sizeof(con) );
+ con->pid = pi;
+ con->fd = fd;
+ con->status = 0;
+ con->prev = m_last;
+
+ m_last = con;
+
+}
+void ProcCtl::remove( pid_t pi ) {
+ /*
+ * We first check if the last item
+ * is equal to pi the we
+ *
+ */
+ ProcContainer* con;
+ if (m_last->pid == pi ) {
+ con = m_last;
+ m_last = con->prev;
+ delete con;
+ return;
+ }
+
+ con = m_last;
+ ProcContainer* forw = 0l;
+ while (con ) {
+ /* remove it */
+ if ( pi == con->pid ) {
+ forw->prev = con->prev;
+ delete con;
+ return;
+ }
+
+ forw = con;
+ con = con->prev;
+ }
+
+}
+void ProcCtl::remove( ProcContainer con ) {
+ remove( con.pid );
+}
+int ProcCtl::status(pid_t pid )const{
+ ProcContainer *con = m_last;
+ while (con) {
+ if (con->pid == pid )
+ return con->status;
+ con = con->prev;
+ }
+ return -1;
+}
+void ProcCtl::signal_handler(int) {
+ int status;
+ signal( SIGCHLD, signal_handler );
+ pid_t pi = waitpid( -1, &status, WNOHANG );
+
+ /*
+ * find the container for pid
+ *
+ */
+ if ( pi < 0 ) {
+ return;
+ }
+
+ ProcContainer* con = m_last;
+ while (con) {
+ if ( con->pid == pi ) {
+ con->status = status;
+ char result = 1;
+ /* give a 'signal' */
+ ::write(con->fd, &result, 1 );
+ }
+ con = con->prev;
+ }
+}
diff --git a/noncore/apps/opie-console/procctl.h b/noncore/apps/opie-console/procctl.h
new file mode 100644
index 0000000..e2161f3
--- a/dev/null
+++ b/noncore/apps/opie-console/procctl.h
@@ -0,0 +1,33 @@
+#ifndef OPIE_PROC_CTL_H
+#define OPIE_PROC_CTL_H
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <signal.h>
+
+#include <qmap.h>
+
+
+struct ProcContainer {
+ pid_t pid;
+ int fd;
+ int status;
+ ProcContainer* prev;
+};
+
+class ProcCtl {
+public:
+ ProcCtl();
+ ~ProcCtl();
+
+ int status(pid_t)const;
+ void add( pid_t, int fd );
+ void remove( pid_t );
+ void remove( ProcContainer );
+private:
+ static void signal_handler(int);
+ static ProcContainer* m_last;
+};
+
+#endif