| 1 | /* mbed Microcontroller Library - Stream |
| 2 | * Copyright (c) 2007-2009 ARM Limited. All rights reserved. |
| 3 | */ |
| 4 | |
| 5 | #ifndef MBED_STREAM_H |
| 6 | #define MBED_STREAM_H |
| 7 | |
| 8 | #include "FileLike.h" |
| 9 | #include "platform.h" |
| 10 | #include <cstdio> |
| 11 | |
| 12 | namespace mbed { |
| 13 | |
| 14 | class Stream : public FileLike { |
| 15 | |
| 16 | public: |
| 17 | |
| 18 | Stream(const char *name = NULL); |
| 19 | virtual ~Stream(); |
| 20 | |
| 21 | int putc(int c) { |
| 22 | fflush(_file); |
| 23 | return std::fputc(c, _file); |
| 24 | } |
| 25 | int puts(const char *s) { |
| 26 | fflush(_file); |
| 27 | return std::fputs(s, _file); |
| 28 | } |
| 29 | int getc() { |
| 30 | fflush(_file); |
| 31 | return std::fgetc(_file); |
| 32 | } |
| 33 | char *gets(char *s, int size) { |
| 34 | fflush(_file); |
| 35 | return std::fgets(s,size,_file);; |
| 36 | } |
| 37 | int printf(const char* format, ...); |
| 38 | int scanf(const char* format, ...); |
| 39 | |
| 40 | operator std::FILE*() { return _file; } |
| 41 | |
| 42 | std::FILE *_file; |
| 43 | #ifdef MBED_RPC |
| 44 | virtual const struct rpc_method *get_rpc_methods(); |
| 45 | #endif |
| 46 | |
| 47 | protected: |
| 48 | |
| 49 | virtual int close(); |
| 50 | virtual ssize_t write(const void* buffer, size_t length); |
| 51 | virtual ssize_t read(void* buffer, size_t length); |
| 52 | virtual off_t lseek(off_t offset, int whence); |
| 53 | virtual int isatty(); |
| 54 | virtual int fsync(); |
| 55 | virtual off_t flen(); |
| 56 | |
| 57 | virtual int _putc(int c) = 0; |
| 58 | virtual int _getc() = 0; |
| 59 | |
| 60 | |
| 61 | }; |
| 62 | |
| 63 | } // namespace mbed |
| 64 | |
| 65 | #endif |
| 66 | |