mbed-os

Fork of mbed-os by erkin yucel

Committer:
xuaner
Date:
Thu Jul 20 14:26:57 2017 +0000
Revision:
1:3deb71413561
Parent:
0:f269e3021894
mbed_os

Who changed what in which revision?

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