make api.Destination a class rather than an interface
[fleet.git] / src / edu / berkeley / fleet / interpreter / InterpreterBenkoBox.java
1 package edu.berkeley.fleet.interpreter;
2 import edu.berkeley.fleet.api.*;
3 import edu.berkeley.fleet.api.BenkoBox;
4 import java.util.*;
5
6 /** anything that has a destination address on the switch fabric */
7 public abstract class InterpreterBenkoBox extends BenkoBox {
8         
9     private final String name;
10     private final InterpreterShip ship;
11     private final Destination[] ports;
12     private final int addr = max_addr++;
13         
14     public InterpreterBenkoBox(InterpreterShip ship, String name, String[] ports) {
15         this.ship = ship;
16         this.name = name;
17         this.ports = new Destination[ports.length];
18         for(int i=0; i<ports.length; i++)
19             this.ports[i] =
20                 new InterpreterBenkoBoxDestination(ports[i]);
21     }
22
23     public Iterable<Destination> getDestinations() {
24         HashSet<Destination> ret = new HashSet<Destination>();
25         for(Destination d : ports) ret.add(d);
26         return ret;
27     }
28
29     /** adds the included datum to the port from the switch fabric  side */
30     public abstract void addDataFromFabric(Packet packet);
31
32     abstract void service();
33
34     abstract void   shutdown();
35
36     public   Ship   getShip()                  { return ship; }
37     public   Fleet  getFleet()                 { return getShip().getFleet(); }
38     public   String toString()                 { return ship+"."+name; }
39     public   String getName()                  { return name; }
40     public   int    getInstructionFifoLength() { return 4; }
41     
42     Interpreter getInterpreter() { return ((InterpreterShip)getShip()).getInterpreter(); }
43
44     public long getDestAddr() { return addr; }
45
46     private static int max_addr;
47
48     private class InterpreterBenkoBoxDestination extends InterpreterDestination {
49         public String name;
50         public long addr = max_addr++;
51         public InterpreterBenkoBoxDestination(String name)          { this.name = name; }
52         public String getDestinationName()               { return name; }
53         public Ship getShip()                    { return InterpreterBenkoBox.this.getShip(); }
54         public void addDataFromFabric(Packet packet) { InterpreterBenkoBox.this.addDataFromFabric(packet); }
55         public String toString()                 { return getShip()+"."+getName(); }
56         public long getDestAddr() { return addr; }
57     }
58 }