#include <stdbool.h>
#include <stdlib.h>

#include "console-server.h"

struct rb_test_ctx {
	struct ringbuffer_consumer *rbc;
	bool ignore_poll;
	bool force_only;
	int count;
	uint8_t *data;
	size_t len;
};

void ringbuffer_test_context_init(struct rb_test_ctx *ctx)
{
	ctx->count = 0;
	ctx->data = NULL;
	ctx->len = 0;
	ctx->ignore_poll = false;
	ctx->force_only = false;
}

void ringbuffer_test_context_fini(struct rb_test_ctx *ctx)
{
	free(ctx->data);
}

enum ringbuffer_poll_ret ringbuffer_poll_nop(void *data __attribute__((unused)),
					     size_t force_len
					     __attribute__((unused)))
{
	return RINGBUFFER_POLL_OK;
}

enum ringbuffer_poll_ret ringbuffer_poll_append_all(void *data,
						    size_t force_len)
{
	struct rb_test_ctx *ctx = data;
	size_t len;
	size_t total_len;
	uint8_t *buf;

	if (ctx->ignore_poll) {
		return RINGBUFFER_POLL_OK;
	}

	if (ctx->force_only && !force_len) {
		return RINGBUFFER_POLL_OK;
	}

	ctx->count++;

	total_len = 0;
	for (;;) {
		len = ringbuffer_dequeue_peek(ctx->rbc, total_len, &buf);
		if (!len) {
			break;
		}

		if (ctx->force_only && total_len + len > force_len) {
			len = force_len - total_len;
		}

		ctx->data = realloc(ctx->data, ctx->len + len);
		memcpy(ctx->data + ctx->len, buf, len);
		ctx->len += len;
		total_len += len;

		if (ctx->force_only && total_len >= force_len) {
			break;
		}
	}
	ringbuffer_dequeue_commit(ctx->rbc, total_len);

	return RINGBUFFER_POLL_OK;
}

void ringbuffer_dump(struct ringbuffer *rb)
{
	struct ringbuffer_consumer *rbc;
	size_t i;
	int j;

	printf("---- ringbuffer (%d consumer%s)\n", rb->n_consumers,
	       rb->n_consumers == 1 ? "" : "s");

	for (i = 0; i < rb->size; i++) {
		bool has_consumer = false;
		const char *prefix = "";

		if (rb->tail == i) {
			prefix = "tail=>";
		}

		printf("%6s %02x", prefix, rb->buf[i]);
		for (j = 0; j < rb->n_consumers; j++) {
			rbc = rb->consumers[j];
			if (rbc->pos != i) {
				continue;
			}
			if (!has_consumer) {
				printf(" <=");
			}
			printf("c[%d],len=%zd ", j, ringbuffer_len(rbc));
			has_consumer = true;
		}
		printf("\n");
	}
}
