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
|
/*
* Baltisot
* Copyright (C) 1999-2007 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
*/
/* $Id: Task.h,v 1.32 2008-02-18 09:55:08 pixel Exp $ */
#ifndef __TASK_H__
#define __TASK_H__
#ifndef _WIN32
#include <unistd.h>
#include <sys/time.h>
#else
#include <winsock.h>
#endif
#include <vector>
#include <Exceptions.h>
#include <Handle.h>
#undef E_HANDLE
class Task : public Base {
public:
enum {
EVT_BURST = 0,
EVT_HANDLE,
EVT_PROCESS,
EVT_TIMEOUT,
EVT_TASK,
};
enum {
TASK_ON_HOLD = 0,
TASK_DONE,
TASK_BURST,
};
enum {
W4_STICKY = 1,
W4_READING = 2,
W4_WRITING = 4,
};
Task();
virtual ~Task();
virtual String GetName();
int Run();
int DryRun();
int GetState();
void Suspend(int = -1) throw (GeneralException);
void WaitFor(Task *);
void WaitFor(Handle *, int = 0);
void WaitFor(pid_t);
void WaitFor(const timeval &, int = 0);
void Yield();
bool Yielded();
void Unyield();
Task * WaitedBy();
void SetBurst();
void Stop();
void Restart();
bool IsStopped();
void RemoveFromWatches();
void RemoveTimeout();
Handle * BurstHandle;
protected:
virtual int Do() throw (GeneralException);
int current;
private:
class wbta_t {
public:
wbta_t(Task * ata) : ta(ata) { }
Task * ta;
};
int state;
bool stopped;
bool suspended;
bool yielded;
Task * wbta;
Task * wta;
};
#endif
|