EPICS Base  7.0.6.1
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dbJLink.h
1 /*************************************************************************\
2 * Copyright (c) 2016 UChicago Argonne LLC, as Operator of Argonne
3 * National Laboratory.
4 * SPDX-License-Identifier: EPICS
5 * EPICS BASE is distributed subject to a Software License Agreement found
6 * in file LICENSE that is included with this distribution.
7 \*************************************************************************/
8 /* dbJLink.h */
9 
10 #ifndef INC_dbJLink_H
11 #define INC_dbJLink_H
12 
13 #include <stdlib.h>
14 #include <dbCoreAPI.h>
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 typedef enum {
21  jlif_stop = 0,
22  jlif_continue = 1
23 } jlif_result;
24 
25 DBCORE_API extern const char *jlif_result_name[2];
26 
27 typedef enum {
28  jlif_key_stop = jlif_stop,
29  jlif_key_continue = jlif_continue,
30  jlif_key_child_inlink, jlif_key_child_outlink, jlif_key_child_fwdlink
31 } jlif_key_result;
32 
33 DBCORE_API extern const char *jlif_key_result_name[5];
34 
35 struct link;
36 struct lset;
37 struct jlif;
38 
39 typedef struct jlink {
40  struct jlif *pif; /* Link methods */
41  struct jlink *parent; /* NULL for top-level links */
42  int parseDepth; /* Used by parser, unused afterwards */
43  unsigned debug:1; /* Set to request debug output to console */
44  /* Link types extend or embed this structure for private storage */
45 } jlink;
46 
47 typedef long (*jlink_map_fn)(jlink *, void *ctx);
48 
49 typedef struct jlif {
50  /* Optional parser methods below given as NULL are equivalent to
51  * providing a routine that always returns jlif_stop, meaning that
52  * this JSON construct is not allowed at this point in the parse.
53  */
54 
55  const char *name;
56  /* Name for the link type, used in link value */
57 
58  jlink* (*alloc_jlink)(short dbfType);
59  /* Required, allocate new link structure */
60 
61  void (*free_jlink)(jlink *);
62  /* Required, release all resources allocated for link */
63 
64  jlif_result (*parse_null)(jlink *);
65  /* Optional, parser saw a null value */
66 
67  jlif_result (*parse_boolean)(jlink *, int val);
68  /* Optional, parser saw a boolean value */
69 
70  jlif_result (*parse_integer)(jlink *, long long num);
71  /* Optional, parser saw an integer value */
72 
73  jlif_result (*parse_double)(jlink *, double num);
74  /* Optional, parser saw a double value */
75 
76  jlif_result (*parse_string)(jlink *, const char *val, size_t len);
77  /* Optional, parser saw a string value */
78 
79  jlif_key_result (*parse_start_map)(jlink *);
80  /* Optional, parser saw an open-brace '{'. Return jlif_key_child_inlink,
81  * jlif_key_child_outlink, or jlif_key_child_fwdlink to expect a child
82  * link next (extra key/value pairs may follow)
83  */
84 
85  jlif_result (*parse_map_key)(jlink *, const char *key, size_t len);
86  /* Optional, parser saw a map key */
87 
88  jlif_result (*parse_end_map)(jlink *);
89  /* Optional, parser saw a close-brace '}' */
90 
91  jlif_result (*parse_start_array)(jlink *);
92  /* Optional, parser saw an open-bracket */
93 
94  jlif_result (*parse_end_array)(jlink *);
95  /* Optional, parser saw a close-bracket */
96 
97  void (*end_child)(jlink *parent, jlink *child);
98  /* Optional, called with pointer to the new child link after
99  * the child link has finished parsing successfully
100  */
101 
102  struct lset* (*get_lset)(const jlink *);
103  /* Required, return lset for this link instance */
104 
105  void (*report)(const jlink *, int level, int indent);
106  /* Optional, print status information about this link instance, then
107  * if (level > 0) print a link identifier (at indent+2) and call
108  * dbJLinkReport(child, level-1, indent+4)
109  * for each child.
110  */
111 
112  long (*map_children)(jlink *, jlink_map_fn rtn, void *ctx);
113  /* Optional, call dbJLinkMapChildren() on all embedded links.
114  * Stop immediately and return status if non-zero.
115  */
116 
117  void (*start_child)(jlink *parent, jlink *child);
118  /* Optional, called with pointer to the new child link after
119  * parse_start_map() returned a jlif_key_child_link value and
120  * the child link has been allocated (but not parsed yet)
121  */
122 
123  /* Link types must NOT extend this table with their own routines,
124  * this space is reserved for extensions to the jlink interface.
125  */
126 } jlif;
127 
128 DBCORE_API long dbJLinkParse(const char *json, size_t len, short dbfType,
129  jlink **ppjlink);
130 DBCORE_API long dbJLinkInit(struct link *plink);
131 
132 DBCORE_API void dbJLinkFree(jlink *);
133 DBCORE_API void dbJLinkReport(jlink *, int level, int indent);
134 
135 DBCORE_API long dbJLinkMapChildren(struct link *,
136  jlink_map_fn rtn, void *ctx);
137 
138 DBCORE_API long dbjlr(const char *recname, int level);
139 DBCORE_API long dbJLinkMapAll(char *recname, jlink_map_fn rtn, void *ctx);
140 
141 #ifdef __cplusplus
142 }
143 #endif
144 
145 #endif /* INC_dbJLink_H */
Definition: dbJLink.h:49
Link Support Entry Table.
Definition: dbLink.h:59