Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
GdbFileStream.h
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/anakod/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * GdbFileStream.h
8  *
9  ****/
10 
11 #ifndef _SMING_CORE_DATA_GDB_FILE_STREAM_H_
12 #define _SMING_CORE_DATA_GDB_FILE_STREAM_H_
13 
14 #include "ReadWriteStream.h"
15 #include "FileSystem.h"
16 
22 {
23 public:
25  {
26  }
27 
31  GdbFileStream(const String& fileName, FileOpenFlags openFlags = eFO_ReadOnly)
32  {
33  open(fileName, openFlags);
34  }
35 
36  ~GdbFileStream()
37  {
38  close();
39  }
40 
47  bool open(const String& fileName, FileOpenFlags openFlags = eFO_ReadOnly);
48 
51  void close();
52 
53  size_t write(const uint8_t* buffer, size_t size) override;
54 
55  //Use base class documentation
56  uint16_t readMemoryBlock(char* data, int bufSize) override;
57 
58  //Use base class documentation
59  bool seek(int len) override;
60 
61  //Use base class documentation
62  bool isFinished() override
63  {
64  return pos == size;
65  }
66 
71  {
72  return fileName;
73  }
74 
78  bool fileExist() const
79  {
80  return handle >= 0;
81  }
82 
83  String getName() const override
84  {
85  return fileName;
86  }
87 
88  bool isValid() const override
89  {
90  return fileExist();
91  }
92 
96  size_t getPos() const
97  {
98  return pos;
99  }
100 
104  int available() override
105  {
106  return size - pos;
107  }
108 
109  String id() const override;
110 
115  {
116  return lastError;
117  }
118 
119 private:
124  bool check(int res)
125  {
126  if(res >= 0) {
127  return true;
128  }
129 
130  if(lastError >= 0) {
131  lastError = res;
132  }
133  return false;
134  }
135 
136 private:
137  String fileName;
138  int handle = -1;
139  size_t pos = 0;
140  size_t size = 0;
141  int lastError = 0;
142 };
143 
144 #endif /* _SMING_CORE_DATA_GDB_FILE_STREAM_H_ */
size_t getPos() const
Get the offset of cursor from beginning of data.
Definition: GdbFileStream.h:96
GdbFileStream(const String &fileName, FileOpenFlags openFlags=eFO_ReadOnly)
Create a file stream.
Definition: GdbFileStream.h:31
bool fileExist() const
Determine if file exists.
Definition: GdbFileStream.h:78
bool isFinished() override
Check if all data has been read.
Definition: GdbFileStream.h:62
bool isValid() const override
Determine if the stream object contains valid data.
Definition: GdbFileStream.h:88
GDB File stream class to provide access to host files whilst running under debugger.
Definition: GdbFileStream.h:21
bool seek(int len) override
Move read cursor.
String getFileName() const
Filename of file stream is attached to.
Definition: GdbFileStream.h:70
void close()
Close file.
The string class.
Definition: WString.h:104
size_t write(const uint8_t *buffer, size_t size) override
Write chars to stream.
Read only file.
Definition: FileSystem.h:26
int getLastError()
determine if an error occurred during operation
Definition: GdbFileStream.h:114
bool open(const String &fileName, FileOpenFlags openFlags=eFO_ReadOnly)
Open a file and attach this stream object to it.
uint16_t readMemoryBlock(char *data, int bufSize) override
Read a block of memory.
int available() override
Return the total length of the stream.
Definition: GdbFileStream.h:104
String id() const override
Returns unique id of the resource.
Base class for read/write stream.
Definition: ReadWriteStream.h:23
String getName() const override
Returns name of the resource.
Definition: GdbFileStream.h:83
FileOpenFlags
File open flags.
Definition: FileSystem.h:25