ovni/src/emu/chan.h

69 lines
1.5 KiB
C
Raw Normal View History

2023-01-12 19:16:52 +01:00
/* Copyright (c) 2021-2022 Barcelona Supercomputing Center (BSC)
2022-09-19 12:39:02 +02:00
* SPDX-License-Identifier: GPL-3.0-or-later */
2021-10-26 18:42:41 +02:00
2023-01-12 19:16:52 +01:00
#ifndef CHAN_H
#define CHAN_H
#include <stdint.h>
#include "value.h"
#define MAX_CHAN_STACK 512
#define MAX_CHAN_NAME 512
enum chan_type {
CHAN_SINGLE = 0,
CHAN_STACK = 1,
CHAN_MAXTYPE,
};
enum chan_prop {
CHAN_DIRTY_WRITE = 0,
CHAN_DUPLICATES,
2023-01-16 15:42:59 +01:00
CHAN_ROW,
CHAN_MAXPROP,
};
2023-01-27 18:51:18 +01:00
struct chan_spec {
enum chan_type type;
const char *suffix;
const char *desc;
};
2023-01-12 19:16:52 +01:00
struct chan_stack {
int n;
struct value values[MAX_CHAN_STACK];
};
union chan_data {
struct chan_stack stack;
struct value value;
};
struct chan;
typedef int (*chan_cb_t)(struct chan *chan, void *ptr);
struct chan {
char name[MAX_CHAN_NAME];
enum chan_type type;
union chan_data data;
int is_dirty;
int prop[CHAN_MAXPROP];
2023-01-12 19:16:52 +01:00
struct value last_value;
chan_cb_t dirty_cb;
void *dirty_arg;
};
2023-01-25 12:01:01 +01:00
void chan_init(struct chan *chan, enum chan_type type, const char *fmt, ...);
2023-01-16 15:42:59 +01:00
USE_RET int chan_set(struct chan *chan, struct value value);
USE_RET int chan_push(struct chan *chan, struct value value);
USE_RET int chan_pop(struct chan *chan, struct value expected);
USE_RET int chan_read(struct chan *chan, struct value *value);
USE_RET enum chan_type chan_get_type(struct chan *chan);
USE_RET int chan_flush(struct chan *chan);
void chan_prop_set(struct chan *chan, enum chan_prop prop, int value);
USE_RET int chan_prop_get(struct chan *chan, enum chan_prop prop);
void chan_set_dirty_cb(struct chan *chan, chan_cb_t func, void *arg);
2023-01-12 19:16:52 +01:00
#endif /* CHAN_H */