#ifndef __FILEMANAGER_H #define __FILEMANAGER_H #include #define MAXFILES 4 // how many results we can simultaneously manage #define DIRPAGESIZE 10 // how many results in one readDir #ifndef MAXPATH #define MAXPATH 255 #endif #define FMMAGIC 'F' class FileManager { public: virtual ~FileManager() {}; virtual bool SerializeFile(int8_t outfd, int8_t fd) { writeByte(outfd, FMMAGIC); if (fd == -1 || cachedNames[fd][0] == '\0') { // No file to cache; we're done writeByte(outfd, 0); writeByte(outfd, FMMAGIC); return true; } // have a file to cache; set a marker and continue writeByte(outfd, 1); int8_t l = 0; char *p = cachedNames[fd]; while (*p) { l++; p++; } writeByte(outfd, l); for (int i=0; i> 24) & 0xFF); writeByte(outfd, (fileSeekPositions[fd] >> 16) & 0xFF); writeByte(outfd, (fileSeekPositions[fd] >> 8) & 0xFF); writeByte(outfd, (fileSeekPositions[fd] ) & 0xFF); writeByte(outfd, FMMAGIC); return true; } virtual int8_t DeserializeFile(int8_t infd) { if (readByte(infd) != FMMAGIC) return -1; if (readByte(infd) == 0) { // No file was cached. Verify footer and we're done without error if (readByte(infd) != FMMAGIC) { // FIXME: no way to raise this error. return -1; } return -1; } char buf[MAXPATH]; int8_t l = readByte(infd); for (int i=0; i