xref: /onnv-gate/usr/src/lib/libsysevent/libsysevent_impl.h (revision 11102:b91faef0c984)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*11102SGavin.Maltby@Sun.COM  * Common Development and Distribution License (the "License").
6*11102SGavin.Maltby@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21*11102SGavin.Maltby@Sun.COM 
220Sstevel@tonic-gate /*
23*11102SGavin.Maltby@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #ifndef	_LIBSYSEVENT_IMPL_H
280Sstevel@tonic-gate #define	_LIBSYSEVENT_IMPL_H
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #ifdef	__cplusplus
310Sstevel@tonic-gate extern "C" {
320Sstevel@tonic-gate #endif
330Sstevel@tonic-gate 
340Sstevel@tonic-gate /*
350Sstevel@tonic-gate  * libsysevent implementation-specific structures
360Sstevel@tonic-gate  */
370Sstevel@tonic-gate 
380Sstevel@tonic-gate /* sysevent publisher/subscriber handle and related data structures */
390Sstevel@tonic-gate 
400Sstevel@tonic-gate #define	CHAN_PATH	"/var/run/sysevent_channels"
410Sstevel@tonic-gate #define	REG_DOOR	"reg_door"
420Sstevel@tonic-gate 
430Sstevel@tonic-gate /* Subscription size values */
440Sstevel@tonic-gate #define	MAX_SUBSCRIPTION_SZ	1024
450Sstevel@tonic-gate 
460Sstevel@tonic-gate /* Sysevent Channel Handle */
470Sstevel@tonic-gate typedef struct sysevent_impl_handle {
480Sstevel@tonic-gate 	int		sh_bound;		/* Channel bind status */
490Sstevel@tonic-gate 	int		sh_type;		/* pub/sub channel binding */
500Sstevel@tonic-gate 	uint32_t	sh_id;			/* pub/sub within channel */
510Sstevel@tonic-gate 	int		sh_door_desc;		/* Service door descrip */
520Sstevel@tonic-gate 	char		*sh_door_name;		/* Service door */
530Sstevel@tonic-gate 	char		*sh_channel_name;	/* Event Channel name */
540Sstevel@tonic-gate 	char		*sh_channel_path;	/* Full path to Event Chan */
550Sstevel@tonic-gate 	void		*sh_priv_data;	/* Pub/Sub private data */
560Sstevel@tonic-gate 	mutex_t		sh_lock;	/* lock to protect access */
570Sstevel@tonic-gate } sysevent_impl_hdl_t;
580Sstevel@tonic-gate 
590Sstevel@tonic-gate /* Sysevent queue for subscriber delivery */
600Sstevel@tonic-gate typedef struct sysevent_queue {
610Sstevel@tonic-gate 	struct sysevent_queue	*sq_next;
620Sstevel@tonic-gate 	sysevent_t		*sq_ev;
630Sstevel@tonic-gate } sysevent_queue_t;
640Sstevel@tonic-gate 
650Sstevel@tonic-gate /*
660Sstevel@tonic-gate  * Subscriber private data stored in the sysevent channel handle
670Sstevel@tonic-gate  */
680Sstevel@tonic-gate typedef struct subscriber_priv {
690Sstevel@tonic-gate 	cond_t			sp_cv;		/* cv for event synch */
700Sstevel@tonic-gate 	mutex_t			sp_qlock;	/* event queue lock */
710Sstevel@tonic-gate 	char			*sp_door_name;	/* Publisher reg door */
720Sstevel@tonic-gate 	thread_t		sp_handler_tid; /* delivery handler thread id */
730Sstevel@tonic-gate 	struct sysevent_queue	*sp_evq_head;   /* event q head */
740Sstevel@tonic-gate 	struct sysevent_queue	*sp_evq_tail;   /* event q tail */
750Sstevel@tonic-gate 	void			(*sp_func)(sysevent_t *ev); /* deliver func */
760Sstevel@tonic-gate } subscriber_priv_t;
770Sstevel@tonic-gate 
780Sstevel@tonic-gate /* Subscriber information stored on the publisher side */
790Sstevel@tonic-gate typedef struct subscriber_data {
800Sstevel@tonic-gate 	int			sd_flag;		/* flag */
810Sstevel@tonic-gate 	char			*sd_door_name;	/* Client door name */
820Sstevel@tonic-gate } subscriber_data_t;
830Sstevel@tonic-gate 
840Sstevel@tonic-gate /* Publisher private data stored in the sysevent channel handle */
850Sstevel@tonic-gate typedef struct publisher_priv {
860Sstevel@tonic-gate 	struct class_lst	*pp_class_hash[CLASS_HASH_SZ + 1];
870Sstevel@tonic-gate 	subscriber_data_t	*pp_subscriber_list[MAX_SUBSCRIBERS + 1];
880Sstevel@tonic-gate } publisher_priv_t;
890Sstevel@tonic-gate 
900Sstevel@tonic-gate /* Subscriber flag values */
910Sstevel@tonic-gate #define	ACTIVE		1	/* Active subscriber */
920Sstevel@tonic-gate #define	SEND_AGAIN	2	/* Resend of event requested */
930Sstevel@tonic-gate 
940Sstevel@tonic-gate /* Sysevent handle access */
950Sstevel@tonic-gate #define	SYSEVENT_IMPL_HNDL(sehp)	((sysevent_impl_hdl_t *)(void *)(sehp))
960Sstevel@tonic-gate #define	SH_BOUND(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_bound)
970Sstevel@tonic-gate #define	SH_TYPE(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_type)
980Sstevel@tonic-gate #define	SH_RESULT(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_result)
990Sstevel@tonic-gate #define	SH_ID(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_id)
1000Sstevel@tonic-gate #define	SH_DOOR_DESC(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_door_desc)
1010Sstevel@tonic-gate #define	SH_DOOR_NAME(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_door_name)
1020Sstevel@tonic-gate #define	SH_CHANNEL_NAME(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_channel_name)
1030Sstevel@tonic-gate #define	SH_CHANNEL_PATH(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_channel_path)
1040Sstevel@tonic-gate #define	SH_LOCK(sehp)		(&(SYSEVENT_IMPL_HNDL(sehp)->sh_lock))
1050Sstevel@tonic-gate #define	SH_PRIV_DATA(sehp)	(SYSEVENT_IMPL_HNDL(sehp)->sh_priv_data)
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate #define	SH_CLASS_HASH(sehp)	(((publisher_priv_t *) \
1080Sstevel@tonic-gate 	SH_PRIV_DATA(sehp))->pp_class_hash)
1090Sstevel@tonic-gate #define	SH_SUBSCRIBER(sehp, id)	(((publisher_priv_t *) \
1100Sstevel@tonic-gate 	SH_PRIV_DATA(sehp))->pp_subscriber_list[id])
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate /*
1130Sstevel@tonic-gate  * GPEC Interface definitions
1140Sstevel@tonic-gate  */
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate typedef struct evchan_subscriber evchan_subscr_t;
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate typedef struct evchan_sub_head {
1190Sstevel@tonic-gate 	evchan_subscr_t *evchan_sub_next;
1200Sstevel@tonic-gate } evchan_sub_head_t;
1210Sstevel@tonic-gate 
1220Sstevel@tonic-gate /* Event channel handle */
1230Sstevel@tonic-gate typedef struct evchan_impl_handle {
1240Sstevel@tonic-gate 	pid_t		ev_pid;		/* verify descend via fork() */
1250Sstevel@tonic-gate 	int		ev_fd;		/* descriptor for sev driver */
1260Sstevel@tonic-gate 	mutex_t		ev_lock;	/* lock to protect this structure */
1270Sstevel@tonic-gate 	evchan_sub_head_t ev_sub;	/* anchor of subscriber list */
1280Sstevel@tonic-gate } evchan_impl_hdl_t;
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate /* Evchan handle access */
1310Sstevel@tonic-gate #define	EVCHAN_IMPL_HNDL(evcp)	((evchan_impl_hdl_t *)(void *)(evcp))
1320Sstevel@tonic-gate #define	EV_PID(evcp)		(EVCHAN_IMPL_HNDL(evcp)->ev_pid)
1330Sstevel@tonic-gate #define	EV_FD(evcp)		(EVCHAN_IMPL_HNDL(evcp)->ev_fd)
1340Sstevel@tonic-gate #define	EV_LOCK(evcp)		(&(EVCHAN_IMPL_HNDL(evcp)->ev_lock))
1350Sstevel@tonic-gate #define	EV_SUB(evcp)		(&(EVCHAN_IMPL_HNDL(evcp)->ev_sub))
1360Sstevel@tonic-gate #define	EV_SUB_NEXT(evcp)	(EVCHAN_IMPL_HNDL(evcp)->ev_sub.evchan_sub_next)
1370Sstevel@tonic-gate 
138*11102SGavin.Maltby@Sun.COM struct sysevent_subattr_impl {
139*11102SGavin.Maltby@Sun.COM 	door_xcreate_server_func_t *xs_thrcreate;
140*11102SGavin.Maltby@Sun.COM 	void *xs_thrcreate_cookie;
141*11102SGavin.Maltby@Sun.COM 	door_xcreate_thrsetup_func_t *xs_thrsetup;
142*11102SGavin.Maltby@Sun.COM 	void *xs_thrsetup_cookie;
143*11102SGavin.Maltby@Sun.COM 	pthread_attr_t *xs_thrattr;
144*11102SGavin.Maltby@Sun.COM 	sigset_t xs_sigmask;
145*11102SGavin.Maltby@Sun.COM };
146*11102SGavin.Maltby@Sun.COM 
1470Sstevel@tonic-gate /*
1480Sstevel@tonic-gate  * Subscriber private data
1490Sstevel@tonic-gate  */
1500Sstevel@tonic-gate struct evchan_subscriber {
1510Sstevel@tonic-gate 	evchan_subscr_t *evsub_next;	/* list of subscribers */
1520Sstevel@tonic-gate 	evchan_impl_hdl_t *ev_subhead;	/* link back to channel data */
1530Sstevel@tonic-gate 	int evsub_door_desc;		/* Service door descriptor */
1540Sstevel@tonic-gate 	char *evsub_sid;		/* identifier of subscriber */
1550Sstevel@tonic-gate 	void *evsub_cookie;		/* subscriber cookie */
1560Sstevel@tonic-gate 	int (*evsub_func)(sysevent_t *, void *); /* subscriber event handler */
157*11102SGavin.Maltby@Sun.COM 	struct sysevent_subattr_impl *evsub_attr;
158*11102SGavin.Maltby@Sun.COM 	uint32_t evsub_state;
1590Sstevel@tonic-gate };
1600Sstevel@tonic-gate 
161*11102SGavin.Maltby@Sun.COM #define	EVCHAN_SUB_STATE_ACTIVE		1
162*11102SGavin.Maltby@Sun.COM #define	EVCHAN_SUB_STATE_CLOSING	2
163*11102SGavin.Maltby@Sun.COM 
1640Sstevel@tonic-gate /* Access to subscriber data */
1650Sstevel@tonic-gate #define	EVCHAN_SUBSCR(subp)	((evchan_subscr_t *)(subp))
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate /* Characters for channel name syntax */
1680Sstevel@tonic-gate #define	EVCH_ISCHANCHAR(c)	(isalnum(c) || (c) == '.' || (c) == ':' || \
1690Sstevel@tonic-gate 				    (c) == '-' || (c) == '_')
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate #ifdef	__cplusplus
1720Sstevel@tonic-gate }
1730Sstevel@tonic-gate #endif
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate #endif	/* _LIBSYSEVENT_IMPL_H */
176