-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPipeline.h
More file actions
73 lines (56 loc) · 1.77 KB
/
Pipeline.h
File metadata and controls
73 lines (56 loc) · 1.77 KB
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
#ifndef _Pipeline_h_
#define _Pipeline_h_
/** @file Pipeline.h
* Definition of class Pipeline.
*/
#include <vector> // std::vector
#include "Command.h"
/** @class Pipeline
* A group of commands that are to be executed in parallel interconnected by
* \"<a target='info' href='http://en.wikipedia.org/wiki/Pipeline_(Unix)'>pipes</a>".
* For instance:
* @code
abc | def | ghi | ... | xyz
* @endcode
* The standard output of the first process (i.e. "abc")
* will be connected to the standard input of the second process (i.e. "def").
* The standard output of the second process (i.e. "def")
* will be connected to the standard input of the third process (i.e. "ghi").
* Etc.
*
* The shell waits until the rightmost process (i.e. "xyz") ends.
* The exit status of a pipeline is the exit status
* of the rightmost process (i.e. "xyz").
*/
class Pipeline
{
private:
// The commands to be executed in parallel
// interconnected by pipes.
std::vector<Command*> commands;
// Set to true if this is a background pipeline
bool background;
public:
/// Initialize
Pipeline();
/// Cleanup
~Pipeline();
/// Append a Command to the pipeline
/// @param cp The command to be added
void addCommand(Command *cp);
/// Is the pipeline empty?
/// @return true when empty
bool isEmpty() const;
/// Set background mode
void setBackground() { background = true; }
/// Is this a background pipeline?
/// @return true is background
bool isBackground() const { return background; }
/// Executes all the commands stored in 'commands'.
/// Subsequent processes will be interconnected to each other
/// via pipes (See: unix manual: pipe(2))
void execute();
// TODO: Add any other methods you need
};
// vim:ai:aw:ts=4:sw=4:
#endif /*_Pipeline_h_*/