16683 pthread_cond_timedwait broken when using static initializer
[illumos-gate.git] / usr / src / lib / libpicltree / ptree_impl.h
blobe1ac516a3ec4ddcac0115f1ea2c275c33fb60a96
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright (c) 1999-2001 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #ifndef _PTREE_IMPL_H
28 #define _PTREE_IMPL_H
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
34 #include <synch.h>
35 #include <pthread.h>
37 typedef uint64_t picl_hdl_t;
40 * Hash table size of Ptree and PICL tables
42 #define HASH_TBL_SIZE 128
43 #define HASH_INDEX(s, x) ((int)((x) & ((s) - 1)))
46 * Invalid PICL handle
48 #define PICL_INVALID_PICLHDL (picl_hdl_t)0
51 * Is the object PICLized?
53 #define IS_PICLIZED(x) ((x)->picl_hdl != 0)
56 * A handle is a 64-bit quantity with the daemon's pid value in top 32 bits
57 * and the raw handle value in the lower 32 bits.
59 #define HASH_VAL(x) ((x) & 0xFFFFFFFF)
60 #define GET_PID(x) ((x) >> 32)
61 #define MAKE_HANDLE(x, y) (((picl_hdl_t)(x) << 32) | (y))
64 * Lock type when locking a node
66 #define RDLOCK_NODE 1
67 #define WRLOCK_NODE 2
70 * Property access operation
72 #define PROP_READ 1
73 #define PROP_WRITE 2
76 * PICL object type
78 typedef struct picl_obj picl_obj_t;
81 * Hash table structure
83 struct hash_elem {
84 uint32_t hdl;
85 union {
86 void *data;
87 uint32_t ptreeh;
88 } u;
89 struct hash_elem *next;
91 typedef struct hash_elem hash_elem_t;
92 #define hash_obj u.data
93 #define hash_hdl u.ptreeh
95 typedef struct {
96 int hash_size;
97 hash_elem_t **tbl;
98 } hash_t;
101 * Property expression list
103 typedef struct prop_list {
104 char *pname;
105 char *pval;
106 struct prop_list *next;
107 } prop_list_t;
110 * PICL property (scalar or a table entry)
112 struct picl_prop {
113 ptree_propinfo_t info;
114 void *pvalue;
115 picl_obj_t *nodep; /* prop's node or table */
116 picl_obj_t *next_in_list;
117 picl_obj_t *next_by_row;
118 picl_obj_t *next_by_col;
120 typedef struct picl_prop picl_prop_t;
123 * PICL node
125 struct picl_node {
126 rwlock_t rwlock; /* protects properties */
127 picl_obj_t *firstprop;
128 char *classname;
129 picl_obj_t *parent; /* protected by ptree lock */
130 picl_obj_t *child; /* protected by ptree lock */
131 picl_obj_t *sibling; /* protected by ptree lock */
133 typedef struct picl_node picl_node_t;
136 * PICL object types
138 #define PICL_OBJ_NODE 0x1
139 #define PICL_OBJ_PROP 0x2
140 #define PICL_OBJ_TABLE 0x4
141 #define PICL_OBJ_TABLEENTRY 0x8
144 * PICL object
146 struct picl_obj {
147 uint32_t obj_type;
148 picl_hdl_t ptree_hdl; /* ptree handle */
149 picl_hdl_t picl_hdl; /* client handle */
150 union {
151 picl_node_t node;
152 picl_prop_t prop;
153 } u;
156 #define pinfo_ver u.prop.info.version
157 #define prop_type u.prop.info.piclinfo.type
158 #define prop_size u.prop.info.piclinfo.size
159 #define prop_mode u.prop.info.piclinfo.accessmode
160 #define prop_name u.prop.info.piclinfo.name
161 #define prop_val u.prop.pvalue
162 #define next_row u.prop.next_by_row
163 #define next_col u.prop.next_by_col
164 #define next_prop u.prop.next_in_list
165 #define table_prop u.prop.next_in_list
166 #define prop_node u.prop.nodep
167 #define prop_table u.prop.nodep
168 #define read_func u.prop.info.read
169 #define write_func u.prop.info.write
171 #define first_prop u.node.firstprop
172 #define node_lock u.node.rwlock
173 #define child_node u.node.child
174 #define sibling_node u.node.sibling
175 #define parent_node u.node.parent
176 #define node_classname u.node.classname
179 * PICL event queue structures
181 struct eventq {
182 const char *ename;
183 const void *earg;
184 size_t size;
185 void (*completion_handler)(char *ename, void *earg,
186 size_t size);
187 struct eventq *next;
189 typedef struct eventq eventq_t;
192 * Event handler list
194 struct eh_list {
195 char *ename;
196 void *cookie;
197 void (*evt_handler)(const char *ename, const void *earg,
198 size_t size, void *cookie);
199 short execflg;
200 short wakeupflg;
201 pthread_cond_t cv;
202 struct eh_list *next;
204 typedef struct eh_list evt_handler_t;
206 #define SUPER_USER 0
208 #define MIN(x, y) ((x) < (y) ? (x) : (y))
210 typedef struct picld_plugin_reg_list {
211 picld_plugin_reg_t reg;
212 struct picld_plugin_reg_list *next;
213 } picld_plugin_reg_list_t;
215 typedef struct picld_plinfo {
216 char *libname;
217 char *pathname;
218 void *dlh;
219 struct picld_plinfo *next;
220 } picld_plugin_desc_t;
222 extern int xptree_initialize(int);
223 extern void xptree_destroy(void);
224 extern int xptree_reinitialize(void);
225 extern int xptree_refresh_notify(uint32_t secs);
226 extern int cvt_picl2ptree(picl_hdl_t piclh, picl_hdl_t *ptreeh);
227 extern void cvt_ptree2picl(picl_hdl_t *vbuf);
228 extern int xptree_get_propinfo_by_name(picl_nodehdl_t nodeh,
229 const char *pname, ptree_propinfo_t *pinfo);
230 extern int xptree_get_propval_with_cred(picl_prophdl_t proph, void *valbuf,
231 size_t size, door_cred_t cred);
232 extern int xptree_get_propval_by_name_with_cred(picl_nodehdl_t nodeh,
233 const char *propname, void *valbuf, size_t sz,
234 door_cred_t cred);
235 extern int xptree_update_propval_with_cred(picl_prophdl_t proph,
236 const void *valbuf, size_t sz, door_cred_t cred);
237 extern int xptree_update_propval_by_name_with_cred(picl_nodehdl_t nodeh,
238 const char *propname, const void *valbuf, size_t sz,
239 door_cred_t cred);
242 * PICL daemon verbose level flag
244 extern int verbose_level;
245 extern void dbg_print(int level, const char *fmt, ...);
246 extern void dbg_exec(int level, void (*fn)(void *), void *arg);
248 #ifdef __cplusplus
250 #endif
252 #endif /* _PTREE_IMPL_H */