1b825b439abad7869e8b4f8c638deb1753d678cb
[jump.git] / dol / src / dol / datamodel / pn / Process.java
1 /* $Id: Process.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.datamodel.pn;
3
4 import java.util.StringTokenizer;
5 import java.util.Vector;
6
7 import dol.datamodel.architecture.Processor;
8 import dol.visitor.PNVisitor;
9
10 /**
11  * This class represents a process.
12  */
13 public class Process extends Resource implements Schedulable {
14
15     /**
16      * Constructor to create a Process with a name and an empty
17      * portList.
18      */
19     public Process(String name) {
20         super(name);
21     }
22
23     /**
24      * Accept a Visitor
25      * @param x A Visitor Object.
26      */
27     public void accept(PNVisitor x) {
28         x.visitComponent(this);
29     }
30
31     /**
32      * Clone this Process
33      *
34      * @return  a new instance of the Process.
35      */
36     public Object clone() {
37         Process newObj = (Process) super.clone();
38         newObj.setRange(_range);
39         newObj.setProcessor(_processor);
40         return (newObj);
41     }
42
43     /**
44      * Get the range of this process.
45      *
46      * @return range
47      */
48     public String getRange() {
49         return _range;
50     }
51
52     /**
53      * Get the iterator indices of this process.
54      *
55      * @return range
56      */
57     public Vector<Integer> getIteratorIndices() {
58         Vector<Integer> indices = new Vector<Integer>();
59         StringTokenizer tokenizer =
60             new StringTokenizer(_name.replaceAll(_basename, ""), "_");
61         while (tokenizer.hasMoreTokens()) {
62             indices.add(Integer.valueOf(tokenizer.nextToken()));
63         }
64         return indices;
65     }
66
67     /**
68      * Set the range of this process.
69      *
70      * @param range new range value
71      */
72     public void setRange(String range) {
73         _range= range;
74     }
75
76     public boolean hasInPorts() {
77         for (Port port : getPortList()) {
78             if (port.isInPort())
79                 return true;
80         }
81         return false;
82     }
83
84     public boolean hasOutPorts() {
85         for (Port port : getPortList()) {
86             if (port.isOutPort())
87                 return true;
88         }
89         return false;
90     }
91
92     /**
93      * Get number of inport
94      */
95     public int getNumOfInports() {
96         int i = 0;
97         for (Port port : getPortList())
98             if (port.isInPort())
99                 i++;
100         return i;
101     }
102
103     /**
104      * Get number of outport
105      */
106     public int getNumOfOutports() {
107         int i = 0;
108         for (Port port : getPortList())
109             if (port.isOutPort())
110                 i++;
111         return i;
112     }
113
114     /**
115      * Set the processor this process runs on.
116      * @param processor
117      */
118     public void setProcessor(Processor processor)
119     {
120         _processor = processor;
121     }
122     
123     /**
124      * Get the processor this process runs on.
125      */
126     public Processor getProcessor()
127     {
128         return _processor;
129     }
130     
131     /**
132      * Return a description of the process.
133      *
134      * @return a description of the process.
135      */
136     public String toString() {
137         return "Process: " + getName();
138     }
139
140     /**
141      * Range of the iterator when the instance belongs to an iterated
142      * series of processes.
143      */
144     protected String _range = "";
145     
146     /**
147      * Processor that executes this process.
148      */
149     protected Processor _processor = null;
150 }