Files
OpenCellular/common/stream_adaptor.c
Anton Staaf 855646e36b Producer/Consumer: Refactor to use Queue policies
Previously the Producer and Consumer interfaces tracked the
Consumer and Producer respectively at the other end of the
queue that they interacted with.  This was done to avoid
modifying the queue implementation, but resulted in a rougher
interface that required additional initialization steps and
prevented alternative configurations; many producers and one
consumer for example.

This commit uses the new queue policies to track this
information.  The new direct policy behaves as the old producer
and consumers did.  Now the producers and consumers are just
named references to the queue that they work on and a convenient
location for a notification callback when the queue is updated in
a way that is relevent to the producer or consumer.

All users of Producer and Consumer have been updated including the
stream adaptors which are in use by the echo test code and the
mcdp28x0 driver.  Use of the stream adaptors has also been
simplified.

Signed-off-by: Anton Staaf <robotboy@chromium.org>

BRANCH=None
BUG=None
TEST=make buildall -j
     Manual testing of Ryu (P5) and discovery board echo task

Change-Id: I704be6378a31b4e20f5063295eff9943e4900409
Reviewed-on: https://chromium-review.googlesource.com/271792
Reviewed-by: Anton Staaf <robotboy@chromium.org>
Commit-Queue: Anton Staaf <robotboy@chromium.org>
Trybot-Ready: Anton Staaf <robotboy@chromium.org>
Tested-by: Anton Staaf <robotboy@chromium.org>
2015-05-26 19:36:21 +00:00

72 lines
1.8 KiB
C

/* Copyright 2015 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* Stream adaptor implementation.
*/
#include "producer.h"
#include "consumer.h"
#include "stream_adaptor.h"
#include "util.h"
static size_t in_stream_from_queue_read(struct in_stream const *stream,
uint8_t *buffer,
size_t count)
{
struct in_stream_from_queue const *adaptor =
DOWNCAST(stream, struct in_stream_from_queue, in);
return queue_remove_memcpy(adaptor->consumer.queue,
buffer,
count,
memcpy);
}
static void in_stream_from_queue_written(struct consumer const *consumer,
size_t count)
{
struct in_stream_from_queue const *adaptor =
DOWNCAST(consumer, struct in_stream_from_queue, consumer);
in_stream_ready(&adaptor->in);
}
struct in_stream_ops const in_stream_from_queue_in_stream_ops = {
.read = in_stream_from_queue_read,
};
struct consumer_ops const in_stream_from_queue_consumer_ops = {
.written = in_stream_from_queue_written,
};
static size_t out_stream_from_queue_write(struct out_stream const *stream,
uint8_t const *buffer,
size_t count)
{
struct out_stream_from_queue const *adaptor =
DOWNCAST(stream, struct out_stream_from_queue, out);
return queue_add_memcpy(adaptor->producer.queue,
buffer,
count,
memcpy);
}
static void out_stream_from_queue_read(struct producer const *producer,
size_t count)
{
struct out_stream_from_queue const *adaptor =
DOWNCAST(producer, struct out_stream_from_queue, producer);
out_stream_ready(&adaptor->out);
}
struct out_stream_ops const out_stream_from_queue_out_stream_ops = {
.write = out_stream_from_queue_write,
};
struct producer_ops const out_stream_from_queue_producer_ops = {
.read = out_stream_from_queue_read,
};