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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2002-2003 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * libsysevent implementation-specific structures
38  */
39 
40 /* sysevent publisher/subscriber handle and related data structures */
41 
42 #define	CHAN_PATH	"/var/run/sysevent_channels"
43 #define	REG_DOOR	"reg_door"
44 
45 /* Subscription size values */
46 #define	MAX_SUBSCRIPTION_SZ	1024
47 
48 /* Sysevent Channel Handle */
49 typedef struct sysevent_impl_handle {
50 	int		sh_bound;		/* Channel bind status */
51 	int		sh_type;		/* pub/sub channel binding */
52 	uint32_t	sh_id;			/* pub/sub within channel */
53 	int		sh_door_desc;		/* Service door descrip */
54 	char		*sh_door_name;		/* Service door */
55 	char		*sh_channel_name;	/* Event Channel name */
56 	char		*sh_channel_path;	/* Full path to Event Chan */
57 	void		*sh_priv_data;	/* Pub/Sub private data */
58 	mutex_t		sh_lock;	/* lock to protect access */
59 } sysevent_impl_hdl_t;
60 
61 /* Sysevent queue for subscriber delivery */
62 typedef struct sysevent_queue {
63 	struct sysevent_queue	*sq_next;
64 	sysevent_t		*sq_ev;
65 } sysevent_queue_t;
66 
67 /*
68  * Subscriber private data stored in the sysevent channel handle
69  */
70 typedef struct subscriber_priv {
71 	cond_t			sp_cv;		/* cv for event synch */
72 	mutex_t			sp_qlock;	/* event queue lock */
73 	char			*sp_door_name;	/* Publisher reg door */
74 	thread_t		sp_handler_tid; /* delivery handler thread id */
75 	struct sysevent_queue	*sp_evq_head;   /* event q head */
76 	struct sysevent_queue	*sp_evq_tail;   /* event q tail */
77 	void			(*sp_func)(sysevent_t *ev); /* deliver func */
78 } subscriber_priv_t;
79 
80 /* Subscriber information stored on the publisher side */
81 typedef struct subscriber_data {
82 	int			sd_flag;		/* flag */
83 	char			*sd_door_name;	/* Client door name */
84 } subscriber_data_t;
85 
86 /* Publisher private data stored in the sysevent channel handle */
87 typedef struct publisher_priv {
88 	struct class_lst	*pp_class_hash[CLASS_HASH_SZ + 1];
89 	subscriber_data_t	*pp_subscriber_list[MAX_SUBSCRIBERS + 1];
90 } publisher_priv_t;
91 
92 /* Subscriber flag values */
93 #define	ACTIVE		1	/* Active subscriber */
94 #define	SEND_AGAIN	2	/* Resend of event requested */
95 
96 /* Sysevent handle access */
97 #define	SYSEVENT_IMPL_HNDL(sehp)	((sysevent_impl_hdl_t *)(void *)(sehp))
98 #define	SH_BOUND(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_bound)
99 #define	SH_TYPE(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_type)
100 #define	SH_RESULT(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_result)
101 #define	SH_ID(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_id)
102 #define	SH_DOOR_DESC(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_door_desc)
103 #define	SH_DOOR_NAME(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_door_name)
104 #define	SH_CHANNEL_NAME(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_channel_name)
105 #define	SH_CHANNEL_PATH(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_channel_path)
106 #define	SH_LOCK(sehp)		(&(SYSEVENT_IMPL_HNDL(sehp)->sh_lock))
107 #define	SH_PRIV_DATA(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_priv_data)
108 
109 #define	SH_CLASS_HASH(sehp)	(((publisher_priv_t *) \
110 	SH_PRIV_DATA(sehp))->pp_class_hash)
111 #define	SH_SUBSCRIBER(sehp, id)	(((publisher_priv_t *) \
112 	SH_PRIV_DATA(sehp))->pp_subscriber_list[id])
113 
114 /*
115  * GPEC Interface definitions
116  */
117 
118 typedef struct evchan_subscriber evchan_subscr_t;
119 
120 typedef struct evchan_sub_head {
121 	evchan_subscr_t *evchan_sub_next;
122 } evchan_sub_head_t;
123 
124 /* Event channel handle */
125 typedef struct evchan_impl_handle {
126 	pid_t		ev_pid;		/* verify descend via fork() */
127 	int		ev_fd;		/* descriptor for sev driver */
128 	mutex_t		ev_lock;	/* lock to protect this structure */
129 	evchan_sub_head_t ev_sub;	/* anchor of subscriber list */
130 } evchan_impl_hdl_t;
131 
132 /* Evchan handle access */
133 #define	EVCHAN_IMPL_HNDL(evcp)	((evchan_impl_hdl_t *)(void *)(evcp))
134 #define	EV_PID(evcp)		(EVCHAN_IMPL_HNDL(evcp)->ev_pid)
135 #define	EV_FD(evcp)		(EVCHAN_IMPL_HNDL(evcp)->ev_fd)
136 #define	EV_LOCK(evcp)		(&(EVCHAN_IMPL_HNDL(evcp)->ev_lock))
137 #define	EV_SUB(evcp)		(&(EVCHAN_IMPL_HNDL(evcp)->ev_sub))
138 #define	EV_SUB_NEXT(evcp)	(EVCHAN_IMPL_HNDL(evcp)->ev_sub.evchan_sub_next)
139 
140 /*
141  * Subscriber private data
142  */
143 struct evchan_subscriber {
144 	evchan_subscr_t *evsub_next;	/* list of subscribers */
145 	evchan_impl_hdl_t *ev_subhead;	/* link back to channel data */
146 	int evsub_door_desc;		/* Service door descriptor */
147 	char *evsub_sid;		/* identifier of subscriber */
148 	void *evsub_cookie;		/* subscriber cookie */
149 	int (*evsub_func)(sysevent_t *, void *); /* subscriber event handler */
150 };
151 
152 /* Access to subscriber data */
153 #define	EVCHAN_SUBSCR(subp)	((evchan_subscr_t *)(subp))
154 
155 /* Characters for channel name syntax */
156 #define	EVCH_ISCHANCHAR(c)	(isalnum(c) || (c) == '.' || (c) == ':' || \
157 				    (c) == '-' || (c) == '_')
158 
159 #ifdef	__cplusplus
160 }
161 #endif
162 
163 #endif	/* _LIBSYSEVENT_IMPL_H */
164