xref: /titanic_50/usr/src/lib/libsysevent/libsysevent_impl.h (revision 23a1ccea6aac035f084a7a4cdc968687d1b02daf)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_LIBSYSEVENT_IMPL_H
28 #define	_LIBSYSEVENT_IMPL_H
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 /*
35  * libsysevent implementation-specific structures
36  */
37 
38 /* sysevent publisher/subscriber handle and related data structures */
39 
40 #define	CHAN_PATH	"/var/run/sysevent_channels"
41 #define	REG_DOOR	"reg_door"
42 
43 /* Subscription size values */
44 #define	MAX_SUBSCRIPTION_SZ	1024
45 
46 /* Sysevent Channel Handle */
47 typedef struct sysevent_impl_handle {
48 	int		sh_bound;		/* Channel bind status */
49 	int		sh_type;		/* pub/sub channel binding */
50 	uint32_t	sh_id;			/* pub/sub within channel */
51 	int		sh_door_desc;		/* Service door descrip */
52 	char		*sh_door_name;		/* Service door */
53 	char		*sh_channel_name;	/* Event Channel name */
54 	char		*sh_channel_path;	/* Full path to Event Chan */
55 	void		*sh_priv_data;	/* Pub/Sub private data */
56 	mutex_t		sh_lock;	/* lock to protect access */
57 } sysevent_impl_hdl_t;
58 
59 /* Sysevent queue for subscriber delivery */
60 typedef struct sysevent_queue {
61 	struct sysevent_queue	*sq_next;
62 	sysevent_t		*sq_ev;
63 } sysevent_queue_t;
64 
65 /*
66  * Subscriber private data stored in the sysevent channel handle
67  */
68 typedef struct subscriber_priv {
69 	cond_t			sp_cv;		/* cv for event synch */
70 	mutex_t			sp_qlock;	/* event queue lock */
71 	char			*sp_door_name;	/* Publisher reg door */
72 	thread_t		sp_handler_tid; /* delivery handler thread id */
73 	struct sysevent_queue	*sp_evq_head;   /* event q head */
74 	struct sysevent_queue	*sp_evq_tail;   /* event q tail */
75 	void			(*sp_func)(sysevent_t *ev); /* deliver func */
76 } subscriber_priv_t;
77 
78 /* Subscriber information stored on the publisher side */
79 typedef struct subscriber_data {
80 	int			sd_flag;		/* flag */
81 	char			*sd_door_name;	/* Client door name */
82 } subscriber_data_t;
83 
84 /* Publisher private data stored in the sysevent channel handle */
85 typedef struct publisher_priv {
86 	struct class_lst	*pp_class_hash[CLASS_HASH_SZ + 1];
87 	subscriber_data_t	*pp_subscriber_list[MAX_SUBSCRIBERS + 1];
88 } publisher_priv_t;
89 
90 /* Subscriber flag values */
91 #define	ACTIVE		1	/* Active subscriber */
92 #define	SEND_AGAIN	2	/* Resend of event requested */
93 
94 /* Sysevent handle access */
95 #define	SYSEVENT_IMPL_HNDL(sehp)	((sysevent_impl_hdl_t *)(void *)(sehp))
96 #define	SH_BOUND(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_bound)
97 #define	SH_TYPE(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_type)
98 #define	SH_RESULT(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_result)
99 #define	SH_ID(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_id)
100 #define	SH_DOOR_DESC(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_door_desc)
101 #define	SH_DOOR_NAME(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_door_name)
102 #define	SH_CHANNEL_NAME(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_channel_name)
103 #define	SH_CHANNEL_PATH(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_channel_path)
104 #define	SH_LOCK(sehp)		(&(SYSEVENT_IMPL_HNDL(sehp)->sh_lock))
105 #define	SH_PRIV_DATA(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_priv_data)
106 
107 #define	SH_CLASS_HASH(sehp)	(((publisher_priv_t *) \
108 	SH_PRIV_DATA(sehp))->pp_class_hash)
109 #define	SH_SUBSCRIBER(sehp, id)	(((publisher_priv_t *) \
110 	SH_PRIV_DATA(sehp))->pp_subscriber_list[id])
111 
112 /*
113  * GPEC Interface definitions
114  */
115 
116 typedef struct evchan_subscriber evchan_subscr_t;
117 
118 typedef struct evchan_sub_head {
119 	evchan_subscr_t *evchan_sub_next;
120 } evchan_sub_head_t;
121 
122 /* Event channel handle */
123 typedef struct evchan_impl_handle {
124 	pid_t		ev_pid;		/* verify descend via fork() */
125 	int		ev_fd;		/* descriptor for sev driver */
126 	mutex_t		ev_lock;	/* lock to protect this structure */
127 	evchan_sub_head_t ev_sub;	/* anchor of subscriber list */
128 } evchan_impl_hdl_t;
129 
130 /* Evchan handle access */
131 #define	EVCHAN_IMPL_HNDL(evcp)	((evchan_impl_hdl_t *)(void *)(evcp))
132 #define	EV_PID(evcp)		(EVCHAN_IMPL_HNDL(evcp)->ev_pid)
133 #define	EV_FD(evcp)		(EVCHAN_IMPL_HNDL(evcp)->ev_fd)
134 #define	EV_LOCK(evcp)		(&(EVCHAN_IMPL_HNDL(evcp)->ev_lock))
135 #define	EV_SUB(evcp)		(&(EVCHAN_IMPL_HNDL(evcp)->ev_sub))
136 #define	EV_SUB_NEXT(evcp)	(EVCHAN_IMPL_HNDL(evcp)->ev_sub.evchan_sub_next)
137 
138 struct sysevent_subattr_impl {
139 	door_xcreate_server_func_t *xs_thrcreate;
140 	void *xs_thrcreate_cookie;
141 	door_xcreate_thrsetup_func_t *xs_thrsetup;
142 	void *xs_thrsetup_cookie;
143 	pthread_attr_t *xs_thrattr;
144 	sigset_t xs_sigmask;
145 };
146 
147 /*
148  * Subscriber private data
149  */
150 struct evchan_subscriber {
151 	evchan_subscr_t *evsub_next;	/* list of subscribers */
152 	evchan_impl_hdl_t *ev_subhead;	/* link back to channel data */
153 	int evsub_door_desc;		/* Service door descriptor */
154 	char *evsub_sid;		/* identifier of subscriber */
155 	void *evsub_cookie;		/* subscriber cookie */
156 	int (*evsub_func)(sysevent_t *, void *); /* subscriber event handler */
157 	struct sysevent_subattr_impl *evsub_attr;
158 	uint32_t evsub_state;
159 };
160 
161 #define	EVCHAN_SUB_STATE_ACTIVE		1
162 #define	EVCHAN_SUB_STATE_CLOSING	2
163 
164 /* Access to subscriber data */
165 #define	EVCHAN_SUBSCR(subp)	((evchan_subscr_t *)(subp))
166 
167 /* Characters for channel name syntax */
168 #define	EVCH_ISCHANCHAR(c)	(isalnum(c) || (c) == '.' || (c) == ':' || \
169 				    (c) == '-' || (c) == '_')
170 
171 #ifdef	__cplusplus
172 }
173 #endif
174 
175 #endif	/* _LIBSYSEVENT_IMPL_H */
176