EPICS Base  7.0.8.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  epicsUInt8 dbf_uchar;
44  epicsInt16 dbf_short;
45  epicsUInt16 dbf_ushort;
46  epicsEnum16 dbf_enum;
47  epicsInt32 dbf_long;
48  epicsUInt32 dbf_ulong;
49  epicsInt64 dbf_int64;
50  epicsUInt64 dbf_uint64;
51  epicsFloat32 dbf_float;
52  epicsFloat64 dbf_double;
53 #ifdef DB_EVENT_LOG_STRINGS
54  char dbf_string[MAX_STRING_SIZE];
55 #endif
56 };
57 
58 /*
59  * structure to log the state of a data base field at the time
60  * an event is triggered.
61  */
62 struct db_field_log;
63 typedef void (dbfl_freeFunc)(struct db_field_log *pfl);
64 
65 /*
66  * A db_field_log has one of two types:
67  *
68  * dbfl_type_ref - Reference to value
69  * Used for variable size (array) data types. Meta-data
70  * is stored in the field log, but value data is stored externally.
71  * Only the dbfl_ref side of the data union is valid.
72  *
73  * dbfl_type_val - Internal value
74  * Used to store small scalar data. Meta-data and value are
75  * present in this structure and no external references are used.
76  * Only the dbfl_val side of the data union is valid.
77  */
78 typedef enum dbfl_type {
79  dbfl_type_val,
80  dbfl_type_ref
81 } dbfl_type;
82 
83 /* Context of db_field_log: event = subscription update, read = read reply */
84 typedef enum dbfl_context {
85  dbfl_context_read,
86  dbfl_context_event
87 } dbfl_context;
88 
89 #define dbflTypeStr(t) (t==dbfl_type_val?"val":"ref")
90 
91 struct dbfl_val {
92  union native_value field; /* Field value */
93 };
94 
95 /* External data reference.
96  * If dtor is provided then it should be called when the referenced
97  * data is no longer needed. This is done automatically by
98  * db_delete_field_log(). Any code which changes a dbfl_type_ref
99  * field log to another type, or to reference different data,
100  * must explicitly call the dtor function.
101  * If the dtor is NULL and no_elements > 0, then this means the array
102  * data is still owned by a record. See the macro dbfl_has_copy below.
103  */
104 struct dbfl_ref {
105  void *pvt; /* Private pointer */
106  void *field; /* Field value */
107 };
108 
109 /*
110  * Note that field_size may be larger than MAX_STRING_SIZE.
111  */
112 typedef struct db_field_log {
113  unsigned int type:1; /* type (union) selector */
114  /* ctx is used for all types */
115  unsigned int ctx:1; /* context (operation type) */
116  /* only for dbfl_context_event */
117  unsigned char mask; /* DBE_* mask */
118  /* the following are used for value and reference types */
119  epicsTimeStamp time; /* Time stamp */
120  epicsUTag utag;
121  unsigned short stat; /* Alarm Status */
122  unsigned short sevr; /* Alarm Severity */
123  char amsg[40];
124  short field_type; /* DBF type of data */
125  short field_size; /* Size of a single element */
126  long no_elements; /* No of valid array elements */
127  dbfl_freeFunc *dtor; /* Callback to free filter-allocated resources */
128  union {
129  struct dbfl_val v;
130  struct dbfl_ref r;
131  } u;
132 } db_field_log;
133 
134 /*
135  * Whether a db_field_log* owns the field data. If this is the case, then the
136  * db_field_log is fully decoupled from the record: there is no need to lock
137  * the record when accessing the data, nor to call any rset methods (like
138  * get_array_info) because this has already been done when we made the copy. A
139  * special case here is that of no (remaining) data (i.e. no_elements==0). In
140  * this case, making a copy is redundant, so we have no dtor. But conceptually
141  * the db_field_log still owns the (empty) data.
142  */
143 #define dbfl_has_copy(p)\
144  ((p) && ((p)->type==dbfl_type_val || (p)->dtor || (p)->no_elements==0))
145 
146 #define dbfl_pfield(p)\
147  ((p)->type==dbfl_type_val ? &p->u.v.field : p->u.r.field)
148 
149 #ifdef __cplusplus
150 }
151 #endif
152 
153 #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...