17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*49b225e1SGavin Maltby * Common Development and Distribution License (the "License"). 6*49b225e1SGavin Maltby * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21*49b225e1SGavin Maltby 227c478bd9Sstevel@tonic-gate /* 23*49b225e1SGavin Maltby * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #ifndef _LIBSYSEVENT_IMPL_H 287c478bd9Sstevel@tonic-gate #define _LIBSYSEVENT_IMPL_H 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #ifdef __cplusplus 317c478bd9Sstevel@tonic-gate extern "C" { 327c478bd9Sstevel@tonic-gate #endif 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate /* 357c478bd9Sstevel@tonic-gate * libsysevent implementation-specific structures 367c478bd9Sstevel@tonic-gate */ 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate /* sysevent publisher/subscriber handle and related data structures */ 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate #define CHAN_PATH "/var/run/sysevent_channels" 417c478bd9Sstevel@tonic-gate #define REG_DOOR "reg_door" 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate /* Subscription size values */ 447c478bd9Sstevel@tonic-gate #define MAX_SUBSCRIPTION_SZ 1024 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate /* Sysevent Channel Handle */ 477c478bd9Sstevel@tonic-gate typedef struct sysevent_impl_handle { 487c478bd9Sstevel@tonic-gate int sh_bound; /* Channel bind status */ 497c478bd9Sstevel@tonic-gate int sh_type; /* pub/sub channel binding */ 507c478bd9Sstevel@tonic-gate uint32_t sh_id; /* pub/sub within channel */ 517c478bd9Sstevel@tonic-gate int sh_door_desc; /* Service door descrip */ 527c478bd9Sstevel@tonic-gate char *sh_door_name; /* Service door */ 537c478bd9Sstevel@tonic-gate char *sh_channel_name; /* Event Channel name */ 547c478bd9Sstevel@tonic-gate char *sh_channel_path; /* Full path to Event Chan */ 557c478bd9Sstevel@tonic-gate void *sh_priv_data; /* Pub/Sub private data */ 567c478bd9Sstevel@tonic-gate mutex_t sh_lock; /* lock to protect access */ 577c478bd9Sstevel@tonic-gate } sysevent_impl_hdl_t; 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate /* Sysevent queue for subscriber delivery */ 607c478bd9Sstevel@tonic-gate typedef struct sysevent_queue { 617c478bd9Sstevel@tonic-gate struct sysevent_queue *sq_next; 627c478bd9Sstevel@tonic-gate sysevent_t *sq_ev; 637c478bd9Sstevel@tonic-gate } sysevent_queue_t; 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate /* 667c478bd9Sstevel@tonic-gate * Subscriber private data stored in the sysevent channel handle 677c478bd9Sstevel@tonic-gate */ 687c478bd9Sstevel@tonic-gate typedef struct subscriber_priv { 697c478bd9Sstevel@tonic-gate cond_t sp_cv; /* cv for event synch */ 707c478bd9Sstevel@tonic-gate mutex_t sp_qlock; /* event queue lock */ 717c478bd9Sstevel@tonic-gate char *sp_door_name; /* Publisher reg door */ 727c478bd9Sstevel@tonic-gate thread_t sp_handler_tid; /* delivery handler thread id */ 737c478bd9Sstevel@tonic-gate struct sysevent_queue *sp_evq_head; /* event q head */ 747c478bd9Sstevel@tonic-gate struct sysevent_queue *sp_evq_tail; /* event q tail */ 757c478bd9Sstevel@tonic-gate void (*sp_func)(sysevent_t *ev); /* deliver func */ 767c478bd9Sstevel@tonic-gate } subscriber_priv_t; 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate /* Subscriber information stored on the publisher side */ 797c478bd9Sstevel@tonic-gate typedef struct subscriber_data { 807c478bd9Sstevel@tonic-gate int sd_flag; /* flag */ 817c478bd9Sstevel@tonic-gate char *sd_door_name; /* Client door name */ 827c478bd9Sstevel@tonic-gate } subscriber_data_t; 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate /* Publisher private data stored in the sysevent channel handle */ 857c478bd9Sstevel@tonic-gate typedef struct publisher_priv { 867c478bd9Sstevel@tonic-gate struct class_lst *pp_class_hash[CLASS_HASH_SZ + 1]; 877c478bd9Sstevel@tonic-gate subscriber_data_t *pp_subscriber_list[MAX_SUBSCRIBERS + 1]; 887c478bd9Sstevel@tonic-gate } publisher_priv_t; 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate /* Subscriber flag values */ 917c478bd9Sstevel@tonic-gate #define ACTIVE 1 /* Active subscriber */ 927c478bd9Sstevel@tonic-gate #define SEND_AGAIN 2 /* Resend of event requested */ 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate /* Sysevent handle access */ 957c478bd9Sstevel@tonic-gate #define SYSEVENT_IMPL_HNDL(sehp) ((sysevent_impl_hdl_t *)(void *)(sehp)) 967c478bd9Sstevel@tonic-gate #define SH_BOUND(sehp) (SYSEVENT_IMPL_HNDL(sehp)->sh_bound) 977c478bd9Sstevel@tonic-gate #define SH_TYPE(sehp) (SYSEVENT_IMPL_HNDL(sehp)->sh_type) 987c478bd9Sstevel@tonic-gate #define SH_RESULT(sehp) (SYSEVENT_IMPL_HNDL(sehp)->sh_result) 997c478bd9Sstevel@tonic-gate #define SH_ID(sehp) (SYSEVENT_IMPL_HNDL(sehp)->sh_id) 1007c478bd9Sstevel@tonic-gate #define SH_DOOR_DESC(sehp) (SYSEVENT_IMPL_HNDL(sehp)->sh_door_desc) 1017c478bd9Sstevel@tonic-gate #define SH_DOOR_NAME(sehp) (SYSEVENT_IMPL_HNDL(sehp)->sh_door_name) 1027c478bd9Sstevel@tonic-gate #define SH_CHANNEL_NAME(sehp) (SYSEVENT_IMPL_HNDL(sehp)->sh_channel_name) 1037c478bd9Sstevel@tonic-gate #define SH_CHANNEL_PATH(sehp) (SYSEVENT_IMPL_HNDL(sehp)->sh_channel_path) 1047c478bd9Sstevel@tonic-gate #define SH_LOCK(sehp) (&(SYSEVENT_IMPL_HNDL(sehp)->sh_lock)) 1057c478bd9Sstevel@tonic-gate #define SH_PRIV_DATA(sehp) (SYSEVENT_IMPL_HNDL(sehp)->sh_priv_data) 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate #define SH_CLASS_HASH(sehp) (((publisher_priv_t *) \ 1087c478bd9Sstevel@tonic-gate SH_PRIV_DATA(sehp))->pp_class_hash) 1097c478bd9Sstevel@tonic-gate #define SH_SUBSCRIBER(sehp, id) (((publisher_priv_t *) \ 1107c478bd9Sstevel@tonic-gate SH_PRIV_DATA(sehp))->pp_subscriber_list[id]) 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate /* 1137c478bd9Sstevel@tonic-gate * GPEC Interface definitions 1147c478bd9Sstevel@tonic-gate */ 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate typedef struct evchan_subscriber evchan_subscr_t; 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate typedef struct evchan_sub_head { 1197c478bd9Sstevel@tonic-gate evchan_subscr_t *evchan_sub_next; 1207c478bd9Sstevel@tonic-gate } evchan_sub_head_t; 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate /* Event channel handle */ 1237c478bd9Sstevel@tonic-gate typedef struct evchan_impl_handle { 1247c478bd9Sstevel@tonic-gate pid_t ev_pid; /* verify descend via fork() */ 1257c478bd9Sstevel@tonic-gate int ev_fd; /* descriptor for sev driver */ 1267c478bd9Sstevel@tonic-gate mutex_t ev_lock; /* lock to protect this structure */ 1277c478bd9Sstevel@tonic-gate evchan_sub_head_t ev_sub; /* anchor of subscriber list */ 1287c478bd9Sstevel@tonic-gate } evchan_impl_hdl_t; 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate /* Evchan handle access */ 1317c478bd9Sstevel@tonic-gate #define EVCHAN_IMPL_HNDL(evcp) ((evchan_impl_hdl_t *)(void *)(evcp)) 1327c478bd9Sstevel@tonic-gate #define EV_PID(evcp) (EVCHAN_IMPL_HNDL(evcp)->ev_pid) 1337c478bd9Sstevel@tonic-gate #define EV_FD(evcp) (EVCHAN_IMPL_HNDL(evcp)->ev_fd) 1347c478bd9Sstevel@tonic-gate #define EV_LOCK(evcp) (&(EVCHAN_IMPL_HNDL(evcp)->ev_lock)) 1357c478bd9Sstevel@tonic-gate #define EV_SUB(evcp) (&(EVCHAN_IMPL_HNDL(evcp)->ev_sub)) 1367c478bd9Sstevel@tonic-gate #define EV_SUB_NEXT(evcp) (EVCHAN_IMPL_HNDL(evcp)->ev_sub.evchan_sub_next) 1377c478bd9Sstevel@tonic-gate 138*49b225e1SGavin Maltby struct sysevent_subattr_impl { 139*49b225e1SGavin Maltby door_xcreate_server_func_t *xs_thrcreate; 140*49b225e1SGavin Maltby void *xs_thrcreate_cookie; 141*49b225e1SGavin Maltby door_xcreate_thrsetup_func_t *xs_thrsetup; 142*49b225e1SGavin Maltby void *xs_thrsetup_cookie; 143*49b225e1SGavin Maltby pthread_attr_t *xs_thrattr; 144*49b225e1SGavin Maltby sigset_t xs_sigmask; 145*49b225e1SGavin Maltby }; 146*49b225e1SGavin Maltby 1477c478bd9Sstevel@tonic-gate /* 1487c478bd9Sstevel@tonic-gate * Subscriber private data 1497c478bd9Sstevel@tonic-gate */ 1507c478bd9Sstevel@tonic-gate struct evchan_subscriber { 1517c478bd9Sstevel@tonic-gate evchan_subscr_t *evsub_next; /* list of subscribers */ 1527c478bd9Sstevel@tonic-gate evchan_impl_hdl_t *ev_subhead; /* link back to channel data */ 1537c478bd9Sstevel@tonic-gate int evsub_door_desc; /* Service door descriptor */ 1547c478bd9Sstevel@tonic-gate char *evsub_sid; /* identifier of subscriber */ 1557c478bd9Sstevel@tonic-gate void *evsub_cookie; /* subscriber cookie */ 1567c478bd9Sstevel@tonic-gate int (*evsub_func)(sysevent_t *, void *); /* subscriber event handler */ 157*49b225e1SGavin Maltby struct sysevent_subattr_impl *evsub_attr; 158*49b225e1SGavin Maltby uint32_t evsub_state; 1597c478bd9Sstevel@tonic-gate }; 1607c478bd9Sstevel@tonic-gate 161*49b225e1SGavin Maltby #define EVCHAN_SUB_STATE_ACTIVE 1 162*49b225e1SGavin Maltby #define EVCHAN_SUB_STATE_CLOSING 2 163*49b225e1SGavin Maltby 1647c478bd9Sstevel@tonic-gate /* Access to subscriber data */ 1657c478bd9Sstevel@tonic-gate #define EVCHAN_SUBSCR(subp) ((evchan_subscr_t *)(subp)) 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate /* Characters for channel name syntax */ 1687c478bd9Sstevel@tonic-gate #define EVCH_ISCHANCHAR(c) (isalnum(c) || (c) == '.' || (c) == ':' || \ 1697c478bd9Sstevel@tonic-gate (c) == '-' || (c) == '_') 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1727c478bd9Sstevel@tonic-gate } 1737c478bd9Sstevel@tonic-gate #endif 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate #endif /* _LIBSYSEVENT_IMPL_H */ 176