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