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,
|
2014-07-26 09:06:28 +00:00
|
|
|
2011,2012,2013,2014 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.
|
2012-05-07 18:43:52 +00:00
|
|
|
* Note that no code is present, just abstract interfaces-like
|
|
|
|
* structures, you should look at the system as to a set of
|
|
|
|
* abstract C++ classes (even if written in C). This system
|
|
|
|
* has then advantage to make the access to data streams
|
|
|
|
* independent from the implementation logic.<br>
|
2010-03-16 19:36:21 +00:00
|
|
|
* 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.*/ \
|
2012-06-18 16:22:34 +00:00
|
|
|
size_t (*read)(void *instance, uint8_t *bp, size_t n); \
|
|
|
|
/* Channel put method, blocking.*/ \
|
|
|
|
msg_t (*put)(void *instance, uint8_t b); \
|
|
|
|
/* Channel get method, blocking.*/ \
|
|
|
|
msg_t (*get)(void *instance); \
|
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
|
2012-06-18 16:22:34 +00:00
|
|
|
* be less than the specified number of bytes if an
|
|
|
|
* end-of-file condition has been met.
|
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
|
2012-06-18 16:22:34 +00:00
|
|
|
* be less than the specified number of bytes if an
|
|
|
|
* end-of-file condition has been met.
|
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))
|
2012-06-18 16:22:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sequential Stream blocking byte write.
|
|
|
|
* @details This function writes a byte value to a channel. If the channel
|
|
|
|
* is not ready to accept data then the calling thread is suspended.
|
|
|
|
*
|
2014-11-27 13:48:59 +00:00
|
|
|
* @param[in] ip pointer to a @p BaseSequentialStream or derived class
|
2012-06-18 16:22:34 +00:00
|
|
|
* @param[in] b the byte value to be written to the channel
|
|
|
|
*
|
|
|
|
* @return The operation status.
|
|
|
|
* @retval Q_OK if the operation succeeded.
|
|
|
|
* @retval Q_RESET if an end-of-file condition has been met.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
#define chSequentialStreamPut(ip, b) ((ip)->vmt->put(ip, b))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sequential Stream blocking byte read.
|
|
|
|
* @details This function reads a byte value from a channel. If the data
|
|
|
|
* is not available then the calling thread is suspended.
|
|
|
|
*
|
2014-11-27 13:48:59 +00:00
|
|
|
* @param[in] ip pointer to a @p BaseSequentialStream or derived class
|
2012-06-18 16:22:34 +00:00
|
|
|
*
|
|
|
|
* @return A byte value from the queue.
|
|
|
|
* @retval Q_RESET if an end-of-file condition has been met.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
#define chSequentialStreamGet(ip) ((ip)->vmt->get(ip))
|
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
|
|
|
|
|
|
|
/** @} */
|