123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- #ifndef FILEMAN_H
- #define FILEMAN_H
- #include <fstream>
- #include <string>
- #include <vector>
- #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<std::string> 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<char> readPut();
- /**
- * Write the provided vector to the current file opened for get
- */
- void writeGet(std::vector<char> 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<std::string> names);
- std::vector<std::string> 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
|