Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Stream.h Source File

Stream.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2019 ARM Limited
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 #ifndef MBED_STREAM_H
00018 #define MBED_STREAM_H
00019 
00020 #include "platform/platform.h"
00021 #include "platform/FileLike.h"
00022 #include "platform/NonCopyable.h"
00023 #include "platform/mbed_toolchain.h"
00024 #include <cstdio>
00025 #include <cstdarg>
00026 
00027 namespace mbed {
00028 /** \addtogroup platform-public-api */
00029 /** @{*/
00030 
00031 /**
00032  * \defgroup platform_Stream Stream class
00033  * @{
00034  */
00035 
00036 extern void mbed_set_unbuffered_stream(std::FILE *_file);
00037 
00038 /** File stream
00039  *
00040  * @note Synchronization level: Set by subclass
00041  */
00042 class Stream : public FileLike, private NonCopyable<Stream> {
00043 
00044 public:
00045     Stream(const char *name = NULL);
00046     virtual ~Stream();
00047 
00048 #if !MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
00049     int putc(int c);
00050     int puts(const char *s);
00051     int getc();
00052     char *gets(char *s, int size);
00053     int printf(const char *format, ...) MBED_PRINTF_METHOD(1, 2);
00054     int scanf(const char *format, ...) MBED_SCANF_METHOD(1, 2);
00055     int vprintf(const char *format, std::va_list args) MBED_PRINTF_METHOD(1, 0);
00056     int vscanf(const char *format, std::va_list args) MBED_SCANF_METHOD(1, 0);
00057 
00058     operator std::FILE *()
00059     {
00060         return _file;
00061     }
00062 
00063 #endif // !MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
00064     virtual int close();
00065     virtual ssize_t write(const void *buffer, size_t length);
00066     virtual ssize_t read(void *buffer, size_t length);
00067     virtual off_t seek(off_t offset, int whence);
00068     virtual off_t tell();
00069     virtual void rewind();
00070     virtual int isatty();
00071     virtual int sync();
00072     virtual off_t size();
00073 
00074 protected:
00075     virtual int _putc(int c) = 0;
00076     virtual int _getc() = 0;
00077 
00078 #if !MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
00079     std::FILE *_file;
00080 #endif // !MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
00081 
00082     /** Acquire exclusive access to this object.
00083      */
00084     virtual void lock()
00085     {
00086         // Stub
00087     }
00088 
00089     /** Release exclusive access to this object.
00090      */
00091     virtual void unlock()
00092     {
00093         // Stub
00094     }
00095 };
00096 /**@}*/
00097 
00098 /**@}*/
00099 } // namespace mbed
00100 
00101 #endif
00102