#ifndef FILEMAN_H #define FILEMAN_H #include #include #include #define BLOCKSIZE 8 /** * @class FileMan * * Provides File I/O abstraction */ class FileMan { private: /** * Internal state * * Filestreams for put and get * Vector for holding received filenames from listing * Paths and filenames for put and get * Size for internal read * Total and Remaining chunks for put, get and list * Boolean replacement for filestreams being open for list * */ std::ifstream putfile; std::ofstream getfile; std::vector listdata; std::string getpath, getname, putpath, putname; const unsigned int max_read_len = 8; int putsize; int putchunks; int putchunksRemaining; int getchunks; int getchunksRemaining; int listchunks; int listchunksRemaining; bool islisting; public: /** * Constructor and Destructor */ FileMan(); ~FileMan(); /** * Query internal state * * Return true if the corresponding action is being performed, false otherwise */ bool isGetting(); bool isPutting(); bool isListing(); /** * Check for and prepare state and streams for reading/writing * * Return true if successful, false otherwise */ bool openPut(const std::string &path); bool openGet(const std::string &path); bool openList(); /** * Close the respective filestream */ void closePut(); void closeGet(); void closeList(); /** * Query the names of the file currently being put or get */ std::string getPutName(); std::string getGetName(); /** * Cancel a put, get or list, depreparing internal state (closing streams if * required) */ void cancelPut(); void cancelGet(); void cancelList(); /** * Read max_rea_len bytes from the current file opened for put */ std::vector readPut(); /** * Write the provided vector to the current file opened for get */ void writeGet(std::vector data); /** * Wrapper methods for reading and writing base64 encoded data instead of raw * bytes */ std::string readBase64(); void writeBase64(std::string data); /** * read and write emulating methods for list */ void putListData(std::vector names); std::vector getListData(); /** * Query internal state, requesting the corresponding size */ int getPutChunks(); int getGetChunks(); int getListChunks(); int getPutRemainingChunks(); int getGetRemainingChunks(); int getListRemainingChunks(); int getPutSize(); /** * Set internal state, adjusting the chunks as well as chunks remaining for * get and list */ void setGetChunks(int chunks); void setListChunks(int chunks); /** * Returns the filename of the passed (relative) path of a file */ std::string pathToFilename(std::string path); }; #endif