-rw-r--r-- | noncore/apps/opie-console/filetransfer.cpp | 3 | ||||
-rw-r--r-- | noncore/apps/opie-console/opie-console.pro | 4 | ||||
-rw-r--r-- | noncore/apps/opie-console/procctl.cpp | 90 | ||||
-rw-r--r-- | noncore/apps/opie-console/procctl.h | 33 |
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 | |||
@@ -207,17 +207,16 @@ void FileTransfer::slotProgress( const QStringList& list ) { | |||
207 | // 0 1 2 3 4 5 | 207 | // 0 1 2 3 4 5 |
208 | // Bytes Sent 65536/11534336 BPS:7784 ETA 24:33 | 208 | // Bytes Sent 65536/11534336 BPS:7784 ETA 24:33 |
209 | QStringList progi = QStringList::split('/', list[2].simplifyWhiteSpace() ); | 209 | QStringList progi = QStringList::split('/', list[2].simplifyWhiteSpace() ); |
210 | sent = progi[0].toULong(&complete ); | 210 | sent = progi[0].toULong(&complete ); |
211 | if (!complete ) return; | 211 | if (!complete ) return; |
212 | 212 | ||
213 | total = progi[1].toULong(&complete ); | 213 | total = progi[1].toULong(&complete ); |
214 | if (!complete || total == 0) { | 214 | if (!complete || total == 0) { |
215 | qWarning("returning!!"); | ||
216 | return; | 215 | return; |
217 | } | 216 | } |
218 | 217 | ||
219 | qWarning("%s, %d, %d", progi.join("/").latin1(), sent, total ); | 218 | qWarning("%s, %d, %d", progi.join("/").latin1(), sent, total ); |
220 | 219 | ||
221 | double pro = (double)sent/total; | 220 | double pro = (double)sent/total; |
222 | int prog = pro * 100; | 221 | int prog = pro * 100; |
223 | 222 | ||
@@ -226,20 +225,18 @@ void FileTransfer::slotProgress( const QStringList& list ) { | |||
226 | bps = progi[1].toInt(); | 225 | bps = progi[1].toInt(); |
227 | 226 | ||
228 | // time | 227 | // time |
229 | progi = QStringList::split(':', list[5].simplifyWhiteSpace() ); | 228 | progi = QStringList::split(':', list[5].simplifyWhiteSpace() ); |
230 | min = progi[0].toInt(); | 229 | min = progi[0].toInt(); |
231 | sec = progi[1].toInt(); | 230 | sec = progi[1].toInt(); |
232 | 231 | ||
233 | 232 | ||
234 | qWarning("Prog!:%d", prog ); | ||
235 | if ( prog > m_prog ) { | 233 | if ( prog > m_prog ) { |
236 | m_prog = prog; | 234 | m_prog = prog; |
237 | emit progress(m_file, m_prog, bps, -1, min , sec ); | 235 | emit progress(m_file, m_prog, bps, -1, min , sec ); |
238 | qWarning("Progress: %s, %d\%, %d, %d:%d", m_file.latin1(), m_prog, bps, min, sec ); | ||
239 | } | 236 | } |
240 | 237 | ||
241 | } | 238 | } |
242 | void FileTransfer::cancel() { | 239 | void FileTransfer::cancel() { |
243 | ::kill(m_pid,9 ); | 240 | ::kill(m_pid,9 ); |
244 | delete m_not; | 241 | delete m_not; |
245 | } | 242 | } |
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 | |||
@@ -22,17 +22,17 @@ HEADERS = io_layer.h io_serial.h io_irda.h \ | |||
22 | widget_layer.h \ | 22 | widget_layer.h \ |
23 | transferdialog.h \ | 23 | transferdialog.h \ |
24 | profiledialogwidget.h \ | 24 | profiledialogwidget.h \ |
25 | profileeditordialog.h \ | 25 | profileeditordialog.h \ |
26 | default.h \ | 26 | default.h \ |
27 | terminalwidget.h \ | 27 | terminalwidget.h \ |
28 | iolayerbase.h \ | 28 | iolayerbase.h \ |
29 | serialconfigwidget.h irdaconfigwidget.h btconfigwidget.h \ | 29 | serialconfigwidget.h irdaconfigwidget.h btconfigwidget.h \ |
30 | emulation_widget.h | 30 | emulation_widget.h procctl.h |
31 | 31 | ||
32 | 32 | ||
33 | SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp \ | 33 | SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp \ |
34 | file_layer.cpp filetransfer.cpp \ | 34 | file_layer.cpp filetransfer.cpp \ |
35 | main.cpp \ | 35 | main.cpp \ |
36 | metafactory.cpp \ | 36 | metafactory.cpp \ |
37 | session.cpp \ | 37 | session.cpp \ |
38 | mainwindow.cpp \ | 38 | mainwindow.cpp \ |
@@ -49,16 +49,16 @@ SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp \ | |||
49 | widget_layer.cpp \ | 49 | widget_layer.cpp \ |
50 | transferdialog.cpp \ | 50 | transferdialog.cpp \ |
51 | profiledialogwidget.cpp \ | 51 | profiledialogwidget.cpp \ |
52 | profileeditordialog.cpp \ | 52 | profileeditordialog.cpp \ |
53 | default.cpp \ | 53 | default.cpp \ |
54 | terminalwidget.cpp \ | 54 | terminalwidget.cpp \ |
55 | iolayerbase.cpp \ | 55 | iolayerbase.cpp \ |
56 | serialconfigwidget.cpp irdaconfigwidget.cpp btconfigwidget.cpp \ | 56 | serialconfigwidget.cpp irdaconfigwidget.cpp btconfigwidget.cpp \ |
57 | emulation_widget.cpp | 57 | emulation_widget.cpp procctl.cpp |
58 | 58 | ||
59 | INTERFACES = configurebase.ui editbase.ui | 59 | INTERFACES = configurebase.ui editbase.ui |
60 | INCLUDEPATH += $(OPIEDIR)/include | 60 | INCLUDEPATH += $(OPIEDIR)/include |
61 | DEPENDPATH += $(OPIEDIR)/include | 61 | DEPENDPATH += $(OPIEDIR)/include |
62 | LIBS += -lqpe -lopie | 62 | LIBS += -lqpe -lopie |
63 | TARGET = opie-console | 63 | TARGET = opie-console |
64 | 64 | ||
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 @@ | |||
1 | #include <sys/wait.h> | ||
2 | |||
3 | #include <fcntl.h> | ||
4 | #include <unistd.h> | ||
5 | |||
6 | #include "procctl.h" | ||
7 | |||
8 | ProcContainer *ProcCtl::m_last = 0; | ||
9 | |||
10 | ProcCtl::ProcCtl() { | ||
11 | signal( SIGCHLD, signal_handler ); | ||
12 | } | ||
13 | ProcCtl::~ProcCtl() { | ||
14 | } | ||
15 | void ProcCtl::add(pid_t pi, int fd ) { | ||
16 | ProcContainer * con = new ProcContainer; | ||
17 | //memset(con, 0, sizeof(con) ); | ||
18 | con->pid = pi; | ||
19 | con->fd = fd; | ||
20 | con->status = 0; | ||
21 | con->prev = m_last; | ||
22 | |||
23 | m_last = con; | ||
24 | |||
25 | } | ||
26 | void ProcCtl::remove( pid_t pi ) { | ||
27 | /* | ||
28 | * We first check if the last item | ||
29 | * is equal to pi the we | ||
30 | * | ||
31 | */ | ||
32 | ProcContainer* con; | ||
33 | if (m_last->pid == pi ) { | ||
34 | con = m_last; | ||
35 | m_last = con->prev; | ||
36 | delete con; | ||
37 | return; | ||
38 | } | ||
39 | |||
40 | con = m_last; | ||
41 | ProcContainer* forw = 0l; | ||
42 | while (con ) { | ||
43 | /* remove it */ | ||
44 | if ( pi == con->pid ) { | ||
45 | forw->prev = con->prev; | ||
46 | delete con; | ||
47 | return; | ||
48 | } | ||
49 | |||
50 | forw = con; | ||
51 | con = con->prev; | ||
52 | } | ||
53 | |||
54 | } | ||
55 | void ProcCtl::remove( ProcContainer con ) { | ||
56 | remove( con.pid ); | ||
57 | } | ||
58 | int ProcCtl::status(pid_t pid )const{ | ||
59 | ProcContainer *con = m_last; | ||
60 | while (con) { | ||
61 | if (con->pid == pid ) | ||
62 | return con->status; | ||
63 | con = con->prev; | ||
64 | } | ||
65 | return -1; | ||
66 | } | ||
67 | void ProcCtl::signal_handler(int) { | ||
68 | int status; | ||
69 | signal( SIGCHLD, signal_handler ); | ||
70 | pid_t pi = waitpid( -1, &status, WNOHANG ); | ||
71 | |||
72 | /* | ||
73 | * find the container for pid | ||
74 | * | ||
75 | */ | ||
76 | if ( pi < 0 ) { | ||
77 | return; | ||
78 | } | ||
79 | |||
80 | ProcContainer* con = m_last; | ||
81 | while (con) { | ||
82 | if ( con->pid == pi ) { | ||
83 | con->status = status; | ||
84 | char result = 1; | ||
85 | /* give a 'signal' */ | ||
86 | ::write(con->fd, &result, 1 ); | ||
87 | } | ||
88 | con = con->prev; | ||
89 | } | ||
90 | } | ||
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 @@ | |||
1 | #ifndef OPIE_PROC_CTL_H | ||
2 | #define OPIE_PROC_CTL_H | ||
3 | |||
4 | #include <sys/types.h> | ||
5 | #include <unistd.h> | ||
6 | #include <fcntl.h> | ||
7 | #include <signal.h> | ||
8 | |||
9 | #include <qmap.h> | ||
10 | |||
11 | |||
12 | struct ProcContainer { | ||
13 | pid_t pid; | ||
14 | int fd; | ||
15 | int status; | ||
16 | ProcContainer* prev; | ||
17 | }; | ||
18 | |||
19 | class ProcCtl { | ||
20 | public: | ||
21 | ProcCtl(); | ||
22 | ~ProcCtl(); | ||
23 | |||
24 | int status(pid_t)const; | ||
25 | void add( pid_t, int fd ); | ||
26 | void remove( pid_t ); | ||
27 | void remove( ProcContainer ); | ||
28 | private: | ||
29 | static void signal_handler(int); | ||
30 | static ProcContainer* m_last; | ||
31 | }; | ||
32 | |||
33 | #endif | ||