summaryrefslogtreecommitdiffabout
path: root/include/sitecing/process_manager.h
blob: 73415d35a0ac01026377f79d22d81163b50fbb87 (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
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
#ifndef __SITECING_PROCESS_MANAGER_H
#define __SITECING_PROCESS_MANAGER_H

#include <sitecing/scoreboard.h>

/**
 * @file
 * @brief the process manager.
 */

namespace sitecing {

    /**
     * The process manager.
     */
    class process_manager {
	public:
	    /**
	     * Minimum number of child processes.
	     */
	    int min_children;
	    /**
	     * Maxinum number of child processes.
	     */
	    int max_children;
	    /**
	     * Minimum number of spare child processes.
	     */
	    int min_spare_children;
	    /**
	     * Maxiumum number of spare child processes.
	     */
	    int max_spare_children;
	    /**
	     * The scoreboard.
	     */
	    scoreboard sboard;
	    /**
	     * We're in the process of shutting down.
	     */
	    bool finishing;
	    /**
	     * @todo TODO: wish I could rememer -- document me.
	     */
	    bool die_humbly;

	    process_manager();
	    virtual ~process_manager();

	    /**
	     * The main loop.
	     */
	    void manage();

	    /**
	     * The worker function.
	     * @param the slot allocated for the process.
	     */
	    virtual void process(int slot) = 0;

	    /**
	     * @todo TODO: wish I could remember -- document me.
	     */
	    void manage_children();
	    /**
	     * @todo TODO: wish I could remember -- document me.
	     */
	    bool spawn_children();
	    /**
	     * @todo TODO: wish I could remember -- document me.
	     */
	    bool kill_children();
	    /**
	     * @todo TODO: wish I could remember -- document me.
	     */
	    void spawn_child();
	    /**
	     * @todo TODO: wish I could remember -- document me.
	     */
	    void wait_for_children(bool hang=false);
	    /**
	     * @todo TODO: wish I could remember -- document me.
	     */
	    void collect_dead_souls(bool actively=false);
    };

}

#endif /* __SITECING_PROCESS_MANAGER_H */