forked from epics-base/epicsCoreJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpvDataJava.html
More file actions
3712 lines (3440 loc) · 131 KB
/
pvDataJava.html
File metadata and controls
3712 lines (3440 loc) · 131 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>EPICS pvDataJava</title>
<link rel="stylesheet" type="text/css" href="http://epics-pvdata.sourceforge.net/base.css" />
<link rel="stylesheet" type="text/css" href="http://epics-pvdata.sourceforge.net/epicsv4.css" />
<style type="text/css">
/*<![CDATA[*/
.about { margin-left: 3em; margin-right: 3em; font-size: .83em}
table { margin-left: auto; margin-right: auto }
.diagram { text-align: center; margin: 2.5em 0 }
span.opt { color: grey }
span.nterm { font-style:italic }
span.term { font-family:courier }
span.user { font-family:courier }
span.user:before { content:"<" }
span.user:after { content:">" }
.nonnorm { font-style:italic }
p.ed.priv { display: inline; }
span.ed.priv { display: inline; }
hr { border: none; background-color: #ccc; color: #ccc; height: 1px }
/*]]>*/</style>
<!-- Script that generates the Table of Contents -->
<script type="text/javascript" src="http://epics-pvdata.sourceforge.net/script/tocgen.js"></script>
</head>
<body>
<div class="head">
<h1>EPICS pvDataJava</h1>
<h2 class="nocount">Release 5.1-DEV - 2017.03.29</h2>
<dl>
<dt>Editors:</dt>
<dd>Marty Kraimer, BNL</dd>
<dd>Dave Hickin, Diamond</dd>
</dl>
<p class="copyright">This product is made available subject to acceptance of the <a
href="http://epics-pvdata.sourceforge.net/LICENSE.html">EPICS open source
license.</a></p>
<hr>
</div>
<h2 class="nocount">Abstract</h2>
<p>pvDataJava is a computer software package for the efficient
storage, access, and communication, of structured data. It is specifically the
Java implementation of pvData, which is one part of the set of related products in the EPICS
V4 control system programming environment:<br>
<a href="http://epics-pvdata.sourceforge.net/relatedDocumentsV4.html">relatedDocumentsV4.html</a>
</p>
<h2 class="nocount">Status of this Document</h2>
<p>This is the 29-March-2017 version of the Java implementation of pvData.
</p>
<p>RELEASE_NOTES.md provides changes since the last release.
TODO.md describes things to do before the next release.
</p>
<div id="toc">
<h2 class="nocount" style="page-break-before: always">Table of Contents</h2>
</div>
<div id="contents" class="contents">
<h2>Introduction</h2>
<p>pvData is one of a set of related projects. It describes and implements
data that the other projects support. Thus it is not useful by itself but
understanding pvData is required in order to understand the other projects. The
reader should also become familiar with project pvAccess, which is
located via the same sourceforge site as this project.</p>
<p>
<a href="http://epics-pvdata.sourceforge.net/informative/developerGuide/developerGuide.html">developerGuide</a>
briefly describes a set of application programming interfaces (APIs) for EPICS V4.
It should be read before reading this manual.
</p>
<p>The Java and C++ implementation of pvData implement the same data model but
differ in implementation because of the differences between Java and C++.</p>
<p>pvData is one of a set of related packages in the EPICS V4 core software. It
describes and implements the data management system to which the the other projects
interface.</p>
<p>pvData (Process Variable Data) defines and implements an efficient way to
store, access, and communicate memory resident data structures.</p>
<dl>
<dt>definition</dt>
<dd>Package org.epics.pvdata.pv has Java interface definitions that define
pvData. Although defined with Java syntax they also document what is
required for implementation in other languages such as C++.</dd>
<dt>implementation</dt>
<dd>The set of packages provided by this project provide a complete Java
implementation of pvData. Project pvAccess is the network support for
pvData, i.e. it provides a channel access client and server that fully
support pvData.</dd>
<dt>efficient</dt>
<dd>Small memory footprint, low cpu overhead, and concise code base.</dd>
<dt>data storage</dt>
<dd>pvData defines separate introspection and data interfaces. The
introspection interfaces provide access to immutable objects, which
allows introspection instances to be freely shared. The introspection
interface for a process variable can be accessed without requiring access
to the data.</dd>
<dt>data access</dt>
<dd>Client code can access pvData via the introspection and data
interfaces. For "well known" data, e.g. image data, specialized interfaces
can be provided without requiring any changes to the core software.</dd>
<dt>data transfer</dt>
<dd>The separation of introspection and data interfaces allows for
efficient network data transfer. At connection time introspection
information can be passed from server to client. Each side can create a
data instance. The data is transferred between these instances. The data
in the network buffers does not have to be self describing since each
side has the introspection information.</dd>
<dt>memory resident</dt>
<dd>pvData only defines memory resident data.</dd>
<dt>structured data</dt>
<dd>pvData defines data as structures with subfields
where each each subfield has a name and type.
The types are defined next.</dd>
</dl>
<h2 >Interface Definitions</h2>
<p>This section gives a <b>brief</b> description of the pvData introspection and data interfaces.
In this section the methods are shown but not described. See org.epics.pvdata.pv below for a
description of each method.</p>
<h3>Types</h3>
<p>The following are the type definitions:</p>
<pre>enum Type {
scalar,
scalarArray,
structure,
structureArray,
union_t,
unionArray;
}</pre>
<p>where</p>
<dl>
<dt>scalar</dt>
<dd>A field that has data with one of the <code>ScalarType</code>s.</dd>
<dt>scalarArray</dt>
<dd>A field that is an array where each element is the same <code>ScalarType</code>.</dd>
<dt>structure</dt>
<dd>A field which has named subfields.</dd>
<dt>structureArray</dt>
<dd>A field that is an array of structures where each element has the same
introspection interface, i.e. each element has the same structure.</dd>
<dt>union</dt>
<dd>A union stores a single subfield with a variable type.
A variant union allows the type to be any type.
A regular union allows only a fixed set of types
</dd>
<dt>unionArray</dt>
<dd>
A union array is an array of union fields where each element
has the same introspection interface.
Different elements can have different types but each must have
a type determined by the union interface.
</dd>
</dl>
<pre>enum ScalarType {
pvBoolean,
pvByte,pvShort,pvInt,pvLong,
pvUByte,pvUShort,pvUInt,pvULong,
pvFloat,pvDouble,
pvString;
// The following are convenience methods
public boolean isInteger();
public boolean isUInteger();
public boolean isNumeric();
public boolean isPrimitive();
public static ScalarType getScalarType(String type);
public String toString();
}</pre>
<p>where</p>
<dl>
<dt>boolean</dt>
<dd>true or false</dd>
<dt>byte</dt>
<dd>An 8 bit signed byte</dd>
<dt>short</dt>
<dd>16 bit signed integer</dd>
<dt>int</dt>
<dd>32 bit signed integer</dd>
<dt>long</dt>
<dd>64 bit signed integer</dd>
<dt>ubyte</dt>
<dd>An 8 bit unsigned byte</dd>
<dt>ushort</dt>
<dd>16 bit unsigned integer</dd>
<dt>uint</dt>
<dd>32 bit unsigned integer</dd>
<dt>ulong</dt>
<dd>64 bit unsigned integer</dd>
<dt>float</dt>
<dd>32 bit IEEE float</dd>
<dt>double</dt>
<dd>64 bit IEEE float</dd>
<dt>string</dt>
<dd>An immutable string. The Java implementation is String. For other
implementations the network representation must be the same as for Java.
Note that a string is treated like it is a scaler.</dd>
</dl>
<p><b>NOTE:</b> Java does not support unsigned integers so the Java implementation
of each unsigned type is implemented as the corresponding signed type.
The only exception is the Convert facility. When it performs a widening
operation, e.g. from ubyte to short, it performs the correct conversion.</p>
<h3>Introspection Interfaces</h3>
<p><code>Field</code> is the base introspection interface. It has only an ID and a type.</p>
<pre>interface Field extends Serializable {
String getId();
Type getType();
void toString(StringBuilder buf);
void toString(StringBuilder buf,int indentLevel);
String toString();
}
interface Scalar extends Field {
ScalarType getScalarType();
}
interface ScalarArray extends Field {
ScalarType getElementType();
}
interface Structure extends Field {
Field getField(String fieldName);
Field getField(int fieldIndex);
<T extends Field> T getField(Class<T> c, String fieldName);
<T extends Field> T getField(Class<T> c, int fieldIndex);
Field[] getFields();
String[] getFieldNames();
int getFieldIndex(String fieldName);
String getFieldName(int fieldIndex);
}
interface StructureArray extends Field {
Structure getStructure();
}
public interface Union extends Field{
public static final String DEFAULT_ID = "union";
public static final String ANY_ID = "any";
Field getField(String fieldName);
Field getField(int fieldIndex);
<T extends Field> T getField(Class<T> c, String fieldName);
<T extends Field> T getField(Class<T> c, int fieldIndex);
Field[] getFields();
String[] getFieldNames();
int getFieldIndex(String fieldName);
String getFieldName(int fieldIndex);
boolean isVariant();
}
public interface UnionArray extends Field{
Union getUnion();
}
</pre>
<p>The introspection interfaces provide access to immutable objects. This
allows introspection interfaces to be freely shared between data objects. For
example the introspection interface for a timeStamp, which is a structure
containing two fields, can be shared by every record that has a time stamp.</p>
<h3>Data Interfaces</h3>
<p><code>PVField</code> is the base interface for a data field:</p>
<pre>interface PVField extends Serializable {
String getFieldName();
String getFullName();
int getFieldOffset();
int getNextFieldOffset();
int getNumberFields();
boolean isImmutable();
void setImmutable();
Field getField();
PVStructure getParent();
void postPut();
void setPostHandler(PostHandler postHandler);
void toString(StringBuilder buf);
void toString(StringBuilder buf,int indentLevel);
String toString();
// The following should go away.
PVAuxInfo getPVAuxInfo();
}</pre>
<p>Each scalar type has an associated data interface: <code>PVBoolean</code>,
<code>PVByte</code>, <code>PVShort</code>, <code>PVInt</code>, <code>PVLong</code>,
<code>PVUByte</code>, <code>PVUShort</code>, <code>PVUInt</code>, <code>PVULong</code>,
<code>PVFloat</code>, <code>PVDouble</code> and <code>PVString</code>. Each has a <code>get</code> and a
<code>put</code> method. For example:</p>
<pre>interface PVDouble extends PVScalar{
double get();
void put(double value);
}</pre>
<p><code>PVArray</code> is the base class for arrays.</p>
<pre>interface PVArray extends PVField, SerializableArray {
Array getArray();
int getLength();
void setLength(int length);
int getCapacity();
void setCapacity(int length);
boolean isCapacityMutable();
void setCapacityMutable(boolean isMutable);
}
</pre>
<p><code>PVScalarArray</code> is the base class for scalar arrays.</p>
<pre>interface PVScalarArray extends PVArray {
ScalarArray getScalarArray();
}</pre>
<p>For each scalar type an associated array data interface is defined. Each has
a <code>get</code> and <code>put</code> method. For example: </p>
<pre>public class DoubleArrayData {
public double[] data;
public int offset;
}
interface PVDoubleArray extends PVArray {
int get(int offset, int len, DoubleArrayData data);
int put(int offset,int len, double[] from, int fromOffset);
void shareData(double[] from);
}</pre>
<p><code>PVStructureArray</code> is the interface for an array of structures where each element
has the same introspection interface.</p>
<pre>public class StructureArrayData {
public PVStructure[] data;
public int offset;
}
interface PVStructureArray extends PVArray{
StructureArray getStructureArray();
int get(int offset, int length, StructureArrayData data);
int put(int offset,int length, PVStructure[] from, int fromOffset);
void shareData(PVStructure[] from);
}</pre>
<p><code>PVStructure</code> is the data interface for a structure.</p>
<pre>
interface PVStructure extends PVField , BitSetSerializable{
Structure getStructure();
PVField[] getPVFields();
PVField getSubField(String fieldName);
PVField getSubField(int fieldOffset);
<T extends PVField> T getSubField(Class<T> c, String fieldName);
<T extends PVField> T getSubField(Class<T> c, int fieldOffset);
// The following are convenience methods
// Note that they are no longer needed because of above generic methods
PVBoolean getBooleanField(String fieldName);
PVByte getByteField(String fieldName);
PVShort getShortField(String fieldName);
PVInt getIntField(String fieldName);
PVLong getLongField(String fieldName);
PVFloat getFloatField(String fieldName);
PVDouble getDoubleField(String fieldName);
PVString getStringField(String fieldName);
PVScalarArray getScalarArrayField(String fieldName);
PVStructureArray getStructureArrayField(String fieldName);
PVStructure getStructureField(String fieldName);
PVArray getArrayField(String fieldName,ScalarType elementType);
PVUnion getUnionField(String fieldName);
PVUnionArray getUnionArrayField(String fieldName);
public boolean checkValid();
}</pre>
<h3>Introspection and Data creation</h3>
<p>The following interface creates introspection instances:</p>
<pre>public interface FieldCreate {
FieldBuilder createFieldBuilder();
Scalar createScalar(ScalarType scalarType);
BoundedString createBoundedString(int maxLength);
ScalarArray createScalarArray(ScalarType elementType);
ScalarArray createFixedScalarArray(ScalarType elementType, int size);
ScalarArray createBoundedScalarArray(ScalarType elementType, int bound);
StructureArray createStructureArray(Structure elementStructure);
UnionArray createUnionArray(Union elementUnion);
UnionArray createVariantUnionArray();
Structure createStructure(String[] fieldNames, Field[] field);
Structure createStructure(String id,String[] fieldNames, Field[] field);
Structure appendField(Structure structure,String fieldName, Field field);
Structure appendFields(Structure structure,String[] fieldNames, Field[] fields);
Structure createStructure(Structure structToClone);
Union createVariantUnion();
Union createUnion(String[] fieldNames, Field[] fields);
Union createUnion(String id, String[] fieldNames, Field[] fields);
Field deserialize(ByteBuffer buffer, DeserializableControl control);
}</pre>
<p>The following is a convenience class for creating introspection objects:</p>
<pre>
public interface FieldBuilder
{
public FieldBuilder setId(String id);
public FieldBuilder add(String name, ScalarType scalarType);
public FieldBuilder addBoundedString(String name, int maxLength);
public FieldBuilder add(String name, Field field);
public FieldBuilder addArray(String name, ScalarType scalarType);
public FieldBuilder addFixedArray(String name, ScalarType scalarType, int size);
public FieldBuilder addBoundedArray(String name, ScalarType scalarType, int bound);
public FieldBuilder addArray(String name, Field element);
public Structure createStructure();
public Union createUnion();
FieldBuilder addNestedStructure(String name);
FieldBuilder addNestedUnion(String name);
FieldBuilder addNestedStructureArray(String name);
FieldBuilder addNestedUnionArray(String name);
FieldBuilder endNested();
}
</pre>
<p>The following interface creates data instances:</p>
<pre>public interface PVDataCreate {
PVField createPVField(Field field);
PVField createPVField(PVField fieldToClone);
PVScalar createPVScalar(Scalar scalar);
PVScalar createPVScalar(ScalarType fieldType);
PVScalar createPVScalar(PVScalar scalarToClone);
<T extends PVScalar, TA extends PVScalarArray> T createPVScalar(
PVScalarType<T, TA> scalarType);
PVScalarArray createPVScalarArray(ScalarArray array);
PVScalarArray createPVScalarArray(ScalarType elementType);
PVScalarArray createPVScalarArray(PVScalarArray arrayToClone;
<T extends PVScalar, TA extends PVScalarArray> TA createPVScalarArray(
PVScalarType<T, TA> elementType);
PVStructureArray createPVStructureArray(StructureArray structureArray);
PVUnionArray createPVUnionArray(UnionArray unionArray);
PVUnionArray createPVVariantUnionArray();
PVStructure createPVStructure(Structure structure);
PVStructure createPVStructure(String[] fieldNames,Field[] fields);
PVStructure createPVStructure(PVStructure structToClone);
PVUnion createPVUnion(Union union);
PVUnion createPVVariantUnion();
PVUnion createPVUnion(PVUnion unionToClone);
PVStructureArray createPVStructureArray(Structure structure);
PVUnionArray createPVUnionArray(Union union);
PVField[] flattenPVStructure(PVStructure pvStructure);
}</pre>
<h3>pvData Conversion</h3>
<p>An interface named <code>Convert</code> provides all reasonable conversions to/from
pvData.
The convert utility is also used to implement the <code>toString</code> methods of <code>PVField</code>.
See <code>org.epics.pvdata.pv.Convert</code> for details.</p>
<h2 >Package Summary</h2>
<p>This document describes everything via Java definitions. The initial
implementation is in Java but the functionality is also implemented in C++ (See pvDataCPP for details).</p>
<p>pvData is distributed as a sourceforge mercurial project named pvDataJava.
It consists of the following Java packages:</p>
<h3>org.epics.pvdata.pv</h3>
<p>The Java enum, interface, and class definitions that define pvData. This
section provides a complete definition of what pvData is.</p>
<h3>org.epics.pvdata.factory</h3>
<p>Provides everything required for creating pvData. It provides the following
factories:</p>
<dl>
<dt>FieldFactory</dt>
<dd>Creates introspection interfaces.</dd>
<dt>PVDataFactory</dt>
<dd>Creates data interfaces for all of the supported data types.</dd>
<dt>ConvertFactory</dt>
<dd>Converts between support data types.</dd>
<dt>StatusFactory</dt>
<dd>Status is a class for communication status between code modules.</dd>
<dt>StandardFieldFactory</dt>
<dd>Creates introspection objects for "well known" data.</dd>
<dt>StandardPVFieldFactory</dt>
<dd>Creates data objects for "well known" data.</dd>
</dl>
<p>Although pvDataFactory can provide the implementation for all supported data
types, often it is desirable to provide other implementations. To make it easy
to create alternate implementations a set of abstract and base classes are
supplied.</p>
<h3>org.epics.pvdata.property</h3>
<p>Provides a way to associated properties with a field. </p>
<p>The basic idea is to associate properties with any field named "value". All
the fields in the structure that contains the value field are considered
properties of value with the field name being the property name. See that
package overview for details.</p>
<p>This package also provides support for "well known" field definitions like
timeStamp, alarm, display,etc. Code that uses pvData can be simplified by using
this support.</p>
<h3>org.epics.pvdata.misc</h3>
<p>This package provides support that is used by pvData factories and might
also be useful to software that uses pvData.</p>
<h3>org.epics.pvdata.monitor</h3>
<p>Provides the ability to monitor changes to an arbitrary subset of the fields
in a record.</p>
<h2 >Package org.epics.pvdata.pv</h2>
<h3>Overview</h3>
<p>This package has the complete set of enum, interface, and class definitions
that describe pvData. The implementation is provided in package
org.epics.pvdata.factory.</p>
<p>A <code>PVStructure</code> is a field that contains an array of subfields. Each field has
code for accessing the field. The interface for each field is <code>PVField</code> or an
interface that extends <code>PVField</code>. Each field also has an introspection interface,
which is <code>Field</code> or an extension of <code>Field</code>. This package overview describes the
complete set of data and introspection interfaces for pvData.</p>
<p>This package also describes an interface Convert, which provides a rich set
of methods for converting and copying data between field.</p>
<p>The interface <code>FieldCreate</code> creates the introspection interfaces. The
interface <code>PVDataCreate</code> creates the <code>PVField</code> interfaces. Between them they
provide the ability to create every type of <code>Field</code> and <code>PVField</code>, i.e. they
provide a complete implementation of pvData. It is also possible for other code
to provide implementations.</p>
<p>The interface <code>StandardField</code> provides introspection objects for standard fields.
The interface <code>StandardPVField</code> provides data objects for standard fields.</p>
<p>The interface <code>StatusCreate</code> and class <code>Status</code> provide status objects to pass between source
modules.</p>
<h3>Process Variable Reflection</h3>
<p>Given the introspection object it is
possible to introspect a field without requiring access to data. The
reflection and data interfaces are separate because the data may not be
available. For example when a pvAccess client connects to a PV, the client
library can obtain the reflection information without obtaining any data. Only
when a client issues an I/O request will data be available. This separation is
especially important for arrays and structures so that a client can discover
the type without requiring that a large array or structure be transported over
the network.</p>
<h4>Type</h4>
<p>The types are defined by the Java definitions:</p>
<pre>
enum Type {
scalar,
scalarArray,
structure,
structureArray,
union,
unionArrray;
}
enum ScalarType {
pvBoolean,
pvByte, pvShort, pvInt, pvLong,
pvUByte, pvUShort, pvUInt, pvULong,
pvFloat,pvDouble,
pvString;
//Convenience methods
public boolean isInteger(); // pvByte,...,pvULong
public boolean isUInteger(); // pvUByte,...,pvULong
public boolean isNumeric(); // pvByte,...pvDouble
public boolean isPrimitive(); // pvBoolean,...pvDouble
public static ScalarType getScalarType(String type);
public String toString();
}</pre>
<h4>Serializable</h4>
<p>The following interfaces are called by pvAccess for transporting data over
the network. The abstract and base classes ensure that these methods are
properly implemented. </p>
<pre>
interface Serializable {
void serialize(ByteBuffer buffer,SerializableControl flusher);
void deserialize(ByteBuffer buffer,DeserializableControl control);
}
</pre>
where
<dl>
<dt>serialize</dt>
<dd>Serialize into buffer. flusher is called when buffer is full.</dd>
<dt>deserialize</dt>
<dd>deserialize from byte buffer. control is called when more data is required.</dd>
</dl>
<pre>
interface SerializableControl {
void flushSerializeBuffer();
void ensureBuffer(int size);
void alignBuffer(int alignment);
void cachedSerialize(Field field, ByteBuffer buffer)
}
</pre>
where
<dl>
<dt>flushSerializeBuffer</dt>
<dd>Code that called serialize must empty the buffer.
The call can block until the buffer is flushed.</dd>
<dt>ensureBuffer</dt>
<dd>Helper method. Ensures specified size of bytes, flushes if necessary.</dd>
<dt>alignBuffer</dt>
<dd>Align buffer.Note that this takes care only current buffer alignment. If streaming protocol is used,
care must be taken that entire stream is aligned.</dd>
<dt>cachedSerialize</dt>
<dd>Serialize <code>Field</code> instance via cache.</dd>
</dl>
<pre>
interface DeserializableControl {
void ensureData(int size);
void alignData(int alignment);
Field cachedDeserialize(ByteBuffer buffer)
}
</pre>
where
<dl>
<dt>ensureData</dt>
<dd>Helper method. Ensures specified size of bytes, provides it if necessary.</dd>
<dt>alignData</dt>
<dd>Align buffer.Note that this takes care only current buffer alignment. If streaming protocol is used,
care must be taken that entire stream is aligned.</dd>
<dt>cachedDeserialize</dt>
<dd>Deserialize <code>Field</code> instance via cache.</dd>
</dl>
<pre>
interface SerializableArray extends Serializable {
void serialize(ByteBuffer buffer, SerializableControl flusher, int offset, int count);
}
</pre>
where
<dl>
<dt>serialize</dt>
<dd>Serialize field into given buffer.</dd>
</dl>
<pre>
interface BitSetSerializable {
void serialize(ByteBuffer buffer, SerializableControl flusher, BitSet bitSet);
void deserialize(ByteBuffer buffer, DeserializableControl control, BitSet bitSet);
}
</pre>
where
<dl>
<dt>serialize</dt>
<dd>Serialize field into given buffer. The <code>BitSet</code> shows the fields to serialize.</dd>
<dt>deserialize</dt>
<dd>Deserialize field into given buffer. The <code>BitSet</code> shows the fields to serialize.</dd>
</dl>
<h4>Reflection</h4>
<p>This section defines the complete set of Java PV reflection interfaces.
Reflection consists of the following:</p>
<dl>
<dt>Field</dt>
<dd>A <code>Field</code> has an ID and a type. It can be converted to a string.
The format is the metadata format
described in the overview.</dd>
<dt>Scalar</dt>
<dd>A <code>Scalar</code> has a <code>ScalarType</code></dd>
<dt>ScalarArray</dt>
<dd>A <code>ScalarArray</code> has a <code>ScalarType</code> corresponding to the element type</dd>
<dt>Structure</dt>
<dd>Has fields that can be any of the supported types.
In addition it has a name for each field.</dd>
<dt>StructureArray</dt>
<dd>The field holds <code>Structure[]</code>. Each element has the same <code>Structure</code>
introspection interface. A client can only <code>get</code>/<code>put</code> entire <code>PVStructure</code>
elements NOT subfields of array elements.</dd>
<dt>Union</dt>
<dd>A union field stores a single field. A given union field can either store a
field of any type (variant union) or any of a specified set of types
(regular union). <code>Union</code> describes which of these
applies and the set of types in the case of a regular union. </dd>
<dt>UnionArray</dt>
<dd>The field holds <code>Union[]</code>. Each element has the same
<code>Union</code> introspection interface.</dd>
<dt>FieldCreate</dt>
<dd>This is an interface that provides methods to create introspection
interfaces. A factory is provided to create a <code>FieldCreate</code>.</dd>
</dl>
<h5>Field</h5>
<pre>
interface Field extends Serializable {
String getID();
Type getType();
void toString(StringBuilder buf));
void toString(StringBuilder buf,int indentLevel);
String toString();
}
</pre>
where
<dl>
<dt>getID</dt>
<dd>Get the identification string.
It can be empty.
For scalar fields the ID is the metadata type, i.e. boolean, byte, etc.
For scalarArray fields the ID is the metadata type, i.e. boolean[],
byte[], etc.
For structure fields the ID is determined by the argument specified
when fieldCreate.createStructure is called.
For structureArray fields the ID is XX[] where XX is the ID of the element structure.
</dd>
<dt>getType</dt>
<dd>Get the field type.</dd>
<dt>toString</dt>
<dd>Create a String that shows the type.
The format is the metadata syntax defined in the overview.</dd>
</dl>
<h5>Scalar</h5>
<pre>
interface Scalar extends Field {
ScalarType getScalarType();
}
</pre>
where
<dl>
<dt>getScalarType</dt>
<dd>Return the ScalarType.</dd>
</dl>
<h5>ScalarArray</h5>
<pre>
interface ScalarArray extends Field{
ScalarType getElementType();
}
</pre>
where
<dl>
<dt>getElementType</dt>
<dd>Return the <code>ScalarType</code> for each array element.</dd>
</dl>
<h5>Structure</h5>
<pre>
interface Structure extends Field{
Field getField(String fieldName);
Field getField(int fieldIndex);
<T extends Field> T getField(Class<T> c, String fieldName);
<T extends Field> T getField(Class<T> c, int fieldIndex);
Field[] getFields();
String[] getFieldNames();
int getFieldIndex(String fieldName);
String getFieldName(int fieldIndex);
}
</pre>
where
<dl>
<dt>getField</dt>
<dd>Return a field of the structure.
The field can be requested by name or by index.</dd>
<dt>getField - generic versions</dt>
<dd>These are the methods that get a field of the structure and convert it to the proper type.</dd>
<dt>getFields</dt>
<dd>Return the array of sub fields.</dd>
<dt>getFieldNames</dt>
<dd>Return the fieldNames for the fields.</dd>
<dt>getFieldName</dt>
<dd>Return the <code>Field</code> for the index.</dd>
<dt>getFieldIndex</dt>
<dd>Return the index of the field with the specified fieldName.</dd>
</dl>
<h5>StructureArray</h5>
<pre>
interface StructureArray extends Field{
Structure getStructure();
}
</pre>
where
<dl>
<dt>getStructure</dt>
<dd>Return the introspection interface for the array elements.</dd>
</dl>
<h5>Union</h5>
<pre>
public interface Union extends Field{
public static final String DEFAULT_ID = "union";
public static final String ANY_ID = "any";
Field getField(String fieldName);
Field getField(int fieldIndex);
<T extends Field> T getField(Class<T> c, String fieldName);
<T extends Field> T getField(Class<T> c, int fieldIndex);
Field[] getFields();
String[] getFieldNames();
int getFieldIndex(String fieldName);
String getFieldName(int fieldIndex);
boolean isVariant();
}
</pre>
where
<dl>
<dt>getField</dt>
<dd>Given a name or an index the type is returned.
<b>null</b> is returned if not found.
</dd>
<dt>getFields</dt>
<dd>Get the array of types.</dd>
<dt>getFieldNames</dt>
<dd>Get the array of names.</dd>
<dt>getFieldIndex</dt>
<dd>Get the index for name. -1 is returned if not found.</dd>
<dt>getFieldName</dt>
<dd>Get the name for the specified index.</dd>
<dt>isVariant</dt>
<dd>returns <b>true</b> if this is variant array and <b>false</b> otherwise.</dd>
</dl>
<h5>UnionArray</h5>
<pre>
public interface UnionArray extends Field{
Union getUnion();
}
</pre>
where
<dl>
<dt>getUnion</dt>
<dd>Get the union interface for each element.</dd>
</dl>
<h5>FieldCreate</h5>
<p><b>Syntax for fieldName and ID.</b>
</p>
<p>
A <b>fieldName</b> must begin with a letter and must be a sequence of letters
and digits.
A letter is defined as 'A'-'Z', 'a'-'z','_', or any Unicode character
that denotes a letter in a language. Similarly digits are '0'-'9' and any
Unicode character that denotes a digit in a language.
Note that this is the same as the Java syntax for variable names.
</p>
<p>The syntax for <b>ID</b> is the same except the '.' is also allowed
after the initial letter.</p>
<pre>public interface FieldCreate {
FieldBuilder createFieldBuilder();
Scalar createScalar(ScalarType scalarType);
BoundedString createBoundedString(int maxLength);
ScalarArray createScalarArray(ScalarType elementType);
ScalarArray createFixedScalarArray(ScalarType elementType, int size);
ScalarArray createBoundedScalarArray(ScalarType elementType, int bound);
StructureArray createStructureArray(Structure elementStructure);
UnionArray createUnionArray(Union elementUnion);
UnionArray createVariantUnionArray();
Structure createStructure(String[] fieldNames, Field[] field);
Structure createStructure(String id,String[] fieldNames, Field[] field);
Structure appendField(Structure structure,String fieldName, Field field);
Structure appendFields(Structure structure,String[] fieldNames, Field[] fields);
Structure createStructure(Structure structToClone);
Union createVariantUnion();
Union createUnion(String[] fieldNames, Field[] fields);
Union createUnion(String id, String[] fieldNames, Field[] fields);
Field deserialize(ByteBuffer buffer, DeserializableControl control);
}</pre>
where
<dl>
<dt>createFieldBuilder</dt>
<dd>Create an instance of <code>FieldBuilder</code>, which is described next.</dd>
<dt>createScalar</dt>
<dd>Return the <code>Scalar</code> with the specified <code>ScalarType</code>.
Note that the implementation creates a single instance for
each <code>ScalarType</code>.</dd>
<dt>createBoundedString</dt>
<dd>Return a scalar of type <code>pvString</code> that has a bounded size for a string.</dd>
<dt>createScalarArray</dt>
<dd>Return the <code>ScalarArray</code> with the specified <code>elementType</code>.
Note that the implementation creates a single instance for
each <code>elementType</code>.</dd>
<dt>createFixedScalarArray</dt>
<dd>Return the <code>ScalarArray</code> with the specified <code>elementType</code> and specifies that size of
element size of any object that has this introspection interface.</dd>
<dt>createBoundedScalarArray</dt>
<dd>Return the <code>ScalarArray</code> with the specified <code> elementType</code> and specifies that maximum
element size of any object that has this introspection interface.</dd>
<dt>createStructureArray</dt>
<dd>Return a <code>StructureArray</code> with the specified introspection
interface for each array element.</dd>
<dt>createUnionArray</dt>
<dd>Return a <code>UnionArray</code> with the specified introspection interface.</dd>
<dt>createVariantUnionArray</dt>
<dd>Return a <code>UnionArray</code> of variant union elements.</dd>
<dt>createStructure</dt>
<dd>Return a <code>Structure</code>. There are two methods.
The first creates a structure with an empty ID which results in an ID of <b>structure</b>.
</dd>
<dt>appendField</dt>
<dd>Append a field to a structure.</dd>
<dt>appendFields</dt>
<dd>Append an array of fields to a structure.</dd>
<dt>createVariantUnion</dt>
<dd>Create a variant union, i.e. a union where the subfield can be any valid type.</dd>
<dt>createUnion</dt>
<dd>Create a union where the subfield can have any of the types an names defined
by the arguments and the associated names.
The default ID is <b>union</b> for regular unions and <b>any</b> for variant unions.
</dd>
<dt>deserialize</dt>
<dd>Deserialize a field from the the buffer.</dd>
</dl>
<h5>FieldBuilder</h5>
<p><code>FieldBuilder</code> is a convenience class for creating introspection interfaces.
An example is:</p>
<pre>
FieldCreate fieldCreate = FieldFactory.getFieldCreate();
Structure s = fieldCreate.createFieldBuilder().
add("double", ScalarType.pvDouble).
addNestedStructure("nested").
add("short", ScalarType.pvShort).
add("long", ScalarType.pvLong).
endNested().
addArray("intArray", ScalarType.pvInt).
createStructure();
System.out.println(s);
</pre>
This produces:
<pre>
structure
double double
structure nested
short short
long long
int[] intArray
</pre>
<p>The Java interface is:</p>
<pre>
public interface FieldBuilder
{
public FieldBuilder setId(String id);
public FieldBuilder add(String name, ScalarType scalarType);
public FieldBuilder addBoundedString(String name, int maxLength);
public FieldBuilder add(String name, Field field);
public FieldBuilder addArray(String name, ScalarType scalarType);
public FieldBuilder addFixedArray(String name, ScalarType scalarType, int size);
public FieldBuilder addBoundedArray(String name, ScalarType scalarType, int bound);
public FieldBuilder addArray(String name, Field element);
public Structure createStructure();
public Union createUnion();
FieldBuilder addNestedStructure(String name);
FieldBuilder addNestedUnion(String name);
FieldBuilder addNestedStructureArray(String name);
FieldBuilder addNestedUnionArray(String name);
FieldBuilder endNested();
}
</pre>
<dl>
<dt>setId</dt>
<dd>
Specify the ID for the next <code>createStructure</code> or <code>createUnion call</code>.
</dd>
<dt>add</dt>
<dd>
Add a name and field for then next call to <code>createStructure</code> or <code>createUnion</code>.
There are two forms: one for an existing field and the other for a scalar field.
</dd>
<dt>addBoundedString</dt>
<dd>Add a bounded string field.</dd>
<dt>addArray</dt>
<dd>
Add a name and array field for then next call to <code>createStructure</code> or <code>createUnion</code>.
There are two forms: one for an existing field and the other for a scalar field.
Note that for an existing field this specifies the element type.
</dd>
<dt>addFixedArray</dt>
<dd>Add a scalar fixed array field.</dd>
<dt>addBoundedArray</dt>
<dd>Add a scalar bounded array field.</dd>
<dt>createStructure</dt>
<dd>
Create a <code>Structure</code> from the previous <code>add</code> and <code>addArray</code> methods.
</dd>
<dt>createUnion</dt>
<dd>
Create a <code>Union</code> from the previous <code>add</code> and <code>addArray</code> methods.
</dd>