DBDirectoryProcessor.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Copyright (C) 2014 Carlos Aguilar Melchor, Joris Barrier, Marc-Olivier Killijian
  2. * This file is part of XPIR.
  3. *
  4. * XPIR is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * XPIR is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with XPIR. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef DEF_DBDIRPROC
  18. #define DEF_DBDIRPROC
  19. #include "DBHandler.hpp"
  20. #include <boost/interprocess/sync/interprocess_semaphore.hpp>
  21. #include <boost/thread.hpp>
  22. #include <dirent.h>
  23. #include <vector>
  24. #include <string>
  25. #include <iostream>
  26. #include <fstream>
  27. #include <stdio.h>
  28. #include <string.h>
  29. #define DEFAULT_DIR_NAME "db/"
  30. #define NB_FILE_DESCRIPTORS 50
  31. class DBDirectoryProcessor : public DBHandler
  32. {
  33. private:
  34. boost::mutex mutex;
  35. std::string directory;
  36. std::vector<std::ifstream*> fdPool; // a pool of file descriptors
  37. std::vector <std::string> file_list; // the output file list
  38. bool filesSplitting;
  39. std::string realFileName; // The name of the unique file in case of splitting
  40. public:
  41. DBDirectoryProcessor(); // constructor with no splitting
  42. DBDirectoryProcessor(uint64_t nbStreams); // constructor with filesplitting 1 -> nbStreams
  43. virtual ~DBDirectoryProcessor();
  44. std::string getCatalog(const bool typeOfCatalog);
  45. uint64_t getDBSizeBits();
  46. uint64_t getNbStream();
  47. uint64_t getmaxFileBytesize();
  48. std::ifstream* openStream(uint64_t streamNb, uint64_t requested_offset);
  49. uint64_t readStream(std::ifstream* s,char * buf, uint64_t size);
  50. void readAggregatedStream(uint64_t streamNb, uint64_t alpha, uint64_t offset, uint64_t bytes_per_file, char* rawBits);
  51. void closeStream(std::ifstream* s);
  52. std::streampos getFileSize( std::string filePath );
  53. private:
  54. uint64_t maxFileBytesize;
  55. };
  56. #endif //DEF_CATALOGMAKER