Commit | Line | Data |
---|---|---|
4cff3ded AW |
1 | /* mbed Microcontroller Library - Stream |
2 | * Copyright (c) 2007-2009 ARM Limited. All rights reserved. | |
3 | * sford | |
4 | */ | |
5 | ||
6 | #ifndef MBED_STREAM_H | |
7 | #define MBED_STREAM_H | |
8 | ||
9 | #include "FileLike.h" | |
10 | #include "platform.h" | |
11 | #include <cstdio> | |
12 | ||
13 | namespace mbed { | |
14 | ||
15 | class Stream : public FileLike { | |
16 | ||
17 | public: | |
18 | ||
19 | Stream(const char *name = NULL); | |
20 | virtual ~Stream(); | |
21 | ||
22 | int putc(int c) { | |
23 | fflush(_file); | |
24 | return std::fputc(c, _file); | |
25 | } | |
26 | int puts(const char *s) { | |
27 | fflush(_file); | |
28 | return std::fputs(s, _file); | |
29 | } | |
30 | int getc() { | |
31 | fflush(_file); | |
32 | return std::fgetc(_file); | |
33 | } | |
34 | char *gets(char *s, int size) { | |
35 | fflush(_file); | |
36 | return std::fgets(s,size,_file);; | |
37 | } | |
38 | int printf(const char* format, ...); | |
39 | int scanf(const char* format, ...); | |
40 | ||
41 | operator std::FILE*() { return _file; } | |
42 | ||
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 | std::FILE *_file; | |
61 | ||
62 | }; | |
63 | ||
64 | } // namespace mbed | |
65 | ||
66 | #endif | |
67 |