+/* $Id: Architecture.java 1 2010-02-24 13:03:05Z haidw $ */
+package dol.datamodel.architecture;
+
+import java.util.Hashtable;
+import java.util.Vector;
+
+import dol.visitor.ArchiVisitor;
+
+
+/**
+ * This class defines an architecture.
+ */
+public class Architecture extends ArchiResource {
+ /**
+ * Constructor to create an architecture with a name,
+ * empty processor list, empty memory list, empty hwChannel list and empty connection list.
+ */
+ public Architecture(String name) {
+ super(name);
+ _processorList = new Vector<Processor>();
+ _memoryList = new Vector<Memory>();
+ _hwChannelList = new Vector<HWChannel>();
+ _varList = new Vector<Variable>();
+ _connectionList = new Vector<ArchiConnection>();
+ _readPathList = new Vector<ReadPath>();
+ _writePathList = new Vector<WritePath>();
+ _pathList = new Vector<Path>();
+ _processorPathList = new Hashtable<Processor,
+ Hashtable<Processor, Vector<Path>>>();
+
+ }
+
+ /**
+ * Accept a visitor
+ *
+ * @param x visitor object
+ */
+ public void accept(ArchiVisitor x) {
+ x.visitComponent(this);
+ }
+
+ /**
+ * Clone this Architecture.
+ *
+ * @return new instance of the Architecure
+ */
+ /*
+ @SuppressWarnings("unchecked")
+ public Object clone() {
+ Architecture newObj = (Architecture) super.clone();
+ newObj.setProcessorList((Vector<Processor>)_processorList.clone());
+ newObj.setMemoryList((Vector<Memory>)_memoryList.clone());
+ newObj.setHWChannelList((Vector<HWChannel>)_hwChannelList.clone());
+ newObj.setVarList((Vector<Variable>)_varList.clone());
+ newObj.setConnectionList((Vector<ArchiConnection>)_connectionList.clone());
+ newObj.setReadPathList((Vector<ReadPath>)_readPathList.clone());
+ newObj.setWritePathList((Vector<WritePath>)_writePathList.clone());
+ newObj.setPathList((Vector<Vector<Node>>)_pathList.clone());
+ return newObj;
+ }
+ */
+
+
+ /**
+ * Get the processor list of a Architecture.
+ *
+ * @return the processor list
+ */
+ public Vector<Processor> getProcessorList() {
+ return _processorList;
+ }
+
+ /**
+ * Get the memory list of a Architecture.
+ *
+ * @return the memory list
+ */
+ public Vector<Memory> getMemoryList() {
+ return _memoryList;
+ }
+
+ /**
+ * Get the hwChannel list of a Architecture.
+ *
+ * @return the hwChannel list
+ */
+ public Vector<HWChannel> getHWChannelList() {
+ return _hwChannelList;
+ }
+
+ /**
+ * Get the paths list of a Architecture.
+ *
+ * @return the paths list
+ */
+ public Vector<ReadPath> getReadPathList() {
+ return _readPathList;
+ }
+
+ /**
+ * Get the write paths list of a Architecture.
+ *
+ * @return the paths list
+ */
+ public Vector<WritePath> getWritePathList( ) {
+ return _writePathList;
+ }
+
+ /**
+ * Set the processor paths list of a Architecture.
+ *
+ * @param pathList The new list
+ */
+ public void setPathList(Vector<Path> pathList) {
+ _pathList = pathList;
+ }
+
+ /**
+ * Get the processor paths list of a Architecture.
+ *
+ * @return the processor paths list
+ */
+ public Vector<Path> getPathList() {
+ return _pathList;
+ }
+
+ /**
+ * Return a processor/memory/hwChannel which has a specific name. Return null if
+ * processor cannot be found.
+ *
+ * @param name the name of the processor/memory/hwChannel to search for.
+ * @return the processor/memory/hwChannel with the specific name.
+ */
+ public Processor getProcessor(String name) {
+ for (Processor processor : _processorList) {
+ if (processor.getName().equals(name)) {
+ return processor;
+ }
+ }
+ return null;
+ }
+
+ /**
+ *
+ */
+ public Memory getMemory(String name) {
+ for (Memory memory : _memoryList) {
+ if (memory.getName().equals(name)) {
+ return memory;
+ }
+ }
+ return null;
+ }
+
+ /**
+ *
+ */
+ public HWChannel getHWChannel(String name) {
+ for (HWChannel hwChannel : _hwChannelList) {
+ if (hwChannel.getName().equals(name)) {
+ return hwChannel;
+ }
+ }
+ return null;
+ }
+
+
+ /**
+ * Return a read path which has a specific name. Return null if
+ * not found.
+ *
+ * @param name the name of the read path to search for.
+ * @return the read path with the specific name.
+ */
+ public ReadPath getReadPath(String name) {
+ for (ReadPath p : _readPathList) {
+ if (p.getName().equals(name)) {
+ return p;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return a write path which has a specific name. Return null if
+ * not found.
+ *
+ * @param name the name of the write path to search for.
+ * @return the write path with the specific name.
+ */
+ public WritePath getWritePath(String name) {
+ for (WritePath p : _writePathList) {
+ if (p.getName().equals(name)) {
+ return p;
+ }
+ }
+ return null;
+ }
+
+ public Vector<Variable> getVarList() { return _varList; }
+
+ public Vector<ArchiConnection> getConnectionList() {
+ return _connectionList;
+ }
+
+ /**
+ * Compute all paths between processors.
+ */
+ public void computePaths() {
+ for (WritePath w : _writePathList) {
+ String channelBuffer = w.getCHBuf().getName();
+ for (ReadPath r : _readPathList) {
+ if (r.getCHBuf().getName().equals(channelBuffer)) {
+ Path path = new Path();
+ path.setWritePath(w);
+ path.setReadPath(r);
+ _pathList.add(path);
+ }
+ }
+ }
+
+ /*
+ //print all paths in this architecture
+ for (int j = 0; j < _pathList.size(); j++) {
+ Vector<ArchiResource> path = _pathList.elementAt(j).getPath();
+ for (int k = 0; k < path.size(); k++) {
+ System.out.print(path.elementAt(k).
+ getName() + (k < path.size() - 1 ? " -> " : ""));
+ }
+ System.out.println();
+ }
+ System.out.println("Found " + _pathList.size() + " paths.");
+ */
+
+ computeProcessorPath();
+ }
+
+ /**
+ * Compute all write path from one processor to another processor
+ * in this architecture.
+ */
+ protected void computeProcessorPath() {
+ //iterate over all path in this architecture
+ for (int j = 0; j < _pathList.size(); j++) {
+ Processor startProcessor = _pathList.elementAt(j).getStartProcessor();
+ Processor targetProcessor = _pathList.elementAt(j).getTargetProcessor();
+
+ //create new hashtable entry for this start processor
+ if (!_processorPathList.containsKey(startProcessor)) {
+ Hashtable<Processor, Vector<Path>>
+ processorPathList = new Hashtable<Processor,
+ Vector<Path>>();
+ _processorPathList.put(startProcessor, processorPathList);
+ }
+
+ Hashtable<Processor, Vector<Path>>
+ processorPathList = _processorPathList.
+ get(startProcessor);
+
+ //create new path list for this target processor
+ if(!processorPathList.containsKey(targetProcessor)) {
+ Vector<Path> processorPath = new Vector<Path>();
+ processorPathList.put(targetProcessor, processorPath);
+ }
+
+ Vector<Path> processorPath =
+ processorPathList.get(targetProcessor);
+
+ //add this path to the list of paths
+ processorPath.add(_pathList.elementAt(j));
+ }
+
+ /*
+ //print all processor to processor path
+ int pathCounter = 0;
+ for (int j = 0; j < _processorList.size(); j++) {
+ for (int k = 0; k < _processorList.size(); k++) {
+ Vector<Path> processorPathList =
+ getPaths(_processorList.elementAt(j),
+ _processorList.elementAt(k));
+ for (int l = 0; l < processorPathList.size(); l++) {
+ pathCounter++;
+ Vector<ArchiResource> path = processorPathList.
+ elementAt(l).getPath();
+ for (int m = 0; m < path.size(); m++) {
+ System.out.print(path.elementAt(m).getName()
+ + (m < path.size() - 1 ? " -> " : ""));
+ }
+ System.out.println();
+ }
+ }
+ }
+ System.out.println("Found " + pathCounter + " paths.");
+ */
+ }
+
+ /**
+ * Get all write paths from the given start processor to the given
+ * target processor.
+ *
+ * @param startProcessor processor where write path begins
+ * @param targetProcessor processor where write path ends
+ * @return vector of all write paths between startProcessor and
+ * targetProcessor
+ */
+ public Vector<Path> getPaths(
+ Processor startProcessor, Processor targetProcessor) {
+ if (_processorPathList.get(startProcessor) == null) {
+ return null;
+ }
+ return _processorPathList.get(startProcessor).get(targetProcessor);
+ }
+
+ /**
+ * Register the RX/TX/CH buffer to each resource.
+ * Can be used for dotty generation.
+ */
+ public void registerRWPath2Resource()
+ {
+ for (ReadPath r : _readPathList) {
+ // register rxbuf
+ String memName = r.getRXBuf().getName();
+ for (Memory m : _memoryList) {
+ if (m.getName().equals(memName)) {
+ m.getRXBufList().add(r.getName());
+ }
+ }
+
+ // register chbuf
+ memName = r.getCHBuf().getName();
+ for (Memory m : _memoryList) {
+ if (m.getName().equals(memName)) {
+ m.getCHBufList().add(r.getName() + "_RPath");
+ }
+ }
+
+ // register pathes via a communication resource
+ for (HWChannel c : r.getHWChannelList()) {
+ if (c.getName().equals(r.getName())) {
+ // premise: a path cannot go via a bus twice.
+ c.getPathList().add(r.getName() + "_RPath");
+ }
+ }
+ }
+
+ for (WritePath w : _writePathList) {
+ // register txbuf
+ String memName = w.getTXBuf().getName();
+ for (Memory m : _memoryList) {
+ if (m.getName().equals(memName)) {
+ m.getTXBufList().add(w.getName());
+ }
+ }
+
+ // register chbuf
+ memName = w.getCHBuf().getName();
+ for (Memory m : _memoryList) {
+ if (m.getName().equals(memName)) {
+ m.getCHBufList().add(w.getName() + "_WPath");
+ }
+ }
+
+ // register pathes via a communication resource
+ for (HWChannel c : w.getHWChannelList()) {
+ if (c.getName().equals(w.getName())) {
+ // premise: a path cannot go via a bus twice.
+ c.getPathList().add(w.getName() + "_WPath");
+ }
+ }
+ }
+ }
+
+ /** List of the processors in the Architecture */
+ protected Vector<Processor> _processorList = null;
+
+ /** List of the memories in the Architecture */
+ protected Vector<Memory> _memoryList = null;
+
+ /** List of hwChannels in the Architecture */
+ protected Vector<HWChannel> _hwChannelList = null;
+
+ /** List of variables in the Architecture */
+ protected Vector<Variable> _varList = null;
+
+ /** List of connections in the Architecture: for simplified arch*/
+ protected Vector<ArchiConnection> _connectionList = null;
+
+ /** List of read paths in the Architecture: for detail arch */
+ protected Vector<ReadPath> _readPathList = null;
+
+ /** List of write paths in the Architecture: for detail arch */
+ protected Vector<WritePath> _writePathList = null;
+
+ /** List of paths in the Architecture */
+ protected Vector<Path> _pathList = null;
+
+ /** hashtable to access all processor to processor path */
+ protected Hashtable<Processor, Hashtable<Processor,
+ Vector<Path>>> _processorPathList = null;
+}