#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' #ifndef SEEK_SET #define SEEK_SET 0 #endif #ifndef SEEK_CUR #define SEEK_CUR 1 #endif class FileManager { public: virtual ~FileManager() {}; #define writeByte(fd,x) {static uint8_t c = x; write(outfd, &c, 1);} 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) { uint8_t b; if (read(infd, &b, 1) != 1) return -1; if (b != FMMAGIC) return -1; if (read(infd, &b, 1) != 1) return -1; if (b == 0) { // No file was cached. Verify footer and we're done without error if (read(infd, &b, 1) != 1) return -1; if (b != FMMAGIC) { // FIXME: no way to raise this error. return -1; } return -1; } char buf[MAXPATH]; if (read(infd, &b, 1) != 1) return -1; int8_t len = b; for (int i=0; i