6
6
import net .wbz .selectrix4java .api .device .Device ;
7
7
import net .wbz .selectrix4java .api .device .DeviceAccessException ;
8
8
import net .wbz .selectrix4java .api .device .DeviceConnectionListener ;
9
+ import net .wbz .selectrix4java .test .TestDevice ;
10
+ import org .reflections .Reflections ;
9
11
12
+ import java .lang .reflect .Modifier ;
10
13
import java .util .List ;
11
14
import java .util .Map ;
15
+ import java .util .Set ;
12
16
13
17
/**
14
- * TODO: refactor
18
+ * TODO: refactor for multiple device types
15
19
*
16
20
* @author Daniel Tuerk (daniel.tuerk@w-b-z.com)
17
21
*/
18
22
public class DeviceManager {
19
23
20
24
private final Map <String , Device > devices = Maps .newHashMap ();
21
25
22
- public enum DEVICE_TYPE {COM1 }
26
+ private final List <DeviceConnectionListener > listeners = Lists .newArrayList ();
27
+
28
+ public enum DEVICE_TYPE {SERIAL , TEST }
29
+
30
+
31
+
32
+ // public DeviceManager() {
33
+ //
34
+ // Reflections reflections = new Reflections("net.wbz.selectrix4java");
35
+ // Set<Class<? extends Device>> subTypes = reflections.getSubTypesOf(Device.class);
36
+ //
37
+ // for (Class<? extends Device> deviceClazz : subTypes) {
38
+ // if(!Modifier.isAbstract(deviceClazz.getModifiers())) {
39
+ //
40
+ //
41
+ // }
42
+ // }
43
+ //
44
+ // }
23
45
24
46
public Device registerDevice (DEVICE_TYPE type , String deviceId , int baudRate ) {
25
47
if (!devices .containsKey (deviceId )) {
@@ -34,8 +56,10 @@ public Device registerDevice(DEVICE_TYPE type, String deviceId, int baudRate) {
34
56
35
57
private Device createDevice (DEVICE_TYPE type , String deviceId , int baudRate ) {
36
58
switch (type ) {
37
- case COM1 :
59
+ case SERIAL :
38
60
return new SerialDevice (deviceId , baudRate );
61
+ case TEST :
62
+ return new TestDevice ();
39
63
default :
40
64
throw new RuntimeException ("no device found for type " + type .name ());
41
65
}
@@ -83,7 +107,6 @@ public void removeDevice(Device device) {
83
107
throw new RuntimeException ("no device found to delete" );
84
108
}
85
109
86
- private final List <DeviceConnectionListener > listeners = Lists .newArrayList ();
87
110
88
111
public void addDeviceConnectionListener (DeviceConnectionListener listener ) {
89
112
listeners .add (listener );
0 commit comments