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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #ifndef	_LIBSYSEVENT_H
26 #define	_LIBSYSEVENT_H
27 
28 #include <stdio.h>
29 #include <thread.h>
30 #include <stddef.h>
31 #include <synch.h>
32 #include <sys/types.h>
33 #include <sys/sysevent.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 #define	SYSEVENTD_CHAN	"syseventd_channel"
40 
41 /* sysevent loadable module ops structure and related defines */
42 #define	SE_MAX_RETRY_LIMIT	3
43 #define	SE_RETRY_TIME		1 /* seconds */
44 #define	SE_NO_RETRY		1
45 #define	SE_MAJOR_VERSION	0
46 #define	SE_MINOR_VERSION	0
47 
48 struct slm_mod_ops {
49 	int	major_version;
50 	int	minor_version;
51 	int	retry_limit;
52 	int	(*deliver_event)();
53 };
54 
55 typedef void *sysevent_handle_t;
56 typedef void *subscriber_t;
57 
58 int sysevent_post_event(char *event_class, char *event_subclass, char *vendor,
59 	char *pub_name, nvlist_t *attr_list, sysevent_id_t *eid);
60 sysevent_t *sysevent_dup(sysevent_t *ev);
61 void sysevent_free(sysevent_t *ev);
62 int sysevent_get_attr_list(sysevent_t *ev, nvlist_t **nvlist);
63 int sysevent_lookup_attr(sysevent_t *ev, char *name, int datatype,
64 	sysevent_value_t *se_value);
65 sysevent_attr_t *sysevent_attr_next(sysevent_t *ev, sysevent_attr_t *attr);
66 char *sysevent_attr_name(sysevent_attr_t *attr);
67 int sysevent_attr_value(sysevent_attr_t *attr, sysevent_value_t *se_value);
68 int sysevent_get_class(sysevent_t *ev);
69 char *sysevent_get_class_name(sysevent_t *ev);
70 int sysevent_get_subclass(sysevent_t *ev);
71 char *sysevent_get_subclass_name(sysevent_t *ev);
72 char *sysevent_get_pub(sysevent_t *ev);
73 char *sysevent_get_vendor_name(sysevent_t *ev);
74 char *sysevent_get_pub_name(sysevent_t *ev);
75 void sysevent_get_pid(sysevent_t *ev, pid_t *pid);
76 uint64_t sysevent_get_seq(sysevent_t *ev);
77 void sysevent_get_time(sysevent_t *ev, hrtime_t *etime);
78 size_t sysevent_get_size(sysevent_t *ev);
79 
80 /* syseventd subscriber interfaces */
81 sysevent_handle_t *sysevent_bind_handle(void (*event_handler)(sysevent_t *ev));
82 sysevent_handle_t *sysevent_bind_xhandle(void (*event_handler)(sysevent_t *ev),
83     sysevent_subattr_t *);
84 void sysevent_unbind_handle(sysevent_handle_t *sysevent_hdl);
85 int sysevent_subscribe_event(sysevent_handle_t *sysevent_hdl,
86 	const char *event_class, const char **event_subclass_list,
87 	int num_subclasses);
88 void sysevent_unsubscribe_event(sysevent_handle_t *sysevent_hdl,
89 	const char *event_class);
90 
91 /* Subscriber private interfaces */
92 sysevent_t *sysevent_alloc_event(char *event_class, char *event_subclass,
93 	char *vendor, char *pub_name, nvlist_t *attr_list);
94 int sysevent_send_event(sysevent_handle_t *shp, sysevent_t *ev);
95 sysevent_handle_t *sysevent_open_channel(const char *channel);
96 sysevent_handle_t *sysevent_open_channel_alt(const char *channel_path);
97 void sysevent_close_channel(sysevent_handle_t *shp);
98 int sysevent_bind_subscriber(sysevent_handle_t *shp,
99 	void (*event_handler)(sysevent_t *ev));
100 int sysevent_bind_xsubscriber(sysevent_handle_t *shp,
101 	void (*event_handler)(sysevent_t *ev), sysevent_subattr_t *);
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