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