dol: initial dol commit
[jump.git] / dol / src / dol / datamodel / pn / Process.java
diff --git a/dol/src/dol/datamodel/pn/Process.java b/dol/src/dol/datamodel/pn/Process.java
new file mode 100644 (file)
index 0000000..1b825b4
--- /dev/null
@@ -0,0 +1,150 @@
+/* $Id: Process.java 1 2010-02-24 13:03:05Z haidw $ */
+package dol.datamodel.pn;
+
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+import dol.datamodel.architecture.Processor;
+import dol.visitor.PNVisitor;
+
+/**
+ * This class represents a process.
+ */
+public class Process extends Resource implements Schedulable {
+
+    /**
+     * Constructor to create a Process with a name and an empty
+     * portList.
+     */
+    public Process(String name) {
+        super(name);
+    }
+
+    /**
+     * Accept a Visitor
+     * @param x A Visitor Object.
+     */
+    public void accept(PNVisitor x) {
+        x.visitComponent(this);
+    }
+
+    /**
+     * Clone this Process
+     *
+     * @return  a new instance of the Process.
+     */
+    public Object clone() {
+        Process newObj = (Process) super.clone();
+        newObj.setRange(_range);
+        newObj.setProcessor(_processor);
+        return (newObj);
+    }
+
+    /**
+     * Get the range of this process.
+     *
+     * @return range
+     */
+    public String getRange() {
+        return _range;
+    }
+
+    /**
+     * Get the iterator indices of this process.
+     *
+     * @return range
+     */
+    public Vector<Integer> getIteratorIndices() {
+        Vector<Integer> indices = new Vector<Integer>();
+        StringTokenizer tokenizer =
+            new StringTokenizer(_name.replaceAll(_basename, ""), "_");
+        while (tokenizer.hasMoreTokens()) {
+            indices.add(Integer.valueOf(tokenizer.nextToken()));
+        }
+        return indices;
+    }
+
+    /**
+     * Set the range of this process.
+     *
+     * @param range new range value
+     */
+    public void setRange(String range) {
+        _range= range;
+    }
+
+    public boolean hasInPorts() {
+        for (Port port : getPortList()) {
+            if (port.isInPort())
+                return true;
+        }
+        return false;
+    }
+
+    public boolean hasOutPorts() {
+        for (Port port : getPortList()) {
+            if (port.isOutPort())
+                return true;
+        }
+        return false;
+    }
+
+    /**
+     * Get number of inport
+     */
+    public int getNumOfInports() {
+        int i = 0;
+        for (Port port : getPortList())
+            if (port.isInPort())
+                i++;
+        return i;
+    }
+
+    /**
+     * Get number of outport
+     */
+    public int getNumOfOutports() {
+        int i = 0;
+        for (Port port : getPortList())
+            if (port.isOutPort())
+                i++;
+        return i;
+    }
+
+    /**
+     * Set the processor this process runs on.
+     * @param processor
+     */
+    public void setProcessor(Processor processor)
+    {
+        _processor = processor;
+    }
+    
+    /**
+     * Get the processor this process runs on.
+     */
+    public Processor getProcessor()
+    {
+        return _processor;
+    }
+    
+    /**
+     * Return a description of the process.
+     *
+     * @return a description of the process.
+     */
+    public String toString() {
+        return "Process: " + getName();
+    }
+
+    /**
+     * Range of the iterator when the instance belongs to an iterated
+     * series of processes.
+     */
+    protected String _range = "";
+    
+    /**
+     * Processor that executes this process.
+     */
+    protected Processor _processor = null;
+}