EPICS Base  7.0.6.1
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
db_field_log.h
1 /*************************************************************************\
2 * Copyright (c) 2010 Brookhaven National Laboratory.
3 * Copyright (c) 2010 Helmholtz-Zentrum Berlin
4 * fuer Materialien und Energie GmbH.
5 * Copyright (c) 2002 The University of Chicago, as Operator of Argonne
6 * National Laboratory.
7 * Copyright (c) 2002 The Regents of the University of California, as
8 * Operator of Los Alamos National Laboratory.
9 * SPDX-License-Identifier: EPICS
10 * EPICS BASE is distributed subject to a Software License Agreement found
11 * in file LICENSE that is included with this distribution.
12 \*************************************************************************/
13 /*
14  * Author: Jeffrey O. Hill <[email protected]>
15  *
16  * Ralph Lange <[email protected]>
17  */
18 
19 #ifndef INCLdb_field_logh
20 #define INCLdb_field_logh
21 
22 #include <epicsTime.h>
23 #include <epicsTypes.h>
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 /*
30  * Simple native types (anything which is not a string or an array for
31  * now) logged by db_post_events() for reliable interprocess communication.
32  * (for other types they get whatever happens to be there when the lower
33  * priority task pending on the event queue wakes up). Strings would slow down
34  * events for more reasonable size values. DB fields of native type string
35  * will most likely change infrequently.
36  *
37  * Strings can be added to the set of types for which updates will be queued
38  * by defining the macro DB_EVENT_LOG_STRINGS. The code in db_add_event()
39  * will adjust automatically, it just compares field sizes.
40  */
41 union native_value {
42  epicsInt8 dbf_char;
43  epicsInt16 dbf_short;
44  epicsEnum16 dbf_enum;
45  epicsInt32 dbf_long;
46  epicsFloat32 dbf_float;
47  epicsFloat64 dbf_double;
48 #ifdef DB_EVENT_LOG_STRINGS
49  char dbf_string[MAX_STRING_SIZE];
50 #endif
51 };
52 
53 /*
54  * structure to log the state of a data base field at the time
55  * an event is triggered.
56  */
57 struct db_field_log;
58 typedef void (dbfl_freeFunc)(struct db_field_log *pfl);
59 
60 /*
61  * A db_field_log has one of two types:
62  *
63  * dbfl_type_ref - Reference to value
64  * Used for variable size (array) data types. Meta-data
65  * is stored in the field log, but value data is stored externally.
66  * Only the dbfl_ref side of the data union is valid.
67  *
68  * dbfl_type_val - Internal value
69  * Used to store small scalar data. Meta-data and value are
70  * present in this structure and no external references are used.
71  * Only the dbfl_val side of the data union is valid.
72  */
73 typedef enum dbfl_type {
74  dbfl_type_val,
75  dbfl_type_ref
76 } dbfl_type;
77 
78 /* Context of db_field_log: event = subscription update, read = read reply */
79 typedef enum dbfl_context {
80  dbfl_context_read,
81  dbfl_context_event
82 } dbfl_context;
83 
84 #define dbflTypeStr(t) (t==dbfl_type_val?"val":"ref")
85 
86 struct dbfl_val {
87  union native_value field; /* Field value */
88 };
89 
90 /* External data reference.
91  * If dtor is provided then it should be called when the referenced
92  * data is no longer needed. This is done automatically by
93  * db_delete_field_log(). Any code which changes a dbfl_type_ref
94  * field log to another type, or to reference different data,
95  * must explicitly call the dtor function.
96  * If the dtor is NULL and no_elements > 0, then this means the array
97  * data is still owned by a record. See the macro dbfl_has_copy below.
98  */
99 struct dbfl_ref {
100  dbfl_freeFunc *dtor; /* Callback to free filter-allocated resources */
101  void *pvt; /* Private pointer */
102  void *field; /* Field value */
103 };
104 
105 /*
106  * Note that field_size may be larger than MAX_STRING_SIZE.
107  */
108 typedef struct db_field_log {
109  unsigned int type:1; /* type (union) selector */
110  /* ctx is used for all types */
111  unsigned int ctx:1; /* context (operation type) */
112  /* only for dbfl_context_event */
113  unsigned char mask; /* DBE_* mask */
114  /* the following are used for value and reference types */
115  epicsTimeStamp time; /* Time stamp */
116  epicsUTag utag;
117  unsigned short stat; /* Alarm Status */
118  unsigned short sevr; /* Alarm Severity */
119  char amsg[40];
120  short field_type; /* DBF type of data */
121  short field_size; /* Size of a single element */
122  long no_elements; /* No of valid array elements */
123  union {
124  struct dbfl_val v;
125  struct dbfl_ref r;
126  } u;
127 } db_field_log;
128 
129 /*
130  * Whether a db_field_log* owns the field data. If this is the case, then the
131  * db_field_log is fully decoupled from the record: there is no need to lock
132  * the record when accessing the data, nor to call any rset methods (like
133  * get_array_info) because this has already been done when we made the copy. A
134  * special case here is that of no (remaining) data (i.e. no_elements==0). In
135  * this case, making a copy is redundant, so we have no dtor. But conceptually
136  * the db_field_log still owns the (empty) data.
137  */
138 #define dbfl_has_copy(p)\
139  ((p) && ((p)->type==dbfl_type_val || (p)->u.r.dtor || (p)->no_elements==0))
140 
141 #define dbfl_pfield(p)\
142  ((p)->type==dbfl_type_val ? &p->u.v.field : p->u.r.field)
143 
144 #ifdef __cplusplus
145 }
146 #endif
147 
148 #endif /*INCLdb_field_logh*/
epicsUInt64 epicsUTag
Type of UTAG field (dbCommon::utag)
Definition: epicsTime.h:49
The core data types used by epics.
EPICS time stamp, for use from C code.
Definition: epicsTime.h:42
EPICS time-stamps (epicsTimeStamp), epicsTime C++ class and C functions for handling wall-clock times...