2010-01-05 17:14:09 +00:00
|
|
|
/*
|
2011-03-18 18:38:08 +00:00
|
|
|
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
2012-01-21 14:29:42 +00:00
|
|
|
2011,2012 Giovanni Di Sirio.
|
2010-01-05 17:14:09 +00:00
|
|
|
|
|
|
|
This file is part of ChibiOS/RT.
|
|
|
|
|
|
|
|
ChibiOS/RT is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
ChibiOS/RT is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-02-27 08:54:22 +00:00
|
|
|
* @file chstreams.h
|
2010-02-06 12:31:09 +00:00
|
|
|
* @brief Data streams.
|
|
|
|
* @details This header defines abstract interfaces useful to access generic
|
|
|
|
* data streams in a standardized way.
|
|
|
|
*
|
2010-01-05 17:14:09 +00:00
|
|
|
* @addtogroup data_streams
|
2010-03-16 19:36:21 +00:00
|
|
|
* @details This module define an abstract interface for generic data streams.
|
|
|
|
* Note that no code is present, streams are just abstract interfaces
|
|
|
|
* like structures, you should look at the systems as to a set of
|
|
|
|
* abstract C++ classes (even if written in C). This system has the
|
|
|
|
* advantage to make the access to streams independent from the
|
|
|
|
* implementation logic.<br>
|
|
|
|
* The stream interface can be used as base class for high level
|
|
|
|
* object types such as files, sockets, serial ports, pipes etc.
|
2010-01-05 17:14:09 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2010-02-27 08:54:22 +00:00
|
|
|
#ifndef _CHSTREAMS_H_
|
|
|
|
#define _CHSTREAMS_H_
|
2010-01-05 17:14:09 +00:00
|
|
|
|
|
|
|
/**
|
2010-02-06 12:31:09 +00:00
|
|
|
* @brief BaseSequentialStream specific methods.
|
2010-01-05 17:14:09 +00:00
|
|
|
*/
|
2010-10-18 07:18:20 +00:00
|
|
|
#define _base_sequential_stream_methods \
|
2010-01-23 09:51:18 +00:00
|
|
|
/* Stream write buffer method.*/ \
|
2010-01-22 14:51:54 +00:00
|
|
|
size_t (*write)(void *instance, const uint8_t *bp, size_t n); \
|
2010-01-23 09:51:18 +00:00
|
|
|
/* Stream read buffer method.*/ \
|
2010-01-25 18:50:35 +00:00
|
|
|
size_t (*read)(void *instance, uint8_t *bp, size_t n);
|
2010-01-05 17:14:09 +00:00
|
|
|
|
|
|
|
/**
|
2010-02-06 12:31:09 +00:00
|
|
|
* @brief @p BaseSequentialStream specific data.
|
|
|
|
* @note It is empty because @p BaseSequentialStream is only an interface
|
|
|
|
* without implementation.
|
2010-01-05 17:14:09 +00:00
|
|
|
*/
|
2010-07-19 10:16:23 +00:00
|
|
|
#define _base_sequential_stream_data
|
2010-01-05 17:14:09 +00:00
|
|
|
|
|
|
|
/**
|
2010-02-06 12:31:09 +00:00
|
|
|
* @brief @p BaseSequentialStream virtual methods table.
|
2010-01-05 17:14:09 +00:00
|
|
|
*/
|
|
|
|
struct BaseSequentialStreamVMT {
|
2010-07-19 10:16:23 +00:00
|
|
|
_base_sequential_stream_methods
|
2010-01-05 17:14:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2010-02-06 12:31:09 +00:00
|
|
|
* @brief Base stream class.
|
2010-01-05 17:14:09 +00:00
|
|
|
* @details This class represents a generic blocking unbuffered sequential
|
|
|
|
* data stream.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
2010-02-06 12:31:09 +00:00
|
|
|
/** @brief Virtual Methods Table.*/
|
2010-01-05 17:14:09 +00:00
|
|
|
const struct BaseSequentialStreamVMT *vmt;
|
2010-07-19 10:16:23 +00:00
|
|
|
_base_sequential_stream_data
|
2010-01-05 17:14:09 +00:00
|
|
|
} BaseSequentialStream;
|
|
|
|
|
2011-08-23 10:09:08 +00:00
|
|
|
/**
|
|
|
|
* @name Macro Functions (BaseSequentialStream)
|
|
|
|
* @{
|
|
|
|
*/
|
2010-01-05 17:14:09 +00:00
|
|
|
/**
|
2010-02-06 12:31:09 +00:00
|
|
|
* @brief Sequential Stream write.
|
2010-01-05 17:14:09 +00:00
|
|
|
* @details The function writes data from a buffer to a stream.
|
|
|
|
*
|
2010-02-06 12:31:09 +00:00
|
|
|
* @param[in] ip pointer to a @p BaseSequentialStream or derived class
|
|
|
|
* @param[in] bp pointer to the data buffer
|
|
|
|
* @param[in] n the maximum amount of data to be transferred
|
|
|
|
* @return The number of bytes transferred. The return value can
|
|
|
|
* be less than the specified number of bytes if the
|
|
|
|
* stream reaches a physical end of file and cannot be
|
|
|
|
* extended.
|
2010-09-21 10:22:06 +00:00
|
|
|
*
|
|
|
|
* @api
|
2010-01-05 17:14:09 +00:00
|
|
|
*/
|
2010-01-22 14:51:54 +00:00
|
|
|
#define chSequentialStreamWrite(ip, bp, n) ((ip)->vmt->write(ip, bp, n))
|
2010-01-05 17:14:09 +00:00
|
|
|
|
|
|
|
/**
|
2010-02-06 12:31:09 +00:00
|
|
|
* @brief Sequential Stream read.
|
2010-01-05 17:14:09 +00:00
|
|
|
* @details The function reads data from a stream into a buffer.
|
|
|
|
*
|
2010-02-06 12:31:09 +00:00
|
|
|
* @param[in] ip pointer to a @p BaseSequentialStream or derived class
|
|
|
|
* @param[out] bp pointer to the data buffer
|
|
|
|
* @param[in] n the maximum amount of data to be transferred
|
|
|
|
* @return The number of bytes transferred. The return value can
|
|
|
|
* be less than the specified number of bytes if the
|
|
|
|
* stream reaches the end of the available data.
|
2010-09-21 10:22:06 +00:00
|
|
|
*
|
|
|
|
* @api
|
2010-01-05 17:14:09 +00:00
|
|
|
*/
|
2010-01-22 14:51:54 +00:00
|
|
|
#define chSequentialStreamRead(ip, bp, n) ((ip)->vmt->read(ip, bp, n))
|
2011-08-23 10:09:08 +00:00
|
|
|
/** @} */
|
2010-01-05 17:14:09 +00:00
|
|
|
|
2010-02-27 08:54:22 +00:00
|
|
|
#endif /* _CHSTREAMS_H_ */
|
2010-01-05 17:14:09 +00:00
|
|
|
|
|
|
|
/** @} */
|