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) (side-by-side diff)
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) (ignore 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 @@
+#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;
+ }
+}