Statistics
| Branch: | Revision:

root / src / scave / dataflowmanager.h @ e1750c09

History | View | Annotate | Download (2.58 KB)

1
//=========================================================================
2
//  DATAFLOWMANAGER.H - part of
3
//                  OMNeT++/OMNEST
4
//           Discrete System Simulation in C++
5
//
6
//  Author: Andras Varga
7
//
8
//=========================================================================
9

    
10
/*--------------------------------------------------------------*
11
  Copyright (C) 1992-2008 Andras Varga
12
  Copyright (C) 2006-2008 OpenSim Ltd.
13

14
  This file is distributed WITHOUT ANY WARRANTY. See the file
15
  `license' for details on this and other legal matters.
16
*--------------------------------------------------------------*/
17

    
18
#ifndef _DATAFLOWMANAGER_H_
19
#define _DATAFLOWMANAGER_H_
20

    
21
#include <vector>
22
#include "node.h"
23
#include "progressmonitor.h"
24
#include "channel.h"
25

    
26
NAMESPACE_BEGIN
27

    
28

    
29
/**
30
 * Controls execution of the data flow network.
31
 *
32
 * @see Node, Channel
33
 */
34
class SCAVE_API DataflowManager
35
{
36
    protected:
37
        std::vector<Node *> nodes;
38
        std::vector<Channel *> channels;
39
        int threshold; // channel buffer upper limit
40
        int lastnode; // for round robin
41

    
42
    protected:
43
        // utility called from connect()
44
        void addChannel(Channel *channel);
45

    
46
        // scheduler function called by execute()
47
        Node *selectNode();
48

    
49
        // returns true of a node has finished; if so, also closes
50
        // its input an output channels.
51
        bool updateNodeFinished(Node *node);
52

    
53
        // returns true if the node is a reader node
54
        // (i.e. the category of its type is "reader-node")
55
        bool isReaderNode(Node *node);
56

    
57
        // helper to estimate the total amount of work
58
        int64 getTotalBytesToBeRead();
59

    
60
    public:
61
        /**
62
         * Constructor
63
         */
64
        DataflowManager();
65

    
66
        /**
67
         * Destructor
68
         */
69
        ~DataflowManager();
70

    
71
        /**
72
         * Add a node to the data-flow network.
73
         */
74
        void addNode(Node *node);
75

    
76
        /**
77
         * Connects two Node ports via a Channel object.
78
         */
79
        void connect(Port *src, Port *dest);
80

    
81
        /**
82
         * Executes the data-flow network. That will basically keep
83
         * calling the process() method of nodes that say they are
84
         * ready (isReady() method) until they are all done (isFinished()
85
         * method). If none of them are ready but there are ones which
86
         * haven't finished yet, the method declares a deadlock.
87
         */
88
        void execute(IProgressMonitor *monitor = NULL);
89

    
90
        /**
91
         * For debugging: dumps the data-flow network on the standard output.
92
         */
93
        void dump();
94
};
95

    
96
NAMESPACE_END
97

    
98

    
99
#endif
100

    
101