DBDirectoryProcessor.hpp 2.1 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 <map>
  25. #include <string>
  26. #include <iostream>
  27. #include <fstream>
  28. #include <stdio.h>
  29. #include <string.h>
  30. #define DEFAULT_DIR_NAME "db/"
  31. #define NB_FILE_DESCRIPTORS 50
  32. class DBDirectoryProcessor : public DBHandler
  33. {
  34. private:
  35. boost::mutex mutex;
  36. std::string directory;
  37. std::map<uint64_t, std::ifstream*> fdPool; // a pool of file descriptors
  38. std::vector <std::string> file_list; // the output file list
  39. bool filesSplitting;
  40. bool error = false;
  41. std::string realFileName; // The name of the unique file in case of splitting
  42. public:
  43. DBDirectoryProcessor(); // constructor with no splitting
  44. DBDirectoryProcessor(uint64_t nbStreams); // constructor with filesplitting 1 -> nbStreams
  45. virtual ~DBDirectoryProcessor();
  46. std::string getCatalog(const bool typeOfCatalog);
  47. uint64_t getDBSizeBits();
  48. uint64_t getNbStream();
  49. uint64_t getmaxFileBytesize();
  50. bool getErrorStatus();
  51. bool openStream(uint64_t streamNb, uint64_t requested_offset);
  52. uint64_t readStream(uint64_t streamNb, char * buf, uint64_t size);
  53. void closeStream(uint64_t streamNb);
  54. std::streampos getFileSize( std::string filePath );
  55. private:
  56. uint64_t maxFileBytesize;
  57. };
  58. #endif //DEF_CATALOGMAKER