summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console/procctl.cpp
authorzecke <zecke>2002-10-12 00:30:06 (UTC)
committer zecke <zecke>2002-10-12 00:30:06 (UTC)
commit0a3ffe7e5657bed4cb77d9bc23457755e2d02591 (patch) (unidiff)
treea1b83e61035433668ca5c9e3af31586880535c98 /noncore/apps/opie-console/procctl.cpp
parentffa7f45a2100b7c438a437fce2d3a47608bd36e3 (diff)
downloadopie-0a3ffe7e5657bed4cb77d9bc23457755e2d02591.zip
opie-0a3ffe7e5657bed4cb77d9bc23457755e2d02591.tar.gz
opie-0a3ffe7e5657bed4cb77d9bc23457755e2d02591.tar.bz2
This is targetted to the people telling
in computer science classes that I'm toolkit dependant This is a Process Controller which will be used to work around the limit of only beeing able to do one FileTransfer at a Time
Diffstat (limited to 'noncore/apps/opie-console/procctl.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-console/procctl.cpp90
1 files changed, 90 insertions, 0 deletions
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
8ProcContainer *ProcCtl::m_last = 0;
9
10ProcCtl::ProcCtl() {
11 signal( SIGCHLD, signal_handler );
12}
13ProcCtl::~ProcCtl() {
14}
15void 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}
26void 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}
55void ProcCtl::remove( ProcContainer con ) {
56 remove( con.pid );
57}
58int 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}
67void 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}