/*
 * Copyright (c) 2000 by Sun Microsystems, Inc.
 * All rights reserved.
 */

#ifndef	_LIBSYSEVENT_H
#define	_LIBSYSEVENT_H

#pragma ident	"@(#)libsysevent.h	1.1	00/05/11 SMI"

#include <stdio.h>
#include <thread.h>
#include <stddef.h>
#include <synch.h>
#include <sys/types.h>
#include <sys/sysevent.h>

#ifdef	__cplusplus
extern "C" {
#endif

/* sysevent loadable module ops structure and related defines */
#define	SE_MAX_RETRY_LIMIT	3
#define	SE_RETRY_TIME		1 /* seconds */
#define	SE_NO_RETRY		1
#define	SE_MAJOR_VERSION	0
#define	SE_MINOR_VERSION	0

struct slm_mod_ops {
	int	major_version;
	int	minor_version;
	int	retry_limit;
	int	(*deliver_event)();
};

/* sysevent opaque subscriber handle and related data structures */

#define	DOOR_NAME_SIZE	64

typedef struct sysevent_handle {
	int		subscriber_id;		/* event consumer unique id */
	int		dispatch_id;		/* event dispatcher unique id */
	int		bound;			/* bound to an event class ? */
	int		result;			/* post event result */
	char		door_name[DOOR_NAME_SIZE];	/* producer-consumer */
							/* communication door */
	mutex_t		lock;			/* lock to protect access */
} sysevent_handle_t;

/* libsysevent interfaces */
sysevent_t *sysevent_alloc(char *class, char *subclass, char *pub);
sysevent_t *sysevent_dup(sysevent_t *ev);
void sysevent_free(sysevent_t *ev);
sysevent_t *se_repack(sysevent_t *ev);
int sysevent_lookup_attr(sysevent_t *ev, char *name, int datatype,
	sysevent_value_t *se_value);
sysevent_attr_t *sysevent_attr_next(sysevent_t *ev, sysevent_attr_t *attr);
char *sysevent_attr_name(sysevent_attr_t *attr);
int sysevent_attr_value(sysevent_attr_t *attr, sysevent_value_t *se_value);
int sysevent_get_class(sysevent_t *ev);
char *sysevent_get_class_name(sysevent_t *ev);
int sysevent_get_subclass(sysevent_t *ev);
char *sysevent_get_subclass_name(sysevent_t *ev);
char *sysevent_get_pub(sysevent_t *ev);
uint64_t sysevent_get_seq(sysevent_t *ev);
void sysevent_get_time(sysevent_t *ev, hrtime_t *etime);
size_t sysevent_get_size(sysevent_t *ev);

/* devfsadm private interfaces */
int log_sysevent(sysevent_t *ev, int flag, sysevent_id_t *eid);
int sysevent_add_attr(sysevent_attr_list_t **ev_attr_list, char *name,
	sysevent_value_t *se_value);
void sysevent_free_attr(sysevent_attr_list_t *ev_attr_list);
int sysevent_attach_attributes(sysevent_t *ev,
	sysevent_attr_list_t *ev_attr_list);
void sysevent_detach_attributes(sysevent_t *ev);
int sysevent_post_event(sysevent_handle_t *sysevent_hdl, sysevent_t *ev);
sysevent_handle_t *sysevent_open_channel(char *endpoint);
int sysevent_bind_subscriber(sysevent_handle_t *se_handle,
	int (*callback)(sysevent_t *ev, size_t datalen), char *event_list);

/* Debug interfaces */
void se_print(FILE *fp, sysevent_t *);

#ifdef	__cplusplus
}
#endif

#endif	/* _LIBSYSEVENT_H */
