From 183634c8c4979bea36b6caac40ab7eef6286b46f Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Mon, 16 Jan 2023 16:05:52 +0100 Subject: [PATCH] Pass the bay in the prv_register() function --- src/emu/prv.c | 11 +++++------ src/emu/prv.h | 7 +++---- test/unit/prv.c | 8 ++++---- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/emu/prv.c b/src/emu/prv.c index 4925096..3ca269a 100644 --- a/src/emu/prv.c +++ b/src/emu/prv.c @@ -13,12 +13,11 @@ write_header(FILE *f, long long duration, int nrows) } int -prv_open_file(struct prv *prv, struct bay *bay, long nrows, FILE *file) +prv_open_file(struct prv *prv, long nrows, FILE *file) { memset(prv, 0, sizeof(struct prv)); prv->nrows = nrows; - prv->bay = bay; prv->file = file; /* Write fake header to allocate the space */ @@ -28,7 +27,7 @@ prv_open_file(struct prv *prv, struct bay *bay, long nrows, FILE *file) } int -prv_open(struct prv *prv, struct bay *bay, long nrows, const char *path) +prv_open(struct prv *prv, long nrows, const char *path) { FILE *f = fopen(path, "w"); @@ -38,7 +37,7 @@ prv_open(struct prv *prv, struct bay *bay, long nrows, const char *path) return -1; } - return prv_open_file(prv, bay, nrows, f); + return prv_open_file(prv, nrows, f); } void @@ -121,7 +120,7 @@ cb_prv(struct chan *chan, void *ptr) } int -prv_register(struct prv *prv, long row, long type, struct chan *chan) +prv_register(struct prv *prv, long row, long type, struct bay *bay, struct chan *chan) { struct prv_chan *rchan = find_prv_chan(prv, chan->name); if (rchan != NULL) { @@ -144,7 +143,7 @@ prv_register(struct prv *prv, long row, long type, struct chan *chan) rchan->last_value_set = 0; /* Add emit callback */ - if (bay_add_cb(prv->bay, BAY_CB_EMIT, chan, cb_prv, rchan) != 0) { + if (bay_add_cb(bay, BAY_CB_EMIT, chan, cb_prv, rchan) != 0) { err("prv_register: bay_add_cb failed\n"); return -1; } diff --git a/src/emu/prv.h b/src/emu/prv.h index fefbad5..360f6b2 100644 --- a/src/emu/prv.h +++ b/src/emu/prv.h @@ -23,15 +23,14 @@ struct prv_chan { struct prv { FILE *file; - struct bay *bay; int64_t time; long nrows; struct prv_chan *channels; }; -int prv_open(struct prv *prv, struct bay *bay, long nrows, const char *path); -int prv_open_file(struct prv *prv, struct bay *bay, long nrows, FILE *file); -int prv_register(struct prv *prv, long row, long type, struct chan *c); +int prv_open(struct prv *prv, long nrows, const char *path); +int prv_open_file(struct prv *prv, long nrows, FILE *file); +int prv_register(struct prv *prv, long row, long type, struct bay *bay, struct chan *c); int prv_advance(struct prv *prv, int64_t time); void prv_close(struct prv *prv); diff --git a/test/unit/prv.c b/test/unit/prv.c index f18d92a..03b281a 100644 --- a/test/unit/prv.c +++ b/test/unit/prv.c @@ -19,7 +19,7 @@ test_emit(const char *path) bay_init(&bay); struct prv prv; - prv_open(&prv, &bay, NROWS, path); + prv_open(&prv, NROWS, path); for (int i = 0; i < NROWS; i++) { char buf[MAX_CHAN_NAME]; @@ -31,7 +31,7 @@ test_emit(const char *path) } for (int i = 0; i < NROWS; i++) - if (prv_register(&prv, i, type, &chan[i]) != 0) + if (prv_register(&prv, i, type, &bay, &chan[i]) != 0) die("prv_register failed\n"); for (int i = 0; i < NROWS; i++) @@ -69,7 +69,7 @@ test_duplicate(const char *path) bay_init(&bay); struct prv prv; - prv_open(&prv, &bay, NROWS, path); + prv_open(&prv, NROWS, path); struct chan chan; chan_init(&chan, CHAN_SINGLE, "testchan"); @@ -80,7 +80,7 @@ test_duplicate(const char *path) if (bay_register(&bay, &chan) != 0) die("bay_register failed\n"); - if (prv_register(&prv, 0, type, &chan) != 0) + if (prv_register(&prv, 0, type, &bay, &chan) != 0) die("prv_register failed\n"); if (chan_set(&chan, value_int64(1000)) != 0)