Marco Zecchini
/
Example_RTOS
Rtos API example
mbed-os/platform/Stream.h@0:9fca2b23d0ba, 2019-02-23 (annotated)
- Committer:
- marcozecchini
- Date:
- Sat Feb 23 12:13:36 2019 +0000
- Revision:
- 0:9fca2b23d0ba
final commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
marcozecchini | 0:9fca2b23d0ba | 1 | /* mbed Microcontroller Library |
marcozecchini | 0:9fca2b23d0ba | 2 | * Copyright (c) 2006-2013 ARM Limited |
marcozecchini | 0:9fca2b23d0ba | 3 | * |
marcozecchini | 0:9fca2b23d0ba | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
marcozecchini | 0:9fca2b23d0ba | 5 | * you may not use this file except in compliance with the License. |
marcozecchini | 0:9fca2b23d0ba | 6 | * You may obtain a copy of the License at |
marcozecchini | 0:9fca2b23d0ba | 7 | * |
marcozecchini | 0:9fca2b23d0ba | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
marcozecchini | 0:9fca2b23d0ba | 9 | * |
marcozecchini | 0:9fca2b23d0ba | 10 | * Unless required by applicable law or agreed to in writing, software |
marcozecchini | 0:9fca2b23d0ba | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
marcozecchini | 0:9fca2b23d0ba | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
marcozecchini | 0:9fca2b23d0ba | 13 | * See the License for the specific language governing permissions and |
marcozecchini | 0:9fca2b23d0ba | 14 | * limitations under the License. |
marcozecchini | 0:9fca2b23d0ba | 15 | */ |
marcozecchini | 0:9fca2b23d0ba | 16 | #ifndef MBED_STREAM_H |
marcozecchini | 0:9fca2b23d0ba | 17 | #define MBED_STREAM_H |
marcozecchini | 0:9fca2b23d0ba | 18 | |
marcozecchini | 0:9fca2b23d0ba | 19 | #include "platform/platform.h" |
marcozecchini | 0:9fca2b23d0ba | 20 | #include "platform/FileLike.h" |
marcozecchini | 0:9fca2b23d0ba | 21 | #include "platform/FileHandle.h" |
marcozecchini | 0:9fca2b23d0ba | 22 | #include "platform/NonCopyable.h" |
marcozecchini | 0:9fca2b23d0ba | 23 | #include <cstdio> |
marcozecchini | 0:9fca2b23d0ba | 24 | #include <cstdarg> |
marcozecchini | 0:9fca2b23d0ba | 25 | |
marcozecchini | 0:9fca2b23d0ba | 26 | namespace mbed { |
marcozecchini | 0:9fca2b23d0ba | 27 | /** \addtogroup platform */ |
marcozecchini | 0:9fca2b23d0ba | 28 | /** @{*/ |
marcozecchini | 0:9fca2b23d0ba | 29 | /** |
marcozecchini | 0:9fca2b23d0ba | 30 | * \defgroup platform_Stream Stream class |
marcozecchini | 0:9fca2b23d0ba | 31 | * @{ |
marcozecchini | 0:9fca2b23d0ba | 32 | */ |
marcozecchini | 0:9fca2b23d0ba | 33 | |
marcozecchini | 0:9fca2b23d0ba | 34 | extern void mbed_set_unbuffered_stream(std::FILE *_file); |
marcozecchini | 0:9fca2b23d0ba | 35 | extern int mbed_getc(std::FILE *_file); |
marcozecchini | 0:9fca2b23d0ba | 36 | extern char* mbed_gets(char *s, int size, std::FILE *_file); |
marcozecchini | 0:9fca2b23d0ba | 37 | |
marcozecchini | 0:9fca2b23d0ba | 38 | /** File stream |
marcozecchini | 0:9fca2b23d0ba | 39 | * |
marcozecchini | 0:9fca2b23d0ba | 40 | * @note Synchronization level: Set by subclass |
marcozecchini | 0:9fca2b23d0ba | 41 | */ |
marcozecchini | 0:9fca2b23d0ba | 42 | class Stream : public FileLike, private NonCopyable<Stream> { |
marcozecchini | 0:9fca2b23d0ba | 43 | |
marcozecchini | 0:9fca2b23d0ba | 44 | public: |
marcozecchini | 0:9fca2b23d0ba | 45 | Stream(const char *name=NULL); |
marcozecchini | 0:9fca2b23d0ba | 46 | virtual ~Stream(); |
marcozecchini | 0:9fca2b23d0ba | 47 | |
marcozecchini | 0:9fca2b23d0ba | 48 | int putc(int c); |
marcozecchini | 0:9fca2b23d0ba | 49 | int puts(const char *s); |
marcozecchini | 0:9fca2b23d0ba | 50 | int getc(); |
marcozecchini | 0:9fca2b23d0ba | 51 | char *gets(char *s, int size); |
marcozecchini | 0:9fca2b23d0ba | 52 | int printf(const char* format, ...); |
marcozecchini | 0:9fca2b23d0ba | 53 | int scanf(const char* format, ...); |
marcozecchini | 0:9fca2b23d0ba | 54 | int vprintf(const char* format, std::va_list args); |
marcozecchini | 0:9fca2b23d0ba | 55 | int vscanf(const char* format, std::va_list args); |
marcozecchini | 0:9fca2b23d0ba | 56 | |
marcozecchini | 0:9fca2b23d0ba | 57 | operator std::FILE*() {return _file;} |
marcozecchini | 0:9fca2b23d0ba | 58 | |
marcozecchini | 0:9fca2b23d0ba | 59 | protected: |
marcozecchini | 0:9fca2b23d0ba | 60 | virtual int close(); |
marcozecchini | 0:9fca2b23d0ba | 61 | virtual ssize_t write(const void* buffer, size_t length); |
marcozecchini | 0:9fca2b23d0ba | 62 | virtual ssize_t read(void* buffer, size_t length); |
marcozecchini | 0:9fca2b23d0ba | 63 | virtual off_t seek(off_t offset, int whence); |
marcozecchini | 0:9fca2b23d0ba | 64 | virtual off_t tell(); |
marcozecchini | 0:9fca2b23d0ba | 65 | virtual void rewind(); |
marcozecchini | 0:9fca2b23d0ba | 66 | virtual int isatty(); |
marcozecchini | 0:9fca2b23d0ba | 67 | virtual int sync(); |
marcozecchini | 0:9fca2b23d0ba | 68 | virtual off_t size(); |
marcozecchini | 0:9fca2b23d0ba | 69 | |
marcozecchini | 0:9fca2b23d0ba | 70 | virtual int _putc(int c) = 0; |
marcozecchini | 0:9fca2b23d0ba | 71 | virtual int _getc() = 0; |
marcozecchini | 0:9fca2b23d0ba | 72 | |
marcozecchini | 0:9fca2b23d0ba | 73 | std::FILE *_file; |
marcozecchini | 0:9fca2b23d0ba | 74 | |
marcozecchini | 0:9fca2b23d0ba | 75 | /** Acquire exclusive access to this object. |
marcozecchini | 0:9fca2b23d0ba | 76 | */ |
marcozecchini | 0:9fca2b23d0ba | 77 | virtual void lock() { |
marcozecchini | 0:9fca2b23d0ba | 78 | // Stub |
marcozecchini | 0:9fca2b23d0ba | 79 | } |
marcozecchini | 0:9fca2b23d0ba | 80 | |
marcozecchini | 0:9fca2b23d0ba | 81 | /** Release exclusive access to this object. |
marcozecchini | 0:9fca2b23d0ba | 82 | */ |
marcozecchini | 0:9fca2b23d0ba | 83 | virtual void unlock() { |
marcozecchini | 0:9fca2b23d0ba | 84 | // Stub |
marcozecchini | 0:9fca2b23d0ba | 85 | } |
marcozecchini | 0:9fca2b23d0ba | 86 | }; |
marcozecchini | 0:9fca2b23d0ba | 87 | /**@}*/ |
marcozecchini | 0:9fca2b23d0ba | 88 | |
marcozecchini | 0:9fca2b23d0ba | 89 | /**@}*/ |
marcozecchini | 0:9fca2b23d0ba | 90 | } // namespace mbed |
marcozecchini | 0:9fca2b23d0ba | 91 | |
marcozecchini | 0:9fca2b23d0ba | 92 | #endif |
marcozecchini | 0:9fca2b23d0ba | 93 |