1
2
3
4
5 package org.epics.pvmanager.jca;
6
7 import org.epics.vtype.VFloat;
8 import org.epics.vtype.VInt;
9 import org.epics.vtype.VString;
10 import org.epics.vtype.VShort;
11 import org.epics.vtype.VEnum;
12 import org.epics.vtype.VIntArray;
13 import org.epics.vtype.VByte;
14 import org.epics.vtype.VByteArray;
15 import org.epics.vtype.VStringArray;
16 import org.epics.vtype.VShortArray;
17 import org.epics.vtype.VDoubleArray;
18 import org.epics.vtype.VDouble;
19 import org.epics.vtype.VFloatArray;
20 import gov.aps.jca.Channel;
21 import gov.aps.jca.dbr.*;
22 import java.util.Collections;
23 import java.util.HashSet;
24 import java.util.Set;
25 import java.util.regex.Pattern;
26 import org.epics.pvmanager.ValueCache;
27
28
29
30
31
32 public class JCAVTypeAdapterSet implements JCATypeAdapterSet {
33
34 @Override
35 public Set<JCATypeAdapter> getAdapters() {
36 return converters;
37 }
38
39
40 final static JCATypeAdapter DBRFloatToVFloat = new JCATypeAdapter(VFloat.class, DBR_TIME_Float.TYPE, DBR_CTRL_Double.TYPE, false) {
41
42 @Override
43 public VFloat createValue(DBR value, DBR metadata, JCAConnectionPayload connPayload) {
44 return new VFloatFromDbr((DBR_TIME_Float) value, (DBR_CTRL_Double) metadata, connPayload);
45 }
46 };
47
48
49 final static JCATypeAdapter DBRDoubleToVDouble = new JCATypeAdapter(VDouble.class, DBR_TIME_Double.TYPE, DBR_CTRL_Double.TYPE, false) {
50
51 @Override
52 public VDouble createValue(DBR value, DBR metadata, JCAConnectionPayload connPayload) {
53 return new VDoubleFromDbr((DBR_TIME_Double) value, (DBR_CTRL_Double) metadata, connPayload);
54 }
55 };
56
57
58 final static JCATypeAdapter DBRByteToVByte = new JCATypeAdapter(VByte.class, DBR_TIME_Byte.TYPE, DBR_CTRL_Double.TYPE, false) {
59
60 @Override
61 public VByte createValue(DBR value, DBR metadata, JCAConnectionPayload connPayload) {
62 return new VByteFromDbr((DBR_TIME_Byte) value, (DBR_CTRL_Double) metadata, connPayload);
63 }
64 };
65
66
67 final static JCATypeAdapter DBRShortToVShort = new JCATypeAdapter(VShort.class, DBR_TIME_Short.TYPE, DBR_CTRL_Double.TYPE, false) {
68
69 @Override
70 public VShort createValue(DBR value, DBR metadata, JCAConnectionPayload connPayload) {
71 return new VShortFromDbr((DBR_TIME_Short) value, (DBR_CTRL_Double) metadata, connPayload);
72 }
73 };
74
75
76 final static JCATypeAdapter DBRIntToVInt = new JCATypeAdapter(VInt.class, DBR_TIME_Int.TYPE, DBR_CTRL_Double.TYPE, false) {
77
78 @Override
79 public VInt createValue(DBR value, DBR metadata, JCAConnectionPayload connPayload) {
80 return new VIntFromDbr((DBR_TIME_Int) value, (DBR_CTRL_Double) metadata, connPayload);
81 }
82 };
83
84
85 final static JCATypeAdapter DBRStringToVString = new JCATypeAdapter(VString.class, DBR_TIME_String.TYPE, null, false) {
86
87 @Override
88 public VString createValue(DBR value, DBR metadata, JCAConnectionPayload connPayload) {
89 return new VStringFromDbr((DBR_TIME_String) value, connPayload);
90 }
91 };
92
93
94 final static JCATypeAdapter DBRByteToVString = new JCATypeAdapter(VString.class, DBR_TIME_Byte.TYPE, null, null) {
95
96 @Override
97 public int match(ValueCache<?> cache, JCAConnectionPayload connPayload) {
98 if (!connPayload.isLongString()) {
99 return 0;
100 }
101
102 return super.match(cache, connPayload);
103 }
104
105 @Override
106 public VString createValue(DBR value, DBR metadata, JCAConnectionPayload connPayload) {
107 return new VStringFromDbr((DBR_TIME_Byte) value, connPayload);
108 }
109 };
110
111
112 final static JCATypeAdapter DBREnumToVEnum = new JCATypeAdapter(VEnum.class, DBR_TIME_Enum.TYPE, DBR_LABELS_Enum.TYPE, false) {
113
114 @Override
115 public VEnum createValue(DBR value, DBR metadata, JCAConnectionPayload connPayload) {
116 return new VEnumFromDbr((DBR_TIME_Enum) value, (DBR_LABELS_Enum) metadata, connPayload);
117 }
118 };
119
120
121 final static JCATypeAdapter DBRFloatToVFloatArray = new JCATypeAdapter(VFloatArray.class, DBR_TIME_Float.TYPE, DBR_CTRL_Double.TYPE, true) {
122
123 @Override
124 public VFloatArray createValue(DBR value, DBR metadata, JCAConnectionPayload connPayload) {
125 return new VFloatArrayFromDbr((DBR_TIME_Float) value, (DBR_CTRL_Double) metadata, connPayload);
126 }
127 };
128
129
130 final static JCATypeAdapter DBRDoubleToVDoubleArray = new JCATypeAdapter(VDoubleArray.class, DBR_TIME_Double.TYPE, DBR_CTRL_Double.TYPE, true) {
131
132 @Override
133 public VDoubleArray createValue(DBR value, DBR metadata, JCAConnectionPayload connPayload) {
134 return new VDoubleArrayFromDbr((DBR_TIME_Double) value, (DBR_CTRL_Double) metadata, connPayload);
135 }
136 };
137
138
139 final static JCATypeAdapter DBRByteToVByteArray = new JCATypeAdapter(VByteArray.class, DBR_TIME_Byte.TYPE, DBR_CTRL_Double.TYPE, true) {
140
141 @Override
142 public int match(ValueCache<?> cache, JCAConnectionPayload connPayload) {
143 if (connPayload.isLongString()) {
144 return 0;
145 }
146
147 return super.match(cache, connPayload);
148 }
149
150 @Override
151 public VByteArray createValue(DBR value, DBR metadata, JCAConnectionPayload connPayload) {
152 return new VByteArrayFromDbr((DBR_TIME_Byte) value, (DBR_CTRL_Double) metadata, connPayload);
153 }
154 };
155
156
157 final static JCATypeAdapter DBRShortToVShortArray = new JCATypeAdapter(VShortArray.class, DBR_TIME_Short.TYPE, DBR_CTRL_Double.TYPE, true) {
158
159 @Override
160 public VShortArray createValue(DBR value, DBR metadata, JCAConnectionPayload connPayload) {
161 return new VShortArrayFromDbr((DBR_TIME_Short) value, (DBR_CTRL_Double) metadata, connPayload);
162 }
163 };
164
165
166 final static JCATypeAdapter DBRIntToVIntArray = new JCATypeAdapter(VIntArray.class, DBR_TIME_Int.TYPE, DBR_CTRL_Double.TYPE, true) {
167
168 @Override
169 public VIntArray createValue(DBR value, DBR metadata, JCAConnectionPayload connPayload) {
170 return new VIntArrayFromDbr((DBR_TIME_Int) value, (DBR_CTRL_Double) metadata, connPayload);
171 }
172 };
173
174
175 final static JCATypeAdapter DBRStringToVStringArray = new JCATypeAdapter(VStringArray.class, DBR_TIME_String.TYPE, null, true) {
176
177 @Override
178 public VStringArray createValue(DBR value, DBR metadata, JCAConnectionPayload connPayload) {
179 return new VStringArrayFromDbr((DBR_TIME_String) value, connPayload);
180 }
181 };
182
183 private static final Set<JCATypeAdapter> converters;
184
185 static {
186 Set<JCATypeAdapter> newFactories = new HashSet<JCATypeAdapter>();
187
188 newFactories.add(DBRFloatToVFloat);
189 newFactories.add(DBRDoubleToVDouble);
190 newFactories.add(DBRByteToVByte);
191 newFactories.add(DBRShortToVShort);
192 newFactories.add(DBRIntToVInt);
193 newFactories.add(DBRStringToVString);
194 newFactories.add(DBRByteToVString);
195 newFactories.add(DBREnumToVEnum);
196
197
198 newFactories.add(DBRFloatToVFloatArray);
199 newFactories.add(DBRDoubleToVDoubleArray);
200 newFactories.add(DBRByteToVByteArray);
201 newFactories.add(DBRShortToVShortArray);
202 newFactories.add(DBRIntToVIntArray);
203 newFactories.add(DBRStringToVStringArray);
204 converters = Collections.unmodifiableSet(newFactories);
205 }
206
207 }