2013-02-18 15:32:11 +00:00
|
|
|
/* mbed Microcontroller Library
|
2019-06-27 08:49:22 +00:00
|
|
|
* Copyright (c) 2006-2019 ARM Limited
|
2018-11-09 11:31:20 +00:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2013-02-18 15:32:11 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
#ifndef MBED_STREAM_H
|
|
|
|
#define MBED_STREAM_H
|
|
|
|
|
2016-10-01 07:11:36 +00:00
|
|
|
#include "platform/platform.h"
|
2017-03-07 16:40:37 +00:00
|
|
|
#include "platform/FileLike.h"
|
2017-06-20 11:47:27 +00:00
|
|
|
#include "platform/NonCopyable.h"
|
2019-06-27 08:49:22 +00:00
|
|
|
#include "platform/mbed_toolchain.h"
|
2017-02-16 00:36:00 +00:00
|
|
|
#include <cstdio>
|
2015-11-24 15:10:07 +00:00
|
|
|
#include <cstdarg>
|
2013-02-18 15:32:11 +00:00
|
|
|
|
|
|
|
namespace mbed {
|
2019-06-27 08:49:22 +00:00
|
|
|
/** \addtogroup platform-public-api */
|
2016-10-04 20:02:44 +00:00
|
|
|
/** @{*/
|
2019-09-06 21:58:57 +00:00
|
|
|
|
2017-10-24 15:05:45 +00:00
|
|
|
/**
|
|
|
|
* \defgroup platform_Stream Stream class
|
|
|
|
* @{
|
|
|
|
*/
|
2013-02-18 15:32:11 +00:00
|
|
|
|
2017-02-16 00:36:00 +00:00
|
|
|
extern void mbed_set_unbuffered_stream(std::FILE *_file);
|
2014-12-09 13:30:34 +00:00
|
|
|
|
2016-06-08 12:52:14 +00:00
|
|
|
/** File stream
|
|
|
|
*
|
2017-04-25 19:37:08 +00:00
|
|
|
* @note Synchronization level: Set by subclass
|
2016-06-08 12:52:14 +00:00
|
|
|
*/
|
2017-06-20 11:47:27 +00:00
|
|
|
class Stream : public FileLike, private NonCopyable<Stream> {
|
2013-02-18 15:32:11 +00:00
|
|
|
|
|
|
|
public:
|
2018-06-27 14:09:15 +00:00
|
|
|
Stream(const char *name = NULL);
|
2013-02-18 15:32:11 +00:00
|
|
|
virtual ~Stream();
|
|
|
|
|
2019-10-18 12:46:09 +00:00
|
|
|
#if !MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
|
2013-02-18 15:32:11 +00:00
|
|
|
int putc(int c);
|
|
|
|
int puts(const char *s);
|
|
|
|
int getc();
|
|
|
|
char *gets(char *s, int size);
|
2018-09-12 09:02:22 +00:00
|
|
|
int printf(const char *format, ...) MBED_PRINTF_METHOD(1, 2);
|
|
|
|
int scanf(const char *format, ...) MBED_SCANF_METHOD(1, 2);
|
|
|
|
int vprintf(const char *format, std::va_list args) MBED_PRINTF_METHOD(1, 0);
|
|
|
|
int vscanf(const char *format, std::va_list args) MBED_SCANF_METHOD(1, 0);
|
2013-02-18 15:32:11 +00:00
|
|
|
|
2018-06-27 14:09:15 +00:00
|
|
|
operator std::FILE *()
|
|
|
|
{
|
|
|
|
return _file;
|
|
|
|
}
|
2013-02-18 15:32:11 +00:00
|
|
|
|
2019-10-18 12:46:09 +00:00
|
|
|
#endif // !MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
|
2013-02-18 15:32:11 +00:00
|
|
|
virtual int close();
|
2018-06-27 14:09:15 +00:00
|
|
|
virtual ssize_t write(const void *buffer, size_t length);
|
|
|
|
virtual ssize_t read(void *buffer, size_t length);
|
2017-02-13 19:19:57 +00:00
|
|
|
virtual off_t seek(off_t offset, int whence);
|
|
|
|
virtual off_t tell();
|
|
|
|
virtual void rewind();
|
2013-02-18 15:32:11 +00:00
|
|
|
virtual int isatty();
|
2017-02-13 19:19:57 +00:00
|
|
|
virtual int sync();
|
2017-03-28 13:23:00 +00:00
|
|
|
virtual off_t size();
|
2013-02-18 15:32:11 +00:00
|
|
|
|
2019-10-18 12:46:09 +00:00
|
|
|
protected:
|
2013-02-18 15:32:11 +00:00
|
|
|
virtual int _putc(int c) = 0;
|
|
|
|
virtual int _getc() = 0;
|
|
|
|
|
2019-10-18 12:46:09 +00:00
|
|
|
#if !MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
|
2013-02-18 15:32:11 +00:00
|
|
|
std::FILE *_file;
|
2019-10-18 12:46:09 +00:00
|
|
|
#endif // !MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
|
2014-05-26 17:04:46 +00:00
|
|
|
|
2017-03-01 22:23:03 +00:00
|
|
|
/** Acquire exclusive access to this object.
|
|
|
|
*/
|
2018-06-27 14:09:15 +00:00
|
|
|
virtual void lock()
|
|
|
|
{
|
2017-03-01 22:23:03 +00:00
|
|
|
// Stub
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Release exclusive access to this object.
|
|
|
|
*/
|
2018-06-27 14:09:15 +00:00
|
|
|
virtual void unlock()
|
|
|
|
{
|
2017-03-01 22:23:03 +00:00
|
|
|
// Stub
|
|
|
|
}
|
2013-02-18 15:32:11 +00:00
|
|
|
};
|
2017-10-24 15:05:45 +00:00
|
|
|
/**@}*/
|
2013-02-18 15:32:11 +00:00
|
|
|
|
2017-10-24 15:05:45 +00:00
|
|
|
/**@}*/
|
2013-02-18 15:32:11 +00:00
|
|
|
} // namespace mbed
|
|
|
|
|
|
|
|
#endif
|
2016-10-04 20:02:44 +00:00
|
|
|
|