#ifndef _FMD_MODULE_H
#define _FMD_MODULE_H
#include <sys/types.h>
#include <fm/diagcode.h>
#include <pthread.h>
#include <setjmp.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <fmd_conf.h>
#include <fmd_list.h>
#include <fmd_serd.h>
#include <fmd_buf.h>
#include <fmd_api.h>
#include <fmd_eventq.h>
#include <fmd_topo.h>
struct fmd_module;
struct fmd_thread;
struct fmd_idspace;
struct fmd_ustat;
struct fmd_ustat_snap;
typedef struct fmd_modops {
int (*mop_init)(struct fmd_module *);
int (*mop_fini)(struct fmd_module *);
void (*mop_dispatch)(struct fmd_module *, struct fmd_event *);
int (*mop_transport)(struct fmd_module *,
fmd_xprt_t *, struct fmd_event *);
} fmd_modops_t;
typedef struct fmd_modhash {
pthread_rwlock_t mh_lock;
struct fmd_module **mh_hash;
uint_t mh_hashlen;
uint_t mh_nelems;
} fmd_modhash_t;
typedef struct fmd_modstat {
fmd_eventqstat_t ms_evqstat;
fmd_stat_t ms_loadtime;
fmd_stat_t ms_snaptime;
fmd_stat_t ms_accepted;
fmd_stat_t ms_debugdrop;
fmd_stat_t ms_memtotal;
fmd_stat_t ms_memlimit;
fmd_stat_t ms_buftotal;
fmd_stat_t ms_buflimit;
fmd_stat_t ms_thrtotal;
fmd_stat_t ms_thrlimit;
fmd_stat_t ms_doorthrtotal;
fmd_stat_t ms_doorthrlimit;
fmd_stat_t ms_caseopen;
fmd_stat_t ms_casesolved;
fmd_stat_t ms_caseclosed;
fmd_stat_t ms_ckpt_save;
fmd_stat_t ms_ckpt_restore;
fmd_stat_t ms_ckpt_zeroed;
fmd_stat_t ms_ckpt_cnt;
fmd_stat_t ms_ckpt_time;
fmd_stat_t ms_xprtopen;
fmd_stat_t ms_xprtlimit;
fmd_stat_t ms_xprtqlimit;
} fmd_modstat_t;
typedef struct fmd_module {
fmd_list_t mod_list;
pthread_mutex_t mod_lock;
pthread_cond_t mod_cv;
pthread_t mod_owner;
uint_t mod_refs;
uint_t mod_flags;
uint64_t mod_gen;
int mod_error;
jmp_buf mod_jmpbuf;
fmd_modhash_t *mod_hash;
struct fmd_module *mod_next;
char *mod_name;
char *mod_path;
char *mod_ckpt;
nvlist_t *mod_fmri;
const fmd_modops_t *mod_ops;
void *mod_data;
fmd_hdl_info_t *mod_info;
void *mod_spec;
int mod_argc;
fmd_conf_formal_t *mod_argv;
fmd_conf_t *mod_conf;
struct fm_dc_handle **mod_dictv;
int mod_dictc;
size_t mod_codelen;
struct fmd_eventq *mod_queue;
struct fmd_ustat *mod_ustat;
pthread_mutex_t mod_stats_lock;
fmd_modstat_t *mod_stats;
struct fmd_thread *mod_thread;
struct fmd_idspace *mod_threads;
struct fmd_idspace *mod_timerids;
fmd_list_t mod_cases;
fmd_buf_hash_t mod_bufs;
fmd_serd_hash_t mod_serds;
fmd_list_t mod_transports;
fmd_list_t mod_topolist;
fmd_topo_t *mod_topo_current;
char *mod_vers;
nv_alloc_t mod_nva_sleep;
nv_alloc_t mod_nva_nosleep;
} fmd_module_t;
#define FMD_MOD_INIT 0x001
#define FMD_MOD_FINI 0x002
#define FMD_MOD_QUIT 0x004
#define FMD_MOD_FAIL 0x008
#define FMD_MOD_LOCK 0x010
#define FMD_MOD_BUSY 0x020
#define FMD_MOD_MDIRTY 0x040
#define FMD_MOD_CDIRTY 0x080
#define FMD_MOD_STSUB 0x100
#define FMD_MOD_STPUB 0x200
typedef struct fmd_modtimer {
fmd_module_t *mt_mod;
void *mt_arg;
id_t mt_id;
} fmd_modtimer_t;
typedef struct fmd_modtopo {
fmd_list_t mt_link;
fmd_topo_t *mt_topo;
} fmd_modtopo_t;
extern const fmd_modops_t fmd_bltin_ops;
extern const fmd_modops_t fmd_rtld_ops;
extern const fmd_modops_t fmd_proc_ops;
extern fmd_module_t *fmd_module_create(const char *, const fmd_modops_t *);
extern void fmd_module_unload(fmd_module_t *);
extern void fmd_module_destroy(fmd_module_t *);
extern void fmd_module_dispatch(fmd_module_t *, fmd_event_t *);
extern int fmd_module_transport(fmd_module_t *, fmd_xprt_t *, fmd_event_t *);
extern void fmd_module_timeout(fmd_modtimer_t *, id_t, hrtime_t);
extern void fmd_module_gc(fmd_module_t *);
extern void fmd_module_trygc(fmd_module_t *);
extern int fmd_module_contains(fmd_module_t *, fmd_event_t *);
extern void fmd_module_setdirty(fmd_module_t *);
extern void fmd_module_setcdirty(fmd_module_t *);
extern void fmd_module_clrdirty(fmd_module_t *);
extern void fmd_module_commit(fmd_module_t *);
extern void fmd_module_lock(fmd_module_t *);
extern void fmd_module_unlock(fmd_module_t *);
extern int fmd_module_trylock(fmd_module_t *);
extern int fmd_module_locked(fmd_module_t *);
extern void fmd_module_unregister(fmd_module_t *);
extern int fmd_module_enter(fmd_module_t *, void (*)(fmd_hdl_t *));
extern void fmd_module_exit(fmd_module_t *);
extern void fmd_module_abort(fmd_module_t *, int) __NORETURN;
extern void fmd_module_hold(fmd_module_t *);
extern void fmd_module_rele(fmd_module_t *);
extern int fmd_module_dc_opendict(fmd_module_t *, const char *);
extern int fmd_module_dc_key2code(fmd_module_t *,
char *const [], char *, size_t);
extern fmd_modhash_t *fmd_modhash_create(void);
extern void fmd_modhash_destroy(fmd_modhash_t *);
extern fmd_module_t *fmd_modhash_load(fmd_modhash_t *,
const char *, const fmd_modops_t *);
extern void fmd_modhash_loadall(fmd_modhash_t *,
const fmd_conf_path_t *, const fmd_modops_t *, const char *);
extern fmd_module_t *fmd_modhash_lookup(fmd_modhash_t *, const char *);
extern int fmd_modhash_unload(fmd_modhash_t *, const char *);
extern void fmd_modhash_apply(fmd_modhash_t *, void (*)(fmd_module_t *));
extern void fmd_modhash_tryapply(fmd_modhash_t *, void (*)(fmd_module_t *));
extern void fmd_modhash_dispatch(fmd_modhash_t *, fmd_event_t *);
extern void fmd_modstat_publish(fmd_module_t *);
extern int fmd_modstat_snapshot(fmd_module_t *, struct fmd_ustat_snap *);
extern struct topo_hdl *fmd_module_topo_hold(fmd_module_t *);
extern int fmd_module_topo_rele(fmd_module_t *, struct topo_hdl *);
extern nv_alloc_ops_t fmd_module_nva_ops_sleep;
extern nv_alloc_ops_t fmd_module_nva_ops_nosleep;
#ifdef __cplusplus
}
#endif
#endif