feat: implement log message callback

This commit is contained in:
DSPOM 2022-05-10 10:38:25 +02:00
parent ad7661849c
commit 80ce6d25bb
6 changed files with 44 additions and 8 deletions

View File

@ -120,8 +120,10 @@ ngspice_SOURCES = \
ngspice_CPPFLAGS = $(AM_CPPFLAGS) -DSIMULATOR
if WINGUI
ngspice_LDFLAGS = -municode $(AM_LDFLAGS)
ngspice_LDFLAGS = -municode $(AM_LDFLAGS) -ldl
ngspice_SOURCES += winmain.c hist_info.c
else
ngspice_LDFLAGS =
endif
ngspice_LDADD = \
@ -183,6 +185,7 @@ endif
if OSDI_WANTED
ngspice_LDADD += osdi/libosdi.la
ngspice_LDFLAGS += -Wl,--dynamic-list=$(top_srcdir)/src/osdi/exported.txt
endif
ngspice_LDADD += \

View File

@ -13,6 +13,7 @@ libosdi_la_SOURCES = \
osdiregistry.c \
osdisetup.c \
osdiitf.h
exported.txt

View File

@ -86,11 +86,11 @@ extern SPICEdev *osdi_create_spicedev(const OsdiRegistryEntry *entry) {
// allocate and fill instance params (and opvars)
int *num_instance_para_names = TMALLOC(int, 1);
for (uint32_t i = 0; i < descr->num_instance_params; i++) {
*num_instance_para_names += (int) (1 + descr->param_opvar[i].num_alias);
*num_instance_para_names += (int)(1 + descr->param_opvar[i].num_alias);
}
for (uint32_t i = descr->num_params;
i < descr->num_opvars + descr->num_params; i++) {
*num_instance_para_names += (int) (1 + descr->param_opvar[i].num_alias);
*num_instance_para_names += (int)(1 + descr->param_opvar[i].num_alias);
}
if (entry->dt != UINT32_MAX) {
*num_instance_para_names += 1;
@ -121,7 +121,7 @@ extern SPICEdev *osdi_create_spicedev(const OsdiRegistryEntry *entry) {
// allocate and fill model params
int *num_model_para_names = TMALLOC(int, 1);
for (uint32_t i = descr->num_instance_params; i < descr->num_params; i++) {
*num_model_para_names += (int) (1 + descr->param_opvar[i].num_alias);
*num_model_para_names += (int)(1 + descr->param_opvar[i].num_alias);
}
IFparm *model_para_names = TMALLOC(IFparm, *num_model_para_names);
dst = model_para_names;
@ -143,7 +143,7 @@ extern SPICEdev *osdi_create_spicedev(const OsdiRegistryEntry *entry) {
.numModelParms = num_model_para_names,
.modelParms = model_para_names,
.flags = DEV_DEFAULT,
.registry_entry = (void*) entry,
.registry_entry = (void *)entry,
};
size_t inst_off = entry->inst_offset;
@ -170,3 +170,35 @@ extern SPICEdev *osdi_create_spicedev(const OsdiRegistryEntry *entry) {
return OSDIinfo;
}
extern FILE *osdi_init_log_message(void *handle_, uint32_t lvl) {
OsdiNgspiceHandle *handle = handle_;
switch (lvl) {
case LOG_LVL_DEBUG:
fprintf(stdout, "OSDI(debug) %s: ", handle->name);
break;
case LOG_LVL_INFO:
fprintf(stdout, "OSDI(info) %s: ", handle->name);
break;
case LOG_LVL_WARN:
fprintf(stdout, "OSDI(warn) %s: ", handle->name);
break;
case LOG_LVL_ERR:
fprintf(stderr, "OSDI(err) %s: ", handle->name);
return stderr;
case LOG_LVL_FATAL:
fprintf(stderr, "OSDI(fatal) %s: ", handle->name);
return stderr;
default:
fprintf(stdout, "OSDI(unkown) %s", handle->name);
break;
}
return stdout;
}
extern void osdi_finish_log_message(void *handle, FILE *stream, uint32_t lvl) {
NG_IGNORE(handle);
NG_IGNORE(stream);
NG_IGNORE(lvl);
}

View File

@ -77,7 +77,7 @@ extern int OSDIload(GENmodel *inModel, CKTcircuit *ckt) {
/* hpyothetically this could run in parallel we do not write any shared
data here*/
handle = (OsdiNgspiceHandle){.kind = 2, .name = gen_inst->GENname};
handle = (OsdiNgspiceHandle){.kind = 3, .name = gen_inst->GENname};
/* TODO initial conditions? */
uint32_t ret_flags = descr->eval(&handle, inst, model, flags,
ckt->CKTrhsOld, &sim_params_);

View File

@ -18,7 +18,7 @@
#if (!defined HAS_WINGUI) && (!defined __MINGW32__) && (!defined _MSC_VER)
#include <dlfcn.h> /* to load libraries*/
#define OPENLIB(path) dlopen(path, RTLD_LAZY | RTLD_LOCAL)
#define OPENLIB(path) dlopen(path, RTLD_NOW | RTLD_LOCAL)
#define GET_SYM(lib, sym) dlsym(lib, sym)
#define FREE_DLERR_MSG(msg)

View File

@ -287,7 +287,7 @@ extern int OSDItemp(GENmodel *inModel, CKTcircuit *ckt) {
gen_model = gen_model->GENnextModel) {
void *model = osdi_model_data(gen_model);
handle = (OsdiNgspiceHandle){.kind = 1, .name = gen_model->GENmodName};
handle = (OsdiNgspiceHandle){.kind = 4, .name = gen_model->GENmodName};
init_info = descr->setup_model((void *)&handle, model);
res = handle_init_info(init_info, descr);
if (res) {