Pass the bay in the prv_register() function

This commit is contained in:
Rodrigo Arias 2023-01-16 16:05:52 +01:00 committed by Rodrigo Arias Mallo
parent b3b1164fed
commit 183634c8c4
3 changed files with 12 additions and 14 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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)