View Javadoc

1   /*
2    * @(#) Device.java Feb 18, 2004
3    * 
4    * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
5    * Delft, the Netherlands. All rights reserved.
6    * 
7    * See for project information <a href="http://www.simulation.tudelft.nl/">
8    * www.simulation.tudelft.nl </a>.
9    * 
10   * The source code and binary code of this software is proprietary information
11   * of Delft University of Technology.
12   */
13  
14  package nl.tudelft.simulation.messaging.devices.components;
15  
16  import nl.tudelft.simulation.event.EventProducer;
17  import nl.tudelft.simulation.messaging.devices.types.DeviceType;
18  
19  /***
20   * An abstract Device that can be extended to a sending device, a receiving
21   * device, or a device that combines sending and receiving. <br>
22   * <br>
23   * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
24   * Delft, the Netherlands. All rights reserved.
25   * 
26   * See for project information <a href="http://www.simulation.tudelft.nl/">
27   * www.simulation.tudelft.nl </a>.
28   * 
29   * The source code and binary code of this software is proprietary information
30   * of Delft University of Technology.
31   * 
32   * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
33   *         Jacobs </a>, <a
34   *         href="mailto:s.p.a.vanhouten@tbm.tudelft.nl">Stijn-Pieter van Houten
35   *         </a>, <a
36   *         href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
37   *         Verbraeck </a>
38   * @version $$Revision: 1.3 $$ $$Date: 2005/04/08 11:29:12 $$
39   */
40  public abstract class Device extends EventProducer implements DeviceInterface
41  {
42  	/*** the serial version uid */
43  	private static final long serialVersionUID = 12L;
44  
45  	/*** state of the device */
46  	private DeviceState state = DeviceState.IDLE;
47  
48  	/*** device type */
49  	private DeviceType deviceType;
50  
51  	/*** Name of the device */
52  	protected String name = null;
53  
54  	/*** the transmission delay of the device */
55  	private int transmissionDelay;
56  
57  	/*** the maximum transmission frequency of the device */
58  	private double transmissionFrequency;
59  
60  	/***
61  	 * constructs a new device, take the transmission delay and frequency from
62  	 * the DeviceType.
63  	 * 
64  	 * @param name the name or description of the device
65  	 * @param deviceType the type of device
66  	 */
67  	public Device(final String name, final DeviceType deviceType)
68  	{
69  		this(name, deviceType, deviceType.getTransmissionDelay(), deviceType
70  				.getTransmissionFrequency());
71  	}
72  
73  	/***
74  	 * constructs a new device, override the default transmission delay and
75  	 * frequency from the DeviceType.
76  	 * 
77  	 * @param name the name or description of the device
78  	 * @param deviceType the type of device
79  	 * @param transmissionDelay the default logarithmic transmission delay of
80  	 *        the device.
81  	 * @param transmissionFrequency the maximum transmission frequency of the
82  	 *        device.
83  	 */
84  	public Device(final String name, final DeviceType deviceType,
85  			final int transmissionDelay, final double transmissionFrequency)
86  	{
87  		super();
88  		this.name = name;
89  		this.deviceType = deviceType;
90  		this.transmissionDelay = transmissionDelay;
91  		this.transmissionFrequency = transmissionFrequency;
92  	}
93  
94  	/***
95  	 * @see nl.tudelft.simulation.messaging.devices.components.DeviceInterface#getName()
96  	 */
97  	public String getName()
98  	{
99  		return this.name;
100 	}
101 
102 	/***
103 	 * @see nl.tudelft.simulation.messaging.devices.components.DeviceInterface#getState()
104 	 */
105 	public DeviceState getState()
106 	{
107 		return this.state;
108 	}
109 
110 	/***
111 	 * @param state The state to set.
112 	 */
113 	public void setState(final DeviceState state)
114 	{
115 		this.state = state;
116 		super.fireEvent(DeviceInterface.STATE_CHANGE_EVENT, state);
117 	}
118 
119 	/***
120 	 * @see nl.tudelft.simulation.messaging.devices.components.DeviceInterface#getDeviceType()
121 	 */
122 	public DeviceType getDeviceType()
123 	{
124 		return this.deviceType;
125 	}
126 
127 	/***
128 	 * @see nl.tudelft.simulation.messaging.devices.components.DeviceInterface#getTransmissionDelay()
129 	 */
130 	public int getTransmissionDelay()
131 	{
132 		return this.transmissionDelay;
133 	}
134 
135 	/***
136 	 * @see nl.tudelft.simulation.messaging.devices.components.DeviceInterface#getTransmissionFrequency()
137 	 */
138 	public double getTransmissionFrequency()
139 	{
140 		return this.transmissionFrequency;
141 	}
142 }