,,
Fork of Application by
mbed-dev/drivers/Stream.h@10:41552d038a69, 2017-01-10 (annotated)
- Committer:
- Zaitsev
- Date:
- Tue Jan 10 20:42:26 2017 +0000
- Revision:
- 10:41552d038a69
USB Serial bi-directional bridge
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Zaitsev | 10:41552d038a69 | 1 | /* mbed Microcontroller Library |
Zaitsev | 10:41552d038a69 | 2 | * Copyright (c) 2006-2013 ARM Limited |
Zaitsev | 10:41552d038a69 | 3 | * |
Zaitsev | 10:41552d038a69 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Zaitsev | 10:41552d038a69 | 5 | * you may not use this file except in compliance with the License. |
Zaitsev | 10:41552d038a69 | 6 | * You may obtain a copy of the License at |
Zaitsev | 10:41552d038a69 | 7 | * |
Zaitsev | 10:41552d038a69 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Zaitsev | 10:41552d038a69 | 9 | * |
Zaitsev | 10:41552d038a69 | 10 | * Unless required by applicable law or agreed to in writing, software |
Zaitsev | 10:41552d038a69 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Zaitsev | 10:41552d038a69 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Zaitsev | 10:41552d038a69 | 13 | * See the License for the specific language governing permissions and |
Zaitsev | 10:41552d038a69 | 14 | * limitations under the License. |
Zaitsev | 10:41552d038a69 | 15 | */ |
Zaitsev | 10:41552d038a69 | 16 | #ifndef MBED_STREAM_H |
Zaitsev | 10:41552d038a69 | 17 | #define MBED_STREAM_H |
Zaitsev | 10:41552d038a69 | 18 | |
Zaitsev | 10:41552d038a69 | 19 | #include "platform/platform.h" |
Zaitsev | 10:41552d038a69 | 20 | #include "drivers/FileLike.h" |
Zaitsev | 10:41552d038a69 | 21 | #include <cstdarg> |
Zaitsev | 10:41552d038a69 | 22 | |
Zaitsev | 10:41552d038a69 | 23 | namespace mbed { |
Zaitsev | 10:41552d038a69 | 24 | /** \addtogroup drivers */ |
Zaitsev | 10:41552d038a69 | 25 | /** @{*/ |
Zaitsev | 10:41552d038a69 | 26 | |
Zaitsev | 10:41552d038a69 | 27 | extern void mbed_set_unbuffered_stream(FILE *_file); |
Zaitsev | 10:41552d038a69 | 28 | extern int mbed_getc(FILE *_file); |
Zaitsev | 10:41552d038a69 | 29 | extern char* mbed_gets(char *s, int size, FILE *_file); |
Zaitsev | 10:41552d038a69 | 30 | |
Zaitsev | 10:41552d038a69 | 31 | /** File stream |
Zaitsev | 10:41552d038a69 | 32 | * |
Zaitsev | 10:41552d038a69 | 33 | * @Note Synchronization level: Set by subclass |
Zaitsev | 10:41552d038a69 | 34 | */ |
Zaitsev | 10:41552d038a69 | 35 | class Stream : public FileLike { |
Zaitsev | 10:41552d038a69 | 36 | |
Zaitsev | 10:41552d038a69 | 37 | public: |
Zaitsev | 10:41552d038a69 | 38 | Stream(const char *name=NULL); |
Zaitsev | 10:41552d038a69 | 39 | virtual ~Stream(); |
Zaitsev | 10:41552d038a69 | 40 | |
Zaitsev | 10:41552d038a69 | 41 | int putc(int c); |
Zaitsev | 10:41552d038a69 | 42 | int puts(const char *s); |
Zaitsev | 10:41552d038a69 | 43 | int getc(); |
Zaitsev | 10:41552d038a69 | 44 | char *gets(char *s, int size); |
Zaitsev | 10:41552d038a69 | 45 | int printf(const char* format, ...); |
Zaitsev | 10:41552d038a69 | 46 | int scanf(const char* format, ...); |
Zaitsev | 10:41552d038a69 | 47 | int vprintf(const char* format, std::va_list args); |
Zaitsev | 10:41552d038a69 | 48 | int vscanf(const char* format, std::va_list args); |
Zaitsev | 10:41552d038a69 | 49 | |
Zaitsev | 10:41552d038a69 | 50 | operator std::FILE*() {return _file;} |
Zaitsev | 10:41552d038a69 | 51 | |
Zaitsev | 10:41552d038a69 | 52 | protected: |
Zaitsev | 10:41552d038a69 | 53 | virtual int close(); |
Zaitsev | 10:41552d038a69 | 54 | virtual ssize_t write(const void* buffer, size_t length); |
Zaitsev | 10:41552d038a69 | 55 | virtual ssize_t read(void* buffer, size_t length); |
Zaitsev | 10:41552d038a69 | 56 | virtual off_t lseek(off_t offset, int whence); |
Zaitsev | 10:41552d038a69 | 57 | virtual int isatty(); |
Zaitsev | 10:41552d038a69 | 58 | virtual int fsync(); |
Zaitsev | 10:41552d038a69 | 59 | virtual off_t flen(); |
Zaitsev | 10:41552d038a69 | 60 | |
Zaitsev | 10:41552d038a69 | 61 | virtual int _putc(int c) = 0; |
Zaitsev | 10:41552d038a69 | 62 | virtual int _getc() = 0; |
Zaitsev | 10:41552d038a69 | 63 | |
Zaitsev | 10:41552d038a69 | 64 | std::FILE *_file; |
Zaitsev | 10:41552d038a69 | 65 | |
Zaitsev | 10:41552d038a69 | 66 | /* disallow copy constructor and assignment operators */ |
Zaitsev | 10:41552d038a69 | 67 | private: |
Zaitsev | 10:41552d038a69 | 68 | Stream(const Stream&); |
Zaitsev | 10:41552d038a69 | 69 | Stream & operator = (const Stream&); |
Zaitsev | 10:41552d038a69 | 70 | }; |
Zaitsev | 10:41552d038a69 | 71 | |
Zaitsev | 10:41552d038a69 | 72 | } // namespace mbed |
Zaitsev | 10:41552d038a69 | 73 | |
Zaitsev | 10:41552d038a69 | 74 | #endif |
Zaitsev | 10:41552d038a69 | 75 | |
Zaitsev | 10:41552d038a69 | 76 | /** @}*/ |