summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPixel <Pixel>2001-11-12 22:20:50 +0000
committerPixel <Pixel>2001-11-12 22:20:50 +0000
commitae4d1cfcbbe4c6130bd6370a03f546993a37f567 (patch)
treea423eced8aab74e0ed121ad1b3e828247ac5bb34
parente57c35f00e5eba0ee5199997238cf3179a89c4d2 (diff)
Cleaning includes, progressing taskman...
-rw-r--r--include/Action.h6
-rw-r--r--include/Confirm.h6
-rw-r--r--include/Form.h6
-rw-r--r--include/Handle.h4
-rw-r--r--include/HttpServ.h10
-rw-r--r--include/IRC.h4
-rw-r--r--include/Input.h4
-rw-r--r--include/Menu.h6
-rw-r--r--include/Message.h6
-rw-r--r--include/Output.h4
-rw-r--r--include/ReadJob.h2
-rw-r--r--include/Socket.h10
-rw-r--r--include/String.h2
-rw-r--r--include/Table.h6
-rw-r--r--include/Task.h15
-rw-r--r--include/TaskMan.h6
-rw-r--r--include/Variables.h6
-rw-r--r--lib/Task.cc34
-rw-r--r--lib/TaskMan.cc53
19 files changed, 119 insertions, 71 deletions
diff --git a/include/Action.h b/include/Action.h
index 5fcf660..185cd1a 100644
--- a/include/Action.h
+++ b/include/Action.h
@@ -2,9 +2,9 @@
#define __ACTION_H__
#ifdef __cplusplus
-#include "Handle.h"
-#include "Variables.h"
-#include "Exceptions.h"
+#include <Handle.h>
+#include <Variables.h>
+#include <Exceptions.h>
/*
* La classe Action defini les actions HTTP possibles.
diff --git a/include/Confirm.h b/include/Confirm.h
index 704bb88..efd0606 100644
--- a/include/Confirm.h
+++ b/include/Confirm.h
@@ -2,9 +2,9 @@
#define __CONFIRM_H__
#ifdef __cplusplus
-#include "Action.h"
-#include "String.h"
-#include "Exceptions.h"
+#include <Action.h>
+#include <String.h>
+#include <Exceptions.h>
/*
* Cette classe sert à afficher une boîte de dialogue de confirmation.
diff --git a/include/Form.h b/include/Form.h
index e0bf75d..50b7e3c 100644
--- a/include/Form.h
+++ b/include/Form.h
@@ -2,9 +2,9 @@
#define __FORM_H__
#ifdef __cplusplus
-#include "Action.h"
-#include "String.h"
-#include "Exceptions.h"
+#include <Action.h>
+#include <String.h>
+#include <Exceptions.h>
/*
* Cette classe sert à afficher un formulaire de saisie.
diff --git a/include/Handle.h b/include/Handle.h
index 6d44a48..19de77a 100644
--- a/include/Handle.h
+++ b/include/Handle.h
@@ -4,8 +4,8 @@
#include <unistd.h>
#include <iostream.h>
-#include "String.h"
-#include "Exceptions.h"
+#include <String.h>
+#include <Exceptions.h>
/*
* Pour les classes qui vont deriver: le constructeur Handle(int) specifie
diff --git a/include/HttpServ.h b/include/HttpServ.h
index 6bd2769..5074639 100644
--- a/include/HttpServ.h
+++ b/include/HttpServ.h
@@ -2,11 +2,11 @@
#define __HTTPSERV_H__
#ifdef __cplusplus
-#include "Socket.h"
-#include "String.h"
-#include "Variables.h"
-#include "Action.h"
-#include "Exceptions.h"
+#include <Socket.h>
+#include <String.h>
+#include <Variables.h>
+#include <Action.h>
+#include <Exceptions.h>
/*
* La classe HttpServ. Le constructueur (int, const String &) indique le port
diff --git a/include/IRC.h b/include/IRC.h
index 7c7e32c..f8db55b 100644
--- a/include/IRC.h
+++ b/include/IRC.h
@@ -2,8 +2,8 @@
#define __IRC_H__
#ifdef __cplusplus
-#include "Socket.h"
-#include "Exceptions.h"
+#include <Socket.h>
+#include <Exceptions.h>
#define RPL_WELCOME 1
#define RPL_YOURHOST 2
diff --git a/include/Input.h b/include/Input.h
index 1beb1b5..f9a3df5 100644
--- a/include/Input.h
+++ b/include/Input.h
@@ -2,8 +2,8 @@
#define __INPUT_H__
#ifdef __cplusplus
-#include "String.h"
-#include "Handle.h"
+#include <String.h>
+#include <Handle.h>
/*
* Cette classe sert à créer un fichier ouvert en lecture.
diff --git a/include/Menu.h b/include/Menu.h
index 7ea7662..4167656 100644
--- a/include/Menu.h
+++ b/include/Menu.h
@@ -2,9 +2,9 @@
#define __MENU_H__
#ifdef __cplusplus
-#include "Action.h"
-#include "String.h"
-#include "Exceptions.h"
+#include <Action.h>
+#include <String.h>
+#include <Exceptions.h>
/*
* Cette classe permet d'afficher un menu.
diff --git a/include/Message.h b/include/Message.h
index 888d0be..96b9aa4 100644
--- a/include/Message.h
+++ b/include/Message.h
@@ -2,9 +2,9 @@
#define __MESSAGE_H__
#ifdef __cplusplus
-#include "Action.h"
-#include "String.h"
-#include "Exceptions.h"
+#include <Action.h>
+#include <String.h>
+#include <Exceptions.h>
/*
* Cette classe sert a afficher un message.
diff --git a/include/Output.h b/include/Output.h
index 98af0ac..ef76012 100644
--- a/include/Output.h
+++ b/include/Output.h
@@ -2,8 +2,8 @@
#define __OUTPUT_H__
#ifdef __cplusplus
-#include "String.h"
-#include "Handle.h"
+#include <String.h>
+#include <Handle.h>
/*
* Ouvre un fichier en ecriture.
diff --git a/include/ReadJob.h b/include/ReadJob.h
index be846fb..4822390 100644
--- a/include/ReadJob.h
+++ b/include/ReadJob.h
@@ -4,7 +4,7 @@
#include <Task.h>
#include <Handle.h>
-#include <regex.h>
+#include <Regex.h>
class ReadJob : public Task {
public:
diff --git a/include/Socket.h b/include/Socket.h
index 80c7180..9d70205 100644
--- a/include/Socket.h
+++ b/include/Socket.h
@@ -2,11 +2,11 @@
#define __SOCKET_H__
#ifdef __cplusplus
-#include "Handle.h"
-#include "String.h"
-#include "Output.h"
-#include "Input.h"
-#include "Exceptions.h"
+#include <Handle.h>
+#include <String.h>
+#include <Output.h>
+#include <Input.h>
+#include <Exceptions.h>
/*
* Cree un socket.
diff --git a/include/String.h b/include/String.h
index 463abfc..c6afdb2 100644
--- a/include/String.h
+++ b/include/String.h
@@ -4,7 +4,7 @@
#include <iostream.h>
#include <string.h>
-#include "Exceptions.h"
+#include <Exceptions.h>
/*
* Cette classe permet de stocker des chaînes de caractères simplement.
diff --git a/include/Table.h b/include/Table.h
index c80fc8a..64cf249 100644
--- a/include/Table.h
+++ b/include/Table.h
@@ -2,9 +2,9 @@
#define __TABLE_H__
#ifdef __cplusplus
-#include "Action.h"
-#include "String.h"
-#include "Exceptions.h"
+#include <Action.h>
+#include <String.h>
+#include <Exceptions.h>
/*
* Affiche une table.
diff --git a/include/Task.h b/include/Task.h
index 456f8f3..f728e62 100644
--- a/include/Task.h
+++ b/include/Task.h
@@ -2,7 +2,9 @@
#define __TASK_H__
#ifdef __cplusplus
-#include "Exceptions.h"
+#include <unistd.h>
+#include <vector.h>
+#include <Exceptions.h>
#define TASK_ON_HOLD 0
#define TASK_DONE 1
@@ -14,14 +16,21 @@ class Task : public Base {
virtual String GetName();
int Run();
int GetState();
- int Suspend() throw (GeneralException);
- void Resume(int) throw (GeneralException);
+ void Suspend() throw (GeneralException);
+ bool WaitFor(Handle *);
+ bool WaitFor(Task *);
+ bool WaitFor(pid_t);
+ bool WaitFor(struct timeval);
protected:
virtual int Do();
private:
int state;
bool suspended;
+ vector<Handle *> w4ha;
+ vector<Task *> w4ta;
+ vector<pid_t> w4pr;
+ vector<struct timeval> w4to;
};
#else
diff --git a/include/TaskMan.h b/include/TaskMan.h
index 1efff93..03797af 100644
--- a/include/TaskMan.h
+++ b/include/TaskMan.h
@@ -8,12 +8,12 @@
class TaskMan : public Base {
public:
TaskMan() throw (GeneralException);
- ~TaskMan();
int AddTask(Task *);
- void MainLoop();
+ void MainLoop() throw (GeneralException);
private:
vector<Task *> TaskList;
- static bool Inited;
+ int number;
+ static bool inited;
};
#else
diff --git a/include/Variables.h b/include/Variables.h
index bbd2916..c4d6ba3 100644
--- a/include/Variables.h
+++ b/include/Variables.h
@@ -3,9 +3,9 @@
#ifdef __cplusplus
#include <vector>
-#include "String.h"
-#include "Handle.h"
-#include "Exceptions.h"
+#include <String.h>
+#include <Handle.h>
+#include <Exceptions.h>
/*
* Cette classe nous sert a gérer les variables transportées par les formulaires.
diff --git a/lib/Task.cc b/lib/Task.cc
index c34d0e3..2db8ce5 100644
--- a/lib/Task.cc
+++ b/lib/Task.cc
@@ -37,26 +37,24 @@ String Task::GetName() {
return "Unknow Task";
}
-int Task::Suspend() throw (GeneralException) {
- int r;
-
+void Task::Suspend() throw (GeneralException) {
cerr << "Suspending task " << GetName() << "...\n";
-
suspended = true;
-
- r = setjmp(env);
-
- if (!r) throw TaskSwitch();
-
- return r;
+ throw TaskSwitch();
}
-void Task::Resume(int val) throw (GeneralException) {
- cerr << "Resuming task " << GetName() << "...\n";
- if (suspended) {
- suspended = false;
- longjmp(env, val);
- } else {
- throw GeneralException(String("Task ") + GetName() + " was not suspended.");
- }
+void WaitFor(Handle * h) {
+ w4ha.push_back(h);
+}
+
+void WaitFor(Task * t) {
+ w4ta.push_back(t);
+}
+
+void WaitFor(pid_t p) {
+ w4pr.push_back(p);
+}
+
+void WaitFor(struct timeval t) {
+ w4to.push_back(t);
}
diff --git a/lib/TaskMan.cc b/lib/TaskMan.cc
index f8ba303..9abffb1 100644
--- a/lib/TaskMan.cc
+++ b/lib/TaskMan.cc
@@ -1,18 +1,59 @@
-#include <TaskMan.h>
+#include <signal.h>
+#include "TaskMan.h"
-bool TaskMan::Inited = false;
+bool TaskMan::inited = false;
+
+static got_sigchild = 0;
+
+void taskman_sigchild(int sig) {
+ got_sigchild = 1;
+ signal(SIGCHILD, taskman_sigchild);
+}
TaskMan::TaskMan() throw (GeneralException) {
- if (Inited) {
- throw GeneralException("Another Task Manager is already running, aborting.");
+ throw GeneralException("You can't instanciate a Task Manager.");
+}
+
+void TaskMan::Init() throw (GeneralException) {
+ if (inited) {
+ throw GeneralException("Task Manager already initialised.");
}
- Inited = true;
+ signal(SIGCHILD, taskman_sigchild);
+
+ inited = true;
+ number = 0;
}
int TaskMan::AddTask(Task * t) {
+ TaskList.push_back(t);
+ number++;
+
+ return 0;
+}
+
+int TaskMan::RemoveTask(Task * t) {
+ int i;
+ for (i = 0; i < number; i++) {
+ if (TaskList[i] == t) {
+ TaskList.erase(i);
+ number--;
+ return 0;
+ }
+ }
+ return -1;
}
-void TaskMan::MainLoop() {
+void TaskMan::MainLoop() throw (GeneralException) {
+ while (1) {
+ if (number == 0) {
+ throw GeneralException("TaskMan: No more task to manage.");
+ }
+
+#ifdef HAVE_POLL
+
+#else
+#endif
+ }
}