xref: /titanic_51/usr/src/lib/libsysevent/libsysevent.h (revision 1e49577a7fcde812700ded04431b49d67cc57d6d)
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 2000-2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_LIBSYSEVENT_H
28 #define	_LIBSYSEVENT_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <stdio.h>
33 #include <thread.h>
34 #include <stddef.h>
35 #include <synch.h>
36 #include <sys/types.h>
37 #include <sys/sysevent.h>
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 #define	SYSEVENTD_CHAN	"syseventd_channel"
44 
45 /* sysevent loadable module ops structure and related defines */
46 #define	SE_MAX_RETRY_LIMIT	3
47 #define	SE_RETRY_TIME		1 /* seconds */
48 #define	SE_NO_RETRY		1
49 #define	SE_MAJOR_VERSION	0
50 #define	SE_MINOR_VERSION	0
51 
52 struct slm_mod_ops {
53 	int	major_version;
54 	int	minor_version;
55 	int	retry_limit;
56 	int	(*deliver_event)();
57 };
58 
59 typedef void *sysevent_handle_t;
60 typedef void *subscriber_t;
61 
62 int sysevent_post_event(char *event_class, char *event_subclass, char *vendor,
63 	char *pub_name, nvlist_t *attr_list, sysevent_id_t *eid);
64 sysevent_t *sysevent_dup(sysevent_t *ev);
65 void sysevent_free(sysevent_t *ev);
66 int sysevent_get_attr_list(sysevent_t *ev, nvlist_t **nvlist);
67 int sysevent_lookup_attr(sysevent_t *ev, char *name, int datatype,
68 	sysevent_value_t *se_value);
69 sysevent_attr_t *sysevent_attr_next(sysevent_t *ev, sysevent_attr_t *attr);
70 char *sysevent_attr_name(sysevent_attr_t *attr);
71 int sysevent_attr_value(sysevent_attr_t *attr, sysevent_value_t *se_value);
72 int sysevent_get_class(sysevent_t *ev);
73 char *sysevent_get_class_name(sysevent_t *ev);
74 int sysevent_get_subclass(sysevent_t *ev);
75 char *sysevent_get_subclass_name(sysevent_t *ev);
76 char *sysevent_get_pub(sysevent_t *ev);
77 char *sysevent_get_vendor_name(sysevent_t *ev);
78 char *sysevent_get_pub_name(sysevent_t *ev);
79 void sysevent_get_pid(sysevent_t *ev, pid_t *pid);
80 uint64_t sysevent_get_seq(sysevent_t *ev);
81 void sysevent_get_time(sysevent_t *ev, hrtime_t *etime);
82 size_t sysevent_get_size(sysevent_t *ev);
83 
84 /* syseventd subscriber interfaces */
85 sysevent_handle_t *sysevent_bind_handle(void (*event_handler)(sysevent_t *ev));
86 void sysevent_unbind_handle(sysevent_handle_t *sysevent_hdl);
87 int sysevent_subscribe_event(sysevent_handle_t *sysevent_hdl,
88 	const char *event_class, const char **event_subclass_list,
89 	int num_subclasses);
90 void sysevent_unsubscribe_event(sysevent_handle_t *sysevent_hdl,
91 	const char *event_class);
92 
93 /* Subscriber private interfaces */
94 sysevent_t *sysevent_alloc_event(char *event_class, char *event_subclass,
95 	char *vendor, char *pub_name, nvlist_t *attr_list);
96 int sysevent_send_event(sysevent_handle_t *shp, sysevent_t *ev);
97 sysevent_handle_t *sysevent_open_channel(const char *channel);
98 sysevent_handle_t *sysevent_open_channel_alt(const char *channel_path);
99 void sysevent_close_channel(sysevent_handle_t *shp);
100 int sysevent_bind_subscriber(sysevent_handle_t *shp,
101 	void (*event_handler)(sysevent_t *ev));
102 void sysevent_unbind_subscriber(sysevent_handle_t *shp);
103 int sysevent_bind_publisher(sysevent_handle_t *shp);
104 void sysevent_unbind_publisher(sysevent_handle_t *shp);
105 int sysevent_register_event(sysevent_handle_t *shp, const char *event_class,
106 	const char **event_subclass_list, int num_subclasses);
107 void sysevent_unregister_event(sysevent_handle_t *shp,
108 	const char *event_class);
109 void sysevent_cleanup_subscribers(sysevent_handle_t *shp);
110 void sysevent_cleanup_publishers(sysevent_handle_t *shp);
111 
112 /* Debug interfaces */
113 void se_print(FILE *fp, sysevent_t *);
114 
115 #ifdef	__cplusplus
116 }
117 #endif
118 
119 #endif	/* _LIBSYSEVENT_H */
120