DBDirectoryProcessor.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. bool error = false;
  40. std::string realFileName; // The name of the unique file in case of splitting
  41. public:
  42. DBDirectoryProcessor(); // constructor with no splitting
  43. DBDirectoryProcessor(uint64_t nbStreams); // constructor with filesplitting 1 -> nbStreams
  44. virtual ~DBDirectoryProcessor();
  45. std::string getCatalog(const bool typeOfCatalog);
  46. uint64_t getDBSizeBits();
  47. uint64_t getNbStream();
  48. uint64_t getmaxFileBytesize();
  49. bool getErrorStatus();
  50. std::ifstream* openStream(uint64_t streamNb, uint64_t requested_offset);
  51. uint64_t readStream(std::ifstream* s,char * buf, uint64_t size);
  52. void readAggregatedStream(uint64_t streamNb, uint64_t alpha, uint64_t offset, uint64_t bytes_per_file, char* rawBits);
  53. void closeStream(std::ifstream* s);
  54. std::streampos getFileSize( std::string filePath );
  55. private:
  56. uint64_t maxFileBytesize;
  57. };
  58. #endif //DEF_CATALOGMAKER