1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/*
* Baltisot
* Copyright (C) 1999-2008 Nicolas "Pixel" Noble
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __TASKMAN_H__
#define __TASKMAN_H__
#ifdef _WIN32
typedef int sigset_t;
#endif
#include <signal.h>
#include <Task.h>
#include <vector>
class TaskMan : public Base {
public:
static void AddTask(Task *);
static std::vector<Task *>::iterator FindTask(Task *) throw (GeneralException);
static void RemoveFromWatches(Task *);
static void RemoveTimeout(Task *);
static void Init() throw (GeneralException);
static void MainLoop() throw (GeneralException);
static void WaitFor(Handle *, Task *, int = 0);
static void WaitFor(pid_t, Task *, int = 0);
static void WaitFor(const timeval &, Task *, int = 0);
static int GotChild(pid_t, int);
static void CleanChildren();
static void Stop();
static int Event();
static Task * Etask();
static Handle * Ehandle();
static int Eprocess();
static int Estatus();
static void SigChild();
static std::vector<Task *>::iterator begin();
static std::vector<Task *>::iterator end();
static int nb_tasks();
static int nb_zombies();
private:
class w4ha_t {
public:
w4ha_t(Handle * aha, int aflags, Task * aT) : ha(aha), flags(aflags), dirty(true), T(aT) { }
Handle * ha;
int flags;
bool dirty;
Task * T;
};
class w4pr_t {
public:
w4pr_t(pid_t apr, Task * aT) : pr(apr), flag(0), status(0), T(aT) { }
pid_t pr;
int flag, status;
Task * T;
};
class w4to_t {
public:
w4to_t(const timeval & ato, int aflags, Task * aT) : to(ato), flags(aflags), T(aT) { }
timeval to;
int flags;
Task * T;
};
typedef std::vector<Task *> TaskList_t;
static TaskList_t TaskList;
static TaskList_t Zombies;
static int number;
static bool inited;
static std::vector<w4ha_t> w4ha;
static std::vector<w4pr_t> w4pr;
static std::vector<w4to_t> w4to;
static bool stopped;
static int event;
static Task * etask;
static Handle * ehandle;
static int eprocess, estatus;
static sigset_t sigchildset;
static int got_sigchild;
static bool CheckDead(Task *);
};
#endif
|