summaryrefslogtreecommitdiff
path: root/lib/TaskMan.cc
blob: 9abffb1b56993424781edfe34782330a3eeb8cff (plain)
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
#include <signal.h>
#include "TaskMan.h"

bool TaskMan::inited = false;

static got_sigchild = 0;

void taskman_sigchild(int sig) {
    got_sigchild = 1;
    signal(SIGCHILD, taskman_sigchild);
}

TaskMan::TaskMan() throw (GeneralException) {
    throw GeneralException("You can't instanciate a Task Manager.");
}

void TaskMan::Init() throw (GeneralException) {
    if (inited) {
	throw GeneralException("Task Manager already initialised.");
    }
    
    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() throw (GeneralException) {
    while (1) {
	if (number == 0) {
	    throw GeneralException("TaskMan: No more task to manage.");
	}

#ifdef HAVE_POLL
	
#else
#endif	
    }
}